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,7 +531,10 @@ class TestERP5Web(ERP5TypeTestCase, ZopeTestCase.Functional): ...@@ -530,7 +531,10 @@ 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
...@@ -554,14 +558,37 @@ class TestERP5Web(ERP5TypeTestCase, ZopeTestCase.Functional): ...@@ -554,14 +558,37 @@ class TestERP5Web(ERP5TypeTestCase, ZopeTestCase.Functional):
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 = [] web_page_list = []
for index in range(0, 10): property_dict = { '01' : dict(language = 'en' , version = "1" , reference = "A"),
'02' : dict(language = 'en' , version = "2" , reference = "B"),
'03' : dict(language = 'en' , version = "3" , reference = "C"),
'04' : dict(language = 'pt' , version = "1" , reference = "A"),
'05' : dict(language = 'pt' , version = "2" , reference = "C"),
'06' : dict(language = 'pt' , version = "3" , reference = "B"),
'07' : dict(language = 'ja' , version = "1" , reference = "C"),
'08' : dict(language = 'ja' , version = "2" , reference = "A"),
'09' : dict(language = 'ja' , version = "3" , reference = "B"),
'10' : dict(language = 'en' , version = "2" , reference = "D"),
'11' : dict(language = 'ja' , version = "3" , reference = "E"),
'12' : dict(language = 'pt' , version = "3" , reference = "F"),
'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( web_page = self.portal.web_page_module.newContent(
portal_type = 'Web Page', portal_type = 'Web Page',
language = 'en',
reference = web_page_reference %index,
publication_section_list=publication_section_category_id_list[:1]) 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) web_page_list.append(web_page)
get_transaction().commit() get_transaction().commit()
...@@ -574,10 +601,66 @@ class TestERP5Web(ERP5TypeTestCase, ZopeTestCase.Functional): ...@@ -574,10 +601,66 @@ class TestERP5Web(ERP5TypeTestCase, ZopeTestCase.Functional):
web_page.publish() web_page.publish()
get_transaction().commit() get_transaction().commit()
self.tic() self.tic()
self.assertEqual(len(web_page_list), len(websection.getDocumentValueList()))
# test if limit works self.assertEqual(2, len(websection.getDocumentValueList(limit=2)))
self.assertEqual(5, len(websection.getDocumentValueList(limit=5))) #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