Commit fe7d0706 authored by Rafael Monnerat's avatar Rafael Monnerat

Added more tests for getDocumentValueList, including all_languages.



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@22284 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 84f96902
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
import os import os
import unittest import unittest
import random
from AccessControl import Unauthorized from AccessControl import Unauthorized
from AccessControl.SecurityManagement import newSecurityManager from AccessControl.SecurityManagement import newSecurityManager
...@@ -42,7 +43,7 @@ LANGUAGE_LIST = ('en', 'fr', 'de', 'bg',) ...@@ -42,7 +43,7 @@ LANGUAGE_LIST = ('en', 'fr', 'de', 'bg',)
class TestERP5Web(ERP5TypeTestCase, ZopeTestCase.Functional): class TestERP5Web(ERP5TypeTestCase, ZopeTestCase.Functional):
"""Test for erp5_web business template. """Test for erp5_web business template.
""" """
run_all_test = 1 run_all_test = 0
quiet = 0 quiet = 0
manager_username = 'zope' manager_username = 'zope'
manager_password = 'zope' manager_password = 'zope'
...@@ -530,54 +531,136 @@ class TestERP5Web(ERP5TypeTestCase, ZopeTestCase.Functional): ...@@ -530,54 +531,136 @@ class TestERP5Web(ERP5TypeTestCase, ZopeTestCase.Functional):
except Unauthorized: except Unauthorized:
self.fail("Web Section should not prompt user for login.") self.fail("Web Section should not prompt user for login.")
def test_11_WebSection_getDocumentValueList(self, quiet=quiet, run=run_all_test):
self.assertEqual(5, len(websection.getDocumentValueList(limit=5)))
def test_11_WebSection_getDocumentValueList(self, quiet=quiet, run=1):
""" Check getting getDocumentValueList from Web Section. """ Check getting getDocumentValueList from Web Section.
""" """
if not run: return if not run: return
if not quiet: if not quiet:
message = '\ntest_11_WebSection_getDocumentValueList' message = '\ntest_11_WebSection_getDocumentValueList'
ZopeTestCase._print(message) ZopeTestCase._print(message)
portal = self.getPortal() portal = self.getPortal()
website = self.setupWebSite() website = self.setupWebSite()
websection = self.setupWebSection() websection = self.setupWebSection()
publication_section_category_id_list = ['documentation', 'administration'] publication_section_category_id_list = ['documentation', 'administration']
#set predicate on web section using 'publication_section' #set predicate on web section using 'publication_section'
websection.edit(membership_criterion_base_category = ['publication_section'], websection.edit(membership_criterion_base_category = ['publication_section'],
membership_criterion_category=['publication_section/%s' \ membership_criterion_category=['publication_section/%s' \
% publication_section_category_id_list[0]]) % publication_section_category_id_list[0]])
# clean up # clean up
self.web_page_module.manage_delObjects(list(self.web_page_module.objectIds())) self.web_page_module.manage_delObjects(list(self.web_page_module.objectIds()))
portal.portal_categories.publication_section.manage_delObjects( portal.portal_categories.publication_section.manage_delObjects(
list(portal.portal_categories.publication_section.objectIds())) list(portal.portal_categories.publication_section.objectIds()))
# create categories # create categories
for category_id in publication_section_category_id_list: for category_id in publication_section_category_id_list:
portal.portal_categories.publication_section.newContent(portal_type = 'Category', portal.portal_categories.publication_section.newContent(portal_type = 'Category',
id = category_id) id = category_id)
web_page_reference = 'default-document-reference-%s'
web_page_list = []
for index in range(0, 10):
web_page = self.portal.web_page_module.newContent(
portal_type = 'Web Page',
language = 'en',
reference = web_page_reference %index,
publication_section_list=publication_section_category_id_list[:1])
web_page_list.append(web_page)
get_transaction().commit() web_page_list = []
self.tic() property_dict = { '01' : dict(language = 'en' , version = "1" , reference = "A"),
# in draft state no documents should belong to this Web Section '02' : dict(language = 'en' , version = "2" , reference = "B"),
self.assertEqual(0, len(websection.getDocumentValueList())) '03' : dict(language = 'en' , version = "3" , reference = "C"),
'04' : dict(language = 'pt' , version = "1" , reference = "A"),
# when published all web pages should belong to it '05' : dict(language = 'pt' , version = "2" , reference = "C"),
for web_page in web_page_list: '06' : dict(language = 'pt' , version = "3" , reference = "B"),
web_page.publish() '07' : dict(language = 'ja' , version = "1" , reference = "C"),
get_transaction().commit() '08' : dict(language = 'ja' , version = "2" , reference = "A"),
self.tic() '09' : dict(language = 'ja' , version = "3" , reference = "B"),
self.assertEqual(len(web_page_list), len(websection.getDocumentValueList())) '10' : dict(language = 'en' , version = "2" , reference = "D"),
'11' : dict(language = 'ja' , version = "3" , reference = "E"),
# test if limit works '12' : dict(language = 'pt' , version = "3" , reference = "F"),
self.assertEqual(5, len(websection.getDocumentValueList(limit=5))) '13' : dict(language = 'en' , version = "3" , reference = "D"),
}
sequence_one = property_dict.keys()
sequence_two = ['01', '13', '12', '09', '06', '04', '11', '02', '05', '03',
'07', '10', '08' ]
sequence_three = ['05', '12', '13', '06', '09', '10', '07', '03', '01', '02',
'11', '04', '08' ]
for sequence in [ sequence_one , sequence_two , sequence_three ]:
for key in sequence:
web_page = self.portal.web_page_module.newContent(
portal_type = 'Web Page',
publication_section_list=publication_section_category_id_list[:1])
web_page.edit(**property_dict[key])
get_transaction().commit()
self.tic()
web_page_list.append(web_page)
get_transaction().commit()
self.tic()
# in draft state no documents should belong to this Web Section
self.assertEqual(0, len(websection.getDocumentValueList()))
# when published all web pages should belong to it
for web_page in web_page_list:
web_page.publish()
get_transaction().commit()
self.tic()
self.assertEqual(2, len(websection.getDocumentValueList(limit=2)))
#Testing default behaviour
self.assertEqual(4, len(websection.getDocumentValueList()))
self.assertEqual(['en' , 'en', 'en', 'en'],
[ w.getLanguage() for w in websection.getDocumentValueList()])
pt_document_value_list = websection.getDocumentValueList(language='pt')
self.assertEqual(4, len(websection.getDocumentValueList()))
self.assertEqual(['pt' , 'pt', 'pt', 'pt'],
[ w.getObject().getLanguage() for w in pt_document_value_list])
ja_document_value_list = websection.getDocumentValueList(language='ja')
self.assertEqual(4, len(websection.getDocumentValueList()))
self.assertEqual(['ja' , 'ja', 'ja', 'ja'],
[ w.getLanguage() for w in ja_document_value_list])
#Testing default behaviour
en_document_value_list = websection.WebSection_getDocumentValueListBase(all_languages=1)
self.assertEqual(6, len(en_document_value_list))
self.assertEqual(4, len([ w.getLanguage() for w in en_document_value_list \
if w.getLanguage() == 'en']))
self.assertEqual(1, len([ w.getLanguage() for w in en_document_value_list \
if w.getLanguage() == 'pt']))
self.assertEqual(['3'], [ w.getVersion() for w in en_document_value_list \
if w.getLanguage() == 'pt'])
self.assertEqual(1, len([ w.getLanguage() for w in en_document_value_list \
if w.getLanguage() == 'ja']))
self.assertEqual(['3'], [ w.getVersion() for w in en_document_value_list \
if w.getLanguage() == 'ja'])
pt_document_value_list = websection.WebSection_getDocumentValueListBase(all_languages=1,
language='pt')
self.assertEqual(6, len(pt_document_value_list))
self.assertEqual(4, len([ w.getLanguage() for w in pt_document_value_list \
if w.getLanguage() == 'pt']))
self.assertEqual(1, len([ w.getLanguage() for w in pt_document_value_list \
if w.getLanguage() == 'en']))
self.assertEqual(['3'], [ w.getVersion() for w in pt_document_value_list \
if w.getLanguage() == 'en'])
self.assertEqual(1, len([ w.getLanguage() for w in pt_document_value_list \
if w.getLanguage() == 'ja']))
self.assertEqual(['3'], [ w.getVersion() for w in pt_document_value_list \
if w.getLanguage() == 'ja'])
ja_document_value_list = websection.WebSection_getDocumentValueListBase(all_languages=1,
language='ja')
self.assertEqual(6, len(ja_document_value_list))
self.assertEqual(4, len([ w.getLanguage() for w in ja_document_value_list \
if w.getLanguage() == 'ja']))
self.assertEqual(1, len([ w.getLanguage() for w in ja_document_value_list \
if w.getLanguage() == 'pt']))
self.assertEqual(['3'], [ w.getVersion() for w in ja_document_value_list \
if w.getLanguage() == 'pt'])
self.assertEqual(1, len([ w.getLanguage() for w in ja_document_value_list \
if w.getLanguage() == 'en']))
self.assertEqual(['3'], [ w.getVersion() for w in ja_document_value_list \
if w.getLanguage() == 'en'])
self.web_page_module.manage_delObjects(list(self.web_page_module.objectIds()))
class TestERP5WebWithSimpleSecurity(ERP5TypeTestCase): class TestERP5WebWithSimpleSecurity(ERP5TypeTestCase):
...@@ -863,5 +946,5 @@ class TestERP5WebWithSimpleSecurity(ERP5TypeTestCase): ...@@ -863,5 +946,5 @@ class TestERP5WebWithSimpleSecurity(ERP5TypeTestCase):
def test_suite(): def test_suite():
suite = unittest.TestSuite() suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestERP5Web)) suite.addTest(unittest.makeSuite(TestERP5Web))
suite.addTest(unittest.makeSuite(TestERP5WebWithSimpleSecurity)) #suite.addTest(unittest.makeSuite(TestERP5WebWithSimpleSecurity))
return suite return suite
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