Commit 4859291e authored by Ivan Tyagov's avatar Ivan Tyagov

Extend test to cover changing dynamically in URL portal_skin to RSS.

Contributed by zstoinov.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@22543 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 0b39d728
...@@ -29,6 +29,7 @@ import unittest ...@@ -29,6 +29,7 @@ import unittest
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from AccessControl.SecurityManagement import newSecurityManager from AccessControl.SecurityManagement import newSecurityManager
from Products.ERP5Form.Form import ERP5Form
from xml.dom.minidom import parseString from xml.dom.minidom import parseString
...@@ -74,13 +75,16 @@ class TestRSS(ERP5TypeTestCase): ...@@ -74,13 +75,16 @@ class TestRSS(ERP5TypeTestCase):
def makeDataObjects(self, quiet=0, run=run_all_test): def makeDataObjects(self, quiet=0, run=run_all_test):
""" """
Create some Pesons so that we have something to feed. Create some Pesons so that we have something to feed.
(we create only one because we'd have sorting problems)
""" """
if hasattr(self.portal.person_module, 'one'): if hasattr(self.portal.person_module, 'one'):
self.portal.person_module.manage_delObjects(['one']) self.portal.person_module.manage_delObjects(['one'])
if hasattr(self.portal.person_module, 'two'):
self.portal.person_module.manage_delObjects(['two'])
one = self.portal.person_module.newContent(id="one", title="One", description="Person One") one = self.portal.person_module.newContent(id="one", title="One", description="Person One")
two = self.portal.person_module.newContent(id="two", title="Two", description="Person Two")
get_transaction().commit() get_transaction().commit()
one.reindexObject() one.reindexObject()
two.reindexObject()
self.tic() self.tic()
def test_00_haveData(self, quiet=0, run=run_all_test): def test_00_haveData(self, quiet=0, run=run_all_test):
...@@ -89,21 +93,43 @@ class TestRSS(ERP5TypeTestCase): ...@@ -89,21 +93,43 @@ class TestRSS(ERP5TypeTestCase):
""" """
module = self.portal.person_module module = self.portal.person_module
self.assertEquals(module.one.getTitle(), "One") self.assertEquals(module.one.getTitle(), "One")
self.assertEquals(module.two.getTitle(), "Two")
def test_01_renderRSS(self, quiet=0, run=run_all_test): def test_01_renderRSS(self, quiet=0, run=run_all_test):
""" """
View person module as RSS, parse XML, see if everything is there. View person module as RSS, parse XML, see if everything is there.
""" """
portal=self.getPortal()
request=self.app.REQUEST
request.set('portal_skin', 'RSS');
portal.portal_skins.changeSkin('RSS');
one = self.portal.person_module.one one = self.portal.person_module.one
two = self.portal.person_module.two
feed_string = self.portal.person_module.Folder_viewContentListAsRSS() feed_string = self.portal.person_module.Folder_viewContentListAsRSS()
doc = parseString(feed_string) doc = parseString(feed_string)
rss = doc.childNodes[0] rss = doc.childNodes[0]
channel = rss.getElementsByTagName('channel')[0] channel = rss.getElementsByTagName('channel')[0]
self.assertEquals(len(rss.getElementsByTagName('channel')), 1)
self.assertEquals(len(channel.getElementsByTagName('item')), 2)
titles = [getNodeContent(n) for n in channel.getElementsByTagName('title')] titles = [getNodeContent(n) for n in channel.getElementsByTagName('title')]
titles.sort() titles.sort()
self.assertEquals(titles, ['One', 'Persons']) # there is channel title and person title self.assertEquals(titles, ['One', 'Persons', 'Two']) # there is channel title and person titles
self.assertEquals(len(channel.getElementsByTagName('item')), 1)
item = channel.getElementsByTagName('item')[0] # the one person item = channel.getElementsByTagName('item')[0] # the two person, because we have default sorting in form
self.assertEquals(getSubnodeContent(item, 'title'), 'Two')
self.assertEquals(getSubnodeContent(item, 'description'), 'Person Two')
self.assertEquals(getSubnodeContent(item, 'author'), 'seb')
expected_link = two.absolute_url() + '/view'
self.assertEquals(getSubnodeContent(item, 'link'), expected_link)
self.assertEquals(len(item.getElementsByTagName('pubDate')), 1)
# is date formatted correctly?
self.assertEquals(two.getCreationDate().rfc822(), getSubnodeContent(item, 'pubDate'))
item = channel.getElementsByTagName('item')[1] # the one person
self.assertEquals(getSubnodeContent(item, 'title'), 'One') self.assertEquals(getSubnodeContent(item, 'title'), 'One')
self.assertEquals(getSubnodeContent(item, 'description'), 'Person One') self.assertEquals(getSubnodeContent(item, 'description'), 'Person One')
self.assertEquals(getSubnodeContent(item, 'author'), 'seb') self.assertEquals(getSubnodeContent(item, 'author'), 'seb')
...@@ -111,8 +137,80 @@ class TestRSS(ERP5TypeTestCase): ...@@ -111,8 +137,80 @@ class TestRSS(ERP5TypeTestCase):
self.assertEquals(getSubnodeContent(item, 'link'), expected_link) self.assertEquals(getSubnodeContent(item, 'link'), expected_link)
self.assertEquals(len(item.getElementsByTagName('pubDate')), 1) self.assertEquals(len(item.getElementsByTagName('pubDate')), 1)
# is date formatted correctly? # is date formatted correctly?
self.assertEquals(one.getCreationDate().rfc822(), getSubnodeContent(item, 'pubDate')) self.assertEquals(two.getCreationDate().rfc822(), getSubnodeContent(item, 'pubDate'))
def test_02_renderRSS(self, quiet=0, run=run_all_test):
"""
View person module as RSS, parse XML, see if everything is there.
In this case pt for render current form('Test_view') is default page template
and some listbox's columns(i.e. description) label not present in required channel fields
"""
portal=self.getPortal()
request=self.app.REQUEST
request.set('portal_skin', 'RSS');
portal.portal_skins.changeSkin('RSS');
self.getPortal()._setObject('Test_view',
ERP5Form('Test_view', 'View'))
portal.Test_view.manage_addField('listbox', 'listbox', 'ListBox')
portal.Test_view.manage_addField('listbox_link', 'listbox_link', 'StringField')
listbox=portal.Test_view.listbox
self.assertNotEquals(listbox, None)
listbox_link=portal.Test_view.listbox_link
self.assertNotEquals(listbox_link, None)
listbox.manage_edit_xmlrpc(
dict(columns=[('title', 'Title'),
('creation_date', 'pubDate'),
('Base_getRSSAuthor','author'),
('link','link'),
('absolute_url', 'guid')],
sort=[('creation_date | descending')],
list_action='list',
search=1,
select=1,
list_method='searchFolder',
count_method='countFolder',
selection_name='rss_folder_selection'))
listbox_link.manage_tales_xmlrpc(
dict(default="python: cell.absolute_url() + '/view'"))
one = self.portal.person_module.one
two = self.portal.person_module.two
feed_string = self.portal.person_module.Test_view()
doc = parseString(feed_string)
rss = doc.childNodes[0]
channel = rss.getElementsByTagName('channel')[0]
self.assertEquals(len(rss.getElementsByTagName('channel')), 1)
self.assertEquals(len(channel.getElementsByTagName('item')), 2)
titles = [getNodeContent(n) for n in channel.getElementsByTagName('title')]
titles.sort()
self.assertEquals(titles, ['One', 'Persons', 'Two']) # there is channel title and person titles
item = channel.getElementsByTagName('item')[0] # the two person, because we have default sorting in form
self.assertEquals(getSubnodeContent(item, 'title'), 'Two')
self.assertEquals(getSubnodeContent(item, 'description'), 'Person Two')
self.assertEquals(getSubnodeContent(item, 'author'), 'seb')
expected_link = two.absolute_url() + '/view'
self.assertEquals(getSubnodeContent(item, 'link'), expected_link)
self.assertEquals(len(item.getElementsByTagName('pubDate')), 1)
# is date formatted correctly?
self.assertEquals(two.getCreationDate().rfc822(), getSubnodeContent(item, 'pubDate'))
item = channel.getElementsByTagName('item')[1] # the one person
self.assertEquals(getSubnodeContent(item, 'title'), 'One')
self.assertEquals(getSubnodeContent(item, 'description'), 'Person One')
self.assertEquals(getSubnodeContent(item, 'author'), 'seb')
expected_link = one.absolute_url() + '/view'
self.assertEquals(getSubnodeContent(item, 'link'), expected_link)
self.assertEquals(len(item.getElementsByTagName('pubDate')), 1)
# is date formatted correctly?
self.assertEquals(two.getCreationDate().rfc822(), getSubnodeContent(item, 'pubDate'))
def test_suite(): def test_suite():
suite = unittest.TestSuite() suite = unittest.TestSuite()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment