Commit 9375dccd authored by Rafael Monnerat's avatar Rafael Monnerat

Pyflaked and "pep8"ed

parent f647e598
...@@ -32,8 +32,6 @@ import re ...@@ -32,8 +32,6 @@ import re
import unittest import unittest
import transaction import transaction
from AccessControl import Unauthorized from AccessControl import Unauthorized
from AccessControl.SecurityManagement import newSecurityManager
from AccessControl.SecurityManagement import getSecurityManager
from Testing import ZopeTestCase from Testing import ZopeTestCase
from Products.ERP5Type.TransactionalVariable import getTransactionalVariable from Products.ERP5Type.TransactionalVariable import getTransactionalVariable
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
...@@ -41,18 +39,19 @@ from Products.ERP5Type.tests.utils import DummyLocalizer ...@@ -41,18 +39,19 @@ from Products.ERP5Type.tests.utils import DummyLocalizer
from Products.ERP5Type.tests.utils import createZODBPythonScript from Products.ERP5Type.tests.utils import createZODBPythonScript
from Products.ERP5Type.tests.backportUnittest import expectedFailure from Products.ERP5Type.tests.backportUnittest import expectedFailure
LANGUAGE_LIST = ('en', 'fr', 'de', 'bg',) LANGUAGE_LIST = ('en', 'fr', 'de', 'bg', )
HTTP_OK = 200 HTTP_OK = 200
MOVED_TEMPORARILY = 302 MOVED_TEMPORARILY = 302
class TestERP5Web(ERP5TypeTestCase): class TestERP5Web(ERP5TypeTestCase):
"""Test for erp5_web business template. """Test for erp5_web business template.
""" """
manager_username = 'zope' manager_username = 'zope'
manager_password = 'zope' manager_password = 'zope'
website_id = 'test' website_id = 'test'
credential = '%s:%s' % (manager_username, manager_password) credential = '%s:%s' % (manager_username, manager_password)
def getTitle(self): def getTitle(self):
return "ERP5Web" return "ERP5Web"
...@@ -70,12 +69,14 @@ class TestERP5Web(ERP5TypeTestCase): ...@@ -70,12 +69,14 @@ class TestERP5Web(ERP5TypeTestCase):
portal = self.getPortal() portal = self.getPortal()
uf = portal.acl_users uf = portal.acl_users
uf._doAddUser(self.manager_username, self.manager_password, ['Manager'], []) uf._doAddUser(self.manager_username,
self.manager_password,
['Manager'], [])
self.login(self.manager_username) self.login(self.manager_username)
self.web_page_module = self.portal.getDefaultModule('Web Page Module') self.web_page_module = self.portal.getDefaultModule('Web Page Module')
self.web_site_module = self.portal.getDefaultModule('Web Site Module') self.web_site_module = self.portal.getDefaultModule('Web Site Module')
portal.Localizer.manage_changeDefaultLang(language = 'en') portal.Localizer.manage_changeDefaultLang(language='en')
self.portal_id = self.portal.getId() self.portal_id = self.portal.getId()
def clearModule(self, module): def clearModule(self, module):
...@@ -93,18 +94,17 @@ class TestERP5Web(ERP5TypeTestCase): ...@@ -93,18 +94,17 @@ class TestERP5Web(ERP5TypeTestCase):
Setup Web Site Setup Web Site
""" """
portal = self.getPortal() portal = self.getPortal()
request = self.app.REQUEST
# add supported languages for Localizer # add supported languages for Localizer
localizer = portal.Localizer localizer = portal.Localizer
for language in LANGUAGE_LIST: for language in LANGUAGE_LIST:
localizer.manage_addLanguage(language = language) localizer.manage_addLanguage(language=language)
# create website # create website
if hasattr(self.web_site_module, self.website_id): if hasattr(self.web_site_module, self.website_id):
self.web_site_module.manage_delObjects(self.website_id) self.web_site_module.manage_delObjects(self.website_id)
website = self.getPortal().web_site_module.newContent(portal_type = 'Web Site', website = self.web_site_module.newContent(portal_type='Web Site',
id = self.website_id, id=self.website_id,
**kw) **kw)
website.publish() website.publish()
self.stepTic() self.stepTic()
...@@ -114,11 +114,10 @@ class TestERP5Web(ERP5TypeTestCase): ...@@ -114,11 +114,10 @@ class TestERP5Web(ERP5TypeTestCase):
""" """
Setup Web Section Setup Web Section
""" """
web_site_module = self.portal.getDefaultModule('Web Site') website = self.web_site_module[self.website_id]
website = web_site_module[self.website_id]
websection = website.newContent(portal_type='Web Section', **kw) websection = website.newContent(portal_type='Web Section', **kw)
self.websection = websection self.websection = websection
kw = dict(criterion_property_list = 'portal_type', kw = dict(criterion_property_list='portal_type',
membership_criterion_base_category_list='', membership_criterion_base_category_list='',
membership_criterion_category_list='') membership_criterion_category_list='')
websection.edit(**kw) websection.edit(**kw)
...@@ -136,11 +135,6 @@ class TestERP5Web(ERP5TypeTestCase): ...@@ -136,11 +135,6 @@ class TestERP5Web(ERP5TypeTestCase):
Setup some Web Pages. Setup some Web Pages.
""" """
webpage_list = [] webpage_list = []
portal = self.getPortal()
request = self.app.REQUEST
web_site_module = self.portal.getDefaultModule('Web Site')
website = web_site_module[self.website_id]
# create sample web pages # create sample web pages
for language in language_list: for language in language_list:
if suffix is not None: if suffix is not None:
...@@ -167,9 +161,7 @@ class TestERP5Web(ERP5TypeTestCase): ...@@ -167,9 +161,7 @@ class TestERP5Web(ERP5TypeTestCase):
Test that a recataloging works for Web Site documents Test that a recataloging works for Web Site documents
""" """
self.setupWebSite() self.setupWebSite()
portal = self.getPortal() web_site = self.web_site_module[self.website_id]
web_site_module = self.portal.getDefaultModule('Web Site')
web_site = web_site_module[self.website_id]
self.assertTrue(web_site is not None) self.assertTrue(web_site is not None)
# Recatalog the Web Site document # Recatalog the Web Site document
...@@ -194,7 +186,7 @@ class TestERP5Web(ERP5TypeTestCase): ...@@ -194,7 +186,7 @@ class TestERP5Web(ERP5TypeTestCase):
if it is wrapped by certian column width. if it is wrapped by certian column width.
""" """
# disable portal_transforms cache # disable portal_transforms cache
self.portal.portal_transforms.max_sec_in_cache=-1 self.portal.portal_transforms.max_sec_in_cache = -1
page = self.web_page_module.newContent(portal_type='Web Page') page = self.web_page_module.newContent(portal_type='Web Page')
page.edit(text_content='<p>Hé Hé Hé!</p>') page.edit(text_content='<p>Hé Hé Hé!</p>')
self.stepTic() self.stepTic()
...@@ -211,21 +203,22 @@ Hé Hé Hé!""", page.asText().strip()) ...@@ -211,21 +203,22 @@ Hé Hé Hé!""", page.asText().strip())
self.setupWebSite() self.setupWebSite()
portal = self.getPortal() portal = self.getPortal()
request = self.app.REQUEST request = self.app.REQUEST
kw = dict(reference = 'web', kw = dict(reference='web',
first_name = 'TestFN', first_name='TestFN',
last_name = 'TestLN', last_name='TestLN',
default_email_text = 'test@test.com', default_email_text='test@test.com',
password = 'abc', password='abc',
password_confirm = 'abc',) password_confirm='abc',)
for key, item in kw.items(): for key, item in kw.items():
request.set('field_your_%s' %key, item) request.set('field_your_%s' % key, item)
website = portal.web_site_module[self.website_id] website = self.web_site_module[self.website_id]
website.WebSite_createWebSiteAccount('WebSite_viewRegistrationDialog') website.WebSite_createWebSiteAccount('WebSite_viewRegistrationDialog')
self.stepTic() self.stepTic()
# find person object by reference # find person object by reference
person = website.ERP5Site_getAuthenticatedMemberPersonValue(kw['reference']) person = website.ERP5Site_getAuthenticatedMemberPersonValue(
kw['reference'])
self.assertEquals(person.getReference(), kw['reference']) self.assertEquals(person.getReference(), kw['reference'])
self.assertEquals(person.getFirstName(), kw['first_name']) self.assertEquals(person.getFirstName(), kw['first_name'])
self.assertEquals(person.getLastName(), kw['last_name']) self.assertEquals(person.getLastName(), kw['last_name'])
...@@ -234,23 +227,25 @@ Hé Hé Hé!""", page.asText().strip()) ...@@ -234,23 +227,25 @@ Hé Hé Hé!""", page.asText().strip())
# check if user account is 'loggable' # check if user account is 'loggable'
uf = portal.acl_users uf = portal.acl_users
user = uf.getUserById( kw['reference']) user = uf.getUserById(kw['reference'])
self.assertEquals(str(user), kw['reference']) self.assertEquals(str(user), kw['reference'])
self.assertEquals(1, user.has_role(('Member', 'Authenticated',))) self.assertEquals(1, user.has_role(('Member', 'Authenticated',)))
self.login(kw['reference']) self.login(kw['reference'])
self.assertEquals(kw['reference'], str(self.portal.portal_membership.getAuthenticatedMember())) self.assertEquals(kw['reference'],
str(portal.portal_membership.getAuthenticatedMember()))
# test redirection to person oobject # test redirection to person oobject
path = website.absolute_url_path() + '/WebSite_redirectToUserView' path = website.absolute_url_path() + '/WebSite_redirectToUserView'
response = self.publish(path, '%s:%s' %(kw['reference'], kw['password'])) response = self.publish(path, '%s:%s' % (kw['reference'], kw['password']))
self.assertTrue(person.getRelativeUrl() in response.getHeader("Location")) self.assertTrue(person.getRelativeUrl() in response.getHeader("Location"))
# test redirecting to new Person preference # test redirecting to new Person preference
path = website.absolute_url_path() + '/WebSite_redirectToUserPreference' path = website.absolute_url_path() + '/WebSite_redirectToUserPreference'
response = self.publish(path, '%s:%s' %(kw['reference'], kw['password'])) response = self.publish(path, '%s:%s' % (kw['reference'], kw['password']))
self.assertTrue('portal_preferences' in response.getHeader("Location")) self.assertTrue('portal_preferences' in response.getHeader("Location"))
# one preference should be created for user # one preference should be created for user
self.assertEquals(1, self.portal.portal_catalog.countResults(**{'portal_type': 'Preference', self.assertEquals(1,
self.portal.portal_catalog.countResults(**{'portal_type': 'Preference',
'owner': kw['reference']})[0][0]) 'owner': kw['reference']})[0][0])
def test_04_WebPageTranslation(self): def test_04_WebPageTranslation(self):
...@@ -259,18 +254,17 @@ Hé Hé Hé!""", page.asText().strip()) ...@@ -259,18 +254,17 @@ Hé Hé Hé!""", page.asText().strip())
current user selected language in browser. current user selected language in browser.
""" """
portal = self.getPortal() portal = self.getPortal()
request = self.app.REQUEST
website = self.setupWebSite() website = self.setupWebSite()
websection = self.setupWebSection() websection = self.setupWebSection()
page_reference = 'default-webpage' page_reference = 'default-webpage'
webpage_list = self.setupWebSitePages(prefix = page_reference) webpage_list = self.setupWebSitePages(prefix=page_reference)
# set default web page for section # set default web page for section
found_by_reference = portal.portal_catalog(name = page_reference, found_by_reference = portal.portal_catalog(name=page_reference,
portal_type = 'Web Page') portal_type='Web Page')
found = found_by_reference[0].getObject() found = found_by_reference[0].getObject()
websection.edit(categories_list = ['aggregate/%s' %found.getRelativeUrl(),]) websection.edit(categories_list=['aggregate/%s' % found.getRelativeUrl()])
self.assertEqual([found.getReference(),], self.assertEqual([found.getReference()],
websection.getAggregateReferenceList()) websection.getAggregateReferenceList())
# even though we create many pages we should get only one # even though we create many pages we should get only one
# this is the most recent one since all share the same reference # this is the most recent one since all share the same reference
...@@ -283,14 +277,14 @@ Hé Hé Hé!""", page.asText().strip()) ...@@ -283,14 +277,14 @@ Hé Hé Hé!""", page.asText().strip())
# set default language in Localizer only to check that we get # set default language in Localizer only to check that we get
# the corresponding web page for language. # the corresponding web page for language.
# XXX: Extend API so we can select language from REQUEST # XXX: Extend API so we can select language from REQUEST
portal.Localizer.manage_changeDefaultLang(language = language) portal.Localizer.manage_changeDefaultLang(language=language)
default_document = websection.getDefaultDocumentValue() default_document = websection.getDefaultDocumentValue()
self.assertEquals(language, default_document.getLanguage()) self.assertEquals(language, default_document.getLanguage())
def test_05_WebPageTextContentSubstitutions(self): def test_05_WebPageTextContentSubstitutions(self):
""" """
Simple Case of showing the proper text content with and without a substitution Simple Case of showing the proper text content with and without a
mapping method. substitution mapping method.
In case of asText, the content should be replaced too In case of asText, the content should be replaced too
""" """
content = '<a href="${toto}">$titi</a>' content = '<a href="${toto}">$titi</a>'
...@@ -318,7 +312,8 @@ Hé Hé Hé!""", page.asText().strip()) ...@@ -318,7 +312,8 @@ Hé Hé Hé!""", page.asText().strip())
klass._getTestSubstitutionMapping = klass.getTestSubstitutionMapping klass._getTestSubstitutionMapping = klass.getTestSubstitutionMapping
document.setTextContentSubstitutionMappingMethodId('_getTestSubstitutionMapping') document.setTextContentSubstitutionMappingMethodId('_getTestSubstitutionMapping')
# Even with the same callable object, a restricted method id should not be callable. # Even with the same callable object, a restricted method
# id should not be callable.
self.assertRaises(Unauthorized, document.asStrippedHTML) self.assertRaises(Unauthorized, document.asStrippedHTML)
def test_06_DefaultDocumentForWebSection(self): def test_06_DefaultDocumentForWebSection(self):
...@@ -333,15 +328,15 @@ Hé Hé Hé!""", page.asText().strip()) ...@@ -333,15 +328,15 @@ Hé Hé Hé!""", page.asText().strip())
Note: due to generic ERP5 Web implementation this test highly depends Note: due to generic ERP5 Web implementation this test highly depends
on WebSection_geDefaulttDocumentValueList on WebSection_geDefaulttDocumentValueList
""" """
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']
# create pages belonging to this publication_section 'documentation' # create pages belonging to this publication_section 'documentation'
web_page_en = portal.web_page_module.newContent(portal_type = 'Web Page', web_page_en = self.web_page_module.newContent(
portal_type='Web Page',
id='section_home', id='section_home',
language = 'en', language='en',
reference='NXD-DDP', reference='NXD-DDP',
publication_section_list=publication_section_category_id_list[:1]) publication_section_list=publication_section_category_id_list[:1])
websection.setAggregateValue(web_page_en) websection.setAggregateValue(web_page_en)
...@@ -357,7 +352,8 @@ Hé Hé Hé!""", page.asText().strip()) ...@@ -357,7 +352,8 @@ Hé Hé Hé!""", page.asText().strip())
from Products.ERP5.Document.Document import Document from Products.ERP5.Document.Document import Document
base_list = re.findall(Document.base_parser, str(html_page)) base_list = re.findall(Document.base_parser, str(html_page))
base_url = base_list[0] base_url = base_list[0]
self.assertEqual(base_url, "%s/%s/" % (websection.absolute_url(), web_page_en.getReference())) self.assertEqual(base_url, "%s/%s/" % (websection.absolute_url(),
web_page_en.getReference()))
def test_06b_DefaultDocumentForWebSite(self): def test_06b_DefaultDocumentForWebSite(self):
""" """
...@@ -371,12 +367,11 @@ Hé Hé Hé!""", page.asText().strip()) ...@@ -371,12 +367,11 @@ Hé Hé Hé!""", page.asText().strip())
Note: due to generic ERP5 Web implementation this test highly depends Note: due to generic ERP5 Web implementation this test highly depends
on WebSection_geDefaulttDocumentValueList on WebSection_geDefaulttDocumentValueList
""" """
portal = self.getPortal()
website = self.setupWebSite() website = self.setupWebSite()
publication_section_category_id_list = ['documentation', 'administration'] publication_section_category_id_list = ['documentation', 'administration']
# create pages belonging to this publication_section 'documentation' # create pages belonging to this publication_section 'documentation'
web_page_en = portal.web_page_module.newContent(portal_type = 'Web Page', web_page_en = self.web_page_module.newContent(portal_type = 'Web Page',
id='site_home', id='site_home',
language = 'en', language = 'en',
reference='NXD-DDP-Site', reference='NXD-DDP-Site',
...@@ -417,31 +412,31 @@ Hé Hé Hé!""", page.asText().strip()) ...@@ -417,31 +412,31 @@ Hé Hé Hé!""", page.asText().strip())
portal.portal_categories.publication_section.newContent(portal_type = 'Category', portal.portal_categories.publication_section.newContent(portal_type = 'Category',
id = category_id) id = category_id)
property_dict = { '01' : dict(language = 'en' , version = "1" , reference = "A"), property_dict = {'01': dict(language='en', version="1", reference="A"),
'02' : dict(language = 'en' , version = "2" , reference = "B"), '02': dict(language='en', version="2", reference="B"),
'03' : dict(language = 'en' , version = "3" , reference = "C"), '03': dict(language='en', version="3", reference="C"),
'04' : dict(language = 'pt' , version = "1" , reference = "A"), '04': dict(language='pt', version="1", reference="A"),
'05' : dict(language = 'pt' , version = "2" , reference = "C"), '05': dict(language='pt', version="2", reference="C"),
'06' : dict(language = 'pt' , version = "3" , reference = "B"), '06': dict(language='pt', version="3", reference="B"),
'07' : dict(language = 'ja' , version = "1" , reference = "C"), '07': dict(language='ja', version="1", reference="C"),
'08' : dict(language = 'ja' , version = "2" , reference = "A"), '08': dict(language='ja', version="2", reference="A"),
'09' : dict(language = 'ja' , version = "3" , reference = "B"), '09': dict(language='ja', version="3", reference="B"),
'10' : dict(language = 'en' , version = "2" , reference = "D"), '10': dict(language='en', version="2", reference="D"),
'11' : dict(language = 'ja' , version = "3" , reference = "E"), '11': dict(language='ja', version="3", reference="E"),
'12' : dict(language = 'pt' , version = "3" , reference = "F"), '12': dict(language='pt', version="3", reference="F"),
'13' : dict(language = 'en' , version = "3" , reference = "D"), '13': dict(language='en', version="3", reference="D"),
'14' : dict(language = 'ja' , version = "2" , reference = "E"), '14': dict(language='ja', version="2", reference="E"),
'15' : dict(language = 'pt' , version = "2" , reference = "F"), '15': dict(language='pt', version="2", reference="F"),
'16' : dict(language = '' , version = "1" , reference = "A"), '16': dict(language='', version="1", reference="A"),
} }
sequence_one = property_dict.keys() sequence_one = property_dict.keys()
sequence_two = ['01', '13', '12', '09', '06', '15' , '04', '11', '02', '05', '03', sequence_two = ['01', '13', '12', '09', '06', '15', '04', '11', '02',
'07', '10', '08', '14', '16'] '05', '03', '07', '10', '08', '14', '16']
sequence_three = ['05', '12', '13', '14', '06', '09', '10', '07', '03', '01', '02', sequence_three = ['05', '12', '13', '14', '06', '09', '10', '07',
'11', '04', '08' , '15', '16'] '03', '01', '02', '11', '04', '08', '15', '16']
sequence_count = 0 sequence_count = 0
for sequence in [ sequence_one , sequence_two , sequence_three ]: for sequence in [sequence_one, sequence_two, sequence_three]:
sequence_count += 1 sequence_count += 1
message = '\ntest_07_WebSection_getDocumentValueList (Sequence %s)' \ message = '\ntest_07_WebSection_getDocumentValueList (Sequence %s)' \
% (sequence_count) % (sequence_count)
...@@ -449,7 +444,7 @@ Hé Hé Hé!""", page.asText().strip()) ...@@ -449,7 +444,7 @@ Hé Hé Hé!""", page.asText().strip())
web_page_list = [] web_page_list = []
for key in sequence: for key in sequence:
web_page = self.portal.web_page_module.newContent( web_page = self.web_page_module.newContent(
title=key, title=key,
portal_type = 'Web Page', portal_type = 'Web Page',
publication_section_list=publication_section_category_id_list[:1]) publication_section_list=publication_section_category_id_list[:1])
...@@ -472,105 +467,105 @@ Hé Hé Hé!""", page.asText().strip()) ...@@ -472,105 +467,105 @@ Hé Hé Hé!""", page.asText().strip())
# Testing for language parameter # Testing for language parameter
self.assertEqual(4, len(websection.getDocumentValueList())) self.assertEqual(4, len(websection.getDocumentValueList()))
self.assertEqual(['en' , 'en', 'en', 'en'], self.assertEqual(['en', 'en', 'en', 'en'],
[ w.getLanguage() for w in websection.getDocumentValueList()]) [w.getLanguage() for w in websection.getDocumentValueList()])
# Check that receiving an empty string as language parameter (as done # Check that receiving an empty string as language parameter (as done
# when using listbox search) correctly returns user language documents. # when using listbox search) correctly returns user language documents.
default_document_value_list = websection.getDocumentValueList(language='') default_document_value_list = websection.getDocumentValueList(language='')
self.assertEqual(4, len(default_document_value_list)) self.assertEqual(4, len(default_document_value_list))
self.assertEqual(['en', 'en', 'en', 'en'], self.assertEqual(['en', 'en', 'en', 'en'],
[ w.getLanguage() for w in default_document_value_list]) [w.getLanguage() for w in default_document_value_list])
pt_document_value_list = websection.getDocumentValueList(language='pt') pt_document_value_list = websection.getDocumentValueList(language='pt')
self.assertEqual(4, len(pt_document_value_list)) self.assertEqual(4, len(pt_document_value_list))
self.assertEqual(['pt' , 'pt', 'pt', 'pt'], self.assertEqual(['pt', 'pt', 'pt', 'pt'],
[ w.getObject().getLanguage() for w in pt_document_value_list]) [w.getObject().getLanguage() for w in pt_document_value_list])
ja_document_value_list = websection.getDocumentValueList(language='ja') ja_document_value_list = websection.getDocumentValueList(language='ja')
self.assertEqual(4, len(ja_document_value_list)) self.assertEqual(4, len(ja_document_value_list))
self.assertEqual(['ja' , 'ja', 'ja', 'ja'], self.assertEqual(['ja', 'ja', 'ja', 'ja'],
[ w.getLanguage() for w in ja_document_value_list]) [w.getLanguage() for w in ja_document_value_list])
bg_document_value_list = websection.getDocumentValueList(language='bg') bg_document_value_list = websection.getDocumentValueList(language='bg')
self.assertEqual(1, len(bg_document_value_list)) self.assertEqual(1, len(bg_document_value_list))
self.assertEqual([''], self.assertEqual([''],
[ w.getLanguage() for w in bg_document_value_list]) [w.getLanguage() for w in bg_document_value_list])
# Testing for all_versions parameter # Testing for all_versions parameter
en_document_value_list = websection.getDocumentValueList(all_versions=1) en_document_value_list = websection.getDocumentValueList(all_versions=1)
self.assertEqual(5, len(en_document_value_list)) self.assertEqual(5, len(en_document_value_list))
self.assertEqual(['en' , 'en', 'en', 'en', 'en'], self.assertEqual(['en', 'en', 'en', 'en', 'en'],
[ w.getLanguage() for w in en_document_value_list]) [w.getLanguage() for w in en_document_value_list])
pt_document_value_list = websection.getDocumentValueList(language='pt', pt_document_value_list = websection.getDocumentValueList(language='pt',
all_versions=1) all_versions=1)
self.assertEqual(5, len(pt_document_value_list)) self.assertEqual(5, len(pt_document_value_list))
self.assertEqual(['pt' , 'pt', 'pt', 'pt', 'pt'], self.assertEqual(['pt', 'pt', 'pt', 'pt', 'pt'],
[ w.getObject().getLanguage() for w in pt_document_value_list]) [w.getObject().getLanguage() for w in pt_document_value_list])
ja_document_value_list = websection.getDocumentValueList(language='ja', ja_document_value_list = websection.getDocumentValueList(language='ja',
all_versions=1) all_versions=1)
self.assertEqual(5, len(ja_document_value_list)) self.assertEqual(5, len(ja_document_value_list))
self.assertEqual(['ja' , 'ja', 'ja', 'ja', 'ja'], self.assertEqual(['ja', 'ja', 'ja', 'ja', 'ja'],
[ w.getLanguage() for w in ja_document_value_list]) [w.getLanguage() for w in ja_document_value_list])
# Tests for all_languages parameter # Tests for all_languages parameter
en_document_value_list = websection.WebSection_getDocumentValueListBase(all_languages=1) en_document_value_list = websection.WebSection_getDocumentValueListBase(all_languages=1)
self.assertEqual(6, len(en_document_value_list)) self.assertEqual(6, len(en_document_value_list))
self.assertEqual(4, len([ w.getLanguage() for w in en_document_value_list \ self.assertEqual(4, len([w.getLanguage() for w in en_document_value_list \
if w.getLanguage() == 'en'])) if w.getLanguage() == 'en']))
self.assertEqual(1, len([ w.getLanguage() for w in en_document_value_list \ self.assertEqual(1, len([w.getLanguage() for w in en_document_value_list \
if w.getLanguage() == 'pt'])) if w.getLanguage() == 'pt']))
self.assertEqual(['3'], [ w.getVersion() for w in en_document_value_list \ self.assertEqual(['3'], [w.getVersion() for w in en_document_value_list \
if w.getLanguage() == 'pt']) if w.getLanguage() == 'pt'])
self.assertEqual(1, len([ w.getLanguage() for w in en_document_value_list \ self.assertEqual(1, len([w.getLanguage() for w in en_document_value_list \
if w.getLanguage() == 'ja'])) if w.getLanguage() == 'ja']))
self.assertEqual(['3'], [ w.getVersion() for w in en_document_value_list \ self.assertEqual(['3'], [w.getVersion() for w in en_document_value_list \
if w.getLanguage() == 'ja']) if w.getLanguage() == 'ja'])
pt_document_value_list = websection.WebSection_getDocumentValueListBase(all_languages=1, pt_document_value_list = websection.WebSection_getDocumentValueListBase(all_languages=1,
language='pt') language='pt')
self.assertEqual(6, len(pt_document_value_list)) self.assertEqual(6, len(pt_document_value_list))
self.assertEqual(4, len([ w.getLanguage() for w in pt_document_value_list \ self.assertEqual(4, len([w.getLanguage() for w in pt_document_value_list \
if w.getLanguage() == 'pt'])) if w.getLanguage() == 'pt']))
self.assertEqual(1, len([ w.getLanguage() for w in pt_document_value_list \ self.assertEqual(1, len([w.getLanguage() for w in pt_document_value_list \
if w.getLanguage() == 'en'])) if w.getLanguage() == 'en']))
self.assertEqual(['3'], [ w.getVersion() for w in pt_document_value_list \ self.assertEqual(['3'], [w.getVersion() for w in pt_document_value_list \
if w.getLanguage() == 'en']) if w.getLanguage() == 'en'])
self.assertEqual(1, len([ w.getLanguage() for w in pt_document_value_list \ self.assertEqual(1, len([w.getLanguage() for w in pt_document_value_list \
if w.getLanguage() == 'ja'])) if w.getLanguage() == 'ja']))
self.assertEqual(['3'], [ w.getVersion() for w in pt_document_value_list \ self.assertEqual(['3'], [w.getVersion() for w in pt_document_value_list \
if w.getLanguage() == 'ja']) if w.getLanguage() == 'ja'])
ja_document_value_list = websection.WebSection_getDocumentValueListBase(all_languages=1, ja_document_value_list = websection.WebSection_getDocumentValueListBase(all_languages=1,
language='ja') language='ja')
self.assertEqual(6, len(ja_document_value_list)) self.assertEqual(6, len(ja_document_value_list))
self.assertEqual(4, len([ w.getLanguage() for w in ja_document_value_list \ self.assertEqual(4, len([w.getLanguage() for w in ja_document_value_list \
if w.getLanguage() == 'ja'])) if w.getLanguage() == 'ja']))
self.assertEqual(1, len([ w.getLanguage() for w in ja_document_value_list \ self.assertEqual(1, len([w.getLanguage() for w in ja_document_value_list \
if w.getLanguage() == 'pt'])) if w.getLanguage() == 'pt']))
self.assertEqual(['3'], [ w.getVersion() for w in ja_document_value_list \ self.assertEqual(['3'], [w.getVersion() for w in ja_document_value_list \
if w.getLanguage() == 'pt']) if w.getLanguage() == 'pt'])
self.assertEqual(1, len([ w.getLanguage() for w in ja_document_value_list \ self.assertEqual(1, len([w.getLanguage() for w in ja_document_value_list \
if w.getLanguage() == 'en'])) if w.getLanguage() == 'en']))
self.assertEqual(['3'], [ w.getVersion() for w in ja_document_value_list \ self.assertEqual(['3'], [w.getVersion() for w in ja_document_value_list \
if w.getLanguage() == 'en']) if w.getLanguage() == 'en'])
bg_document_value_list = websection.WebSection_getDocumentValueListBase(all_languages=1, bg_document_value_list = websection.WebSection_getDocumentValueListBase(all_languages=1,
language='bg') language='bg')
self.assertEqual(6, len(bg_document_value_list)) self.assertEqual(6, len(bg_document_value_list))
self.assertEqual(0, len([ w.getLanguage() for w in bg_document_value_list \ self.assertEqual(0, len([w.getLanguage() for w in bg_document_value_list \
if w.getLanguage() == 'bg'])) if w.getLanguage() == 'bg']))
self.assertEqual(3, len([ w.getLanguage() for w in bg_document_value_list \ self.assertEqual(3, len([w.getLanguage() for w in bg_document_value_list \
if w.getLanguage() == 'en'])) if w.getLanguage() == 'en']))
self.assertEqual(1, len([ w.getLanguage() for w in bg_document_value_list \ self.assertEqual(1, len([w.getLanguage() for w in bg_document_value_list \
if w.getLanguage() == 'pt'])) if w.getLanguage() == 'pt']))
self.assertEqual(['3'], [ w.getVersion() for w in bg_document_value_list \ self.assertEqual(['3'], [w.getVersion() for w in bg_document_value_list \
if w.getLanguage() == 'pt']) if w.getLanguage() == 'pt'])
self.assertEqual(1, len([ w.getLanguage() for w in bg_document_value_list \ self.assertEqual(1, len([w.getLanguage() for w in bg_document_value_list \
if w.getLanguage() == 'ja'])) if w.getLanguage() == 'ja']))
self.assertEqual(['3'], [ w.getVersion() for w in bg_document_value_list \ self.assertEqual(['3'], [w.getVersion() for w in bg_document_value_list \
if w.getLanguage() == 'ja']) if w.getLanguage() == 'ja'])
# Tests for all_languages and all_versions # Tests for all_languages and all_versions
...@@ -585,51 +580,51 @@ Hé Hé Hé!""", page.asText().strip()) ...@@ -585,51 +580,51 @@ Hé Hé Hé!""", page.asText().strip())
all_versions=1, all_versions=1,
language='ja') language='ja')
for document_value_list in [ en_document_value_list, pt_document_value_list , for document_value_list in [en_document_value_list, pt_document_value_list,
ja_document_value_list]: ja_document_value_list]:
self.assertEqual(16, len(document_value_list)) self.assertEqual(16, len(document_value_list))
self.assertEqual(5, len([ w.getLanguage() for w in document_value_list \ self.assertEqual(5, len([w.getLanguage() for w in document_value_list \
if w.getLanguage() == 'en'])) if w.getLanguage() == 'en']))
self.assertEqual(5, len([ w.getLanguage() for w in en_document_value_list \ self.assertEqual(5, len([w.getLanguage() for w in en_document_value_list \
if w.getLanguage() == 'pt'])) if w.getLanguage() == 'pt']))
self.assertEqual(5, len([ w.getLanguage() for w in en_document_value_list \ self.assertEqual(5, len([w.getLanguage() for w in en_document_value_list \
if w.getLanguage() == 'ja'])) if w.getLanguage() == 'ja']))
# Tests for sort_on parameter # Tests for sort_on parameter
self.assertEqual(['A' , 'B', 'C', 'D'], self.assertEqual(['A', 'B', 'C', 'D'],
[ w.getReference() for w in \ [w.getReference() for w in \
websection.getDocumentValueList(sort_on=[('reference', 'ASC')])]) websection.getDocumentValueList(sort_on=[('reference', 'ASC')])])
self.assertEqual(['01' , '02', '03', '13'], self.assertEqual(['01', '02', '03', '13'],
[ w.getTitle() for w in \ [w.getTitle() for w in \
websection.getDocumentValueList(sort_on=[('title', 'ASC')])]) websection.getDocumentValueList(sort_on=[('title', 'ASC')])])
self.assertEqual(['D' , 'C', 'B', 'A'], self.assertEqual(['D', 'C', 'B', 'A'],
[ w.getReference() for w in \ [w.getReference() for w in \
websection.getDocumentValueList(sort_on=[('reference', 'DESC')])]) websection.getDocumentValueList(sort_on=[('reference', 'DESC')])])
self.assertEqual(['13' , '03', '02', '01'], self.assertEqual(['13', '03', '02', '01'],
[ w.getTitle() for w in \ [w.getTitle() for w in \
websection.getDocumentValueList(sort_on=[('reference', 'DESC')])]) websection.getDocumentValueList(sort_on=[('reference', 'DESC')])])
self.assertEqual(['A' , 'B', 'C', 'D' , 'E' , 'F'], self.assertEqual(['A', 'B', 'C', 'D', 'E', 'F'],
[ w.getReference() for w in \ [w.getReference() for w in \
websection.WebSection_getDocumentValueListBase(all_languages=1, websection.WebSection_getDocumentValueListBase(all_languages=1,
sort_on=[('reference', 'ASC')])]) sort_on=[('reference', 'ASC')])])
self.assertEqual(['01' , '02', '03', '11' , '12' , '13'], self.assertEqual(['01', '02', '03', '11', '12', '13'],
[ w.getTitle() for w in \ [w.getTitle() for w in \
websection.WebSection_getDocumentValueListBase(all_languages=1, websection.WebSection_getDocumentValueListBase(all_languages=1,
sort_on=[('title', 'ASC')])]) sort_on=[('title', 'ASC')])])
self.assertEqual(['F' , 'E', 'D', 'C' , 'B' , 'A'], self.assertEqual(['F', 'E', 'D', 'C', 'B', 'A'],
[ w.getReference() for w in \ [w.getReference() for w in \
websection.WebSection_getDocumentValueListBase(all_languages=1, websection.WebSection_getDocumentValueListBase(all_languages=1,
sort_on=[('reference', 'DESC')])]) sort_on=[('reference', 'DESC')])])
self.assertEqual(['13' , '12', '11', '03' , '02' , '01'], self.assertEqual(['13', '12', '11', '03', '02', '01'],
[ w.getTitle() for w in \ [w.getTitle() for w in \
websection.WebSection_getDocumentValueListBase(all_languages=1, websection.WebSection_getDocumentValueListBase(all_languages=1,
sort_on=[('title', 'DESC')])]) sort_on=[('title', 'DESC')])])
...@@ -756,14 +751,12 @@ Hé Hé Hé!""", page.asText().strip()) ...@@ -756,14 +751,12 @@ Hé Hé Hé!""", page.asText().strip())
web_page_portal_type = 'Web Page' web_page_portal_type = 'Web Page'
# Create web site and web section # Create web site and web section
web_site_module = portal.getDefaultModule(web_site_portal_type) web_site = self.web_site_module.newContent(portal_type=web_site_portal_type)
web_site = web_site_module.newContent(portal_type=web_site_portal_type)
web_section = web_site.newContent(portal_type=web_section_portal_type) web_section = web_site.newContent(portal_type=web_section_portal_type)
sub_web_section = web_section.newContent(portal_type=web_section_portal_type) sub_web_section = web_section.newContent(portal_type=web_section_portal_type)
# Create a document # Create a document
web_page_module = portal.getDefaultModule(web_page_portal_type) web_page = self.web_page_module.newContent(portal_type=web_page_portal_type)
web_page = web_page_module.newContent(portal_type=web_page_portal_type)
# Commit transaction # Commit transaction
def _commit(): def _commit():
...@@ -933,7 +926,6 @@ Hé Hé Hé!""", page.asText().strip()) ...@@ -933,7 +926,6 @@ Hé Hé Hé!""", page.asText().strip())
response = self.publish(path, self.credential) response = self.publish(path, self.credential)
self.assertNotEquals(response.getBody().find(new_content), -1) self.assertNotEquals(response.getBody().find(new_content), -1)
def test_13a_DocumentMovedCache(self): def test_13a_DocumentMovedCache(self):
""" """
What happens to the cache if document is moved What happens to the cache if document is moved
...@@ -1040,7 +1032,6 @@ Hé Hé Hé!""", page.asText().strip()) ...@@ -1040,7 +1032,6 @@ Hé Hé Hé!""", page.asText().strip())
response = self.publish(path, self.credential) response = self.publish(path, self.credential)
self.assertNotEquals(response.getBody().find(new_content), -1) self.assertNotEquals(response.getBody().find(new_content), -1)
def test_14_AccessWebSiteForWithDifferentUserPreferences(self): def test_14_AccessWebSiteForWithDifferentUserPreferences(self):
"""Check that Ram Cache Manager do not mix websection """Check that Ram Cache Manager do not mix websection
rendering between users. rendering between users.
...@@ -1121,7 +1112,6 @@ Hé Hé Hé!""", page.asText().strip()) ...@@ -1121,7 +1112,6 @@ Hé Hé Hé!""", page.asText().strip())
Policy ID - unauthenticated web pages Policy ID - unauthenticated web pages
authenticated authenticated
""" """
request = self.portal.REQUEST
website = self.setupWebSite() website = self.setupWebSite()
web_section_portal_type = 'Web Section' web_section_portal_type = 'Web Section'
web_section = website.newContent(portal_type=web_section_portal_type) web_section = website.newContent(portal_type=web_section_portal_type)
...@@ -1185,9 +1175,6 @@ Hé Hé Hé!""", page.asText().strip()) ...@@ -1185,9 +1175,6 @@ Hé Hé Hé!""", page.asText().strip())
- Access it using another language and edit it - Access it using another language and edit it
- Check that web section is correctly indexed - Check that web section is correctly indexed
""" """
portal = self.getPortal()
request = self.app.REQUEST
language = 'de' language = 'de'
website = self.setupWebSite() website = self.setupWebSite()
...@@ -1244,9 +1231,6 @@ Hé Hé Hé!""", page.asText().strip()) ...@@ -1244,9 +1231,6 @@ Hé Hé Hé!""", page.asText().strip())
- Access it using another language and edit it - Access it using another language and edit it
- Check that web site is correctly modified - Check that web site is correctly modified
""" """
portal = self.getPortal()
request = self.app.REQUEST
language = 'de' language = 'de'
website = self.setupWebSite() website = self.setupWebSite()
...@@ -1296,7 +1280,6 @@ Hé Hé Hé!""", page.asText().strip()) ...@@ -1296,7 +1280,6 @@ Hé Hé Hé!""", page.asText().strip())
""" """
Check if isWebMode & isEditableMode API works. Check if isWebMode & isEditableMode API works.
""" """
portal = self.getPortal()
request = self.app.REQUEST request = self.app.REQUEST
website = self.setupWebSite() website = self.setupWebSite()
...@@ -1326,19 +1309,18 @@ Hé Hé Hé!""", page.asText().strip()) ...@@ -1326,19 +1309,18 @@ Hé Hé Hé!""", page.asText().strip())
""" """
Test Web Site map script. Test Web Site map script.
""" """
portal = self.getPortal()
request = self.app.REQUEST request = self.app.REQUEST
website = self.setupWebSite() website = self.setupWebSite()
kw = {'depth': 5, kw = {'depth': 5,
'include_subsection':1} 'include_subsection': 1}
website.setSiteMapSectionParent(1) website.setSiteMapSectionParent(1)
websection1 = website.newContent(portal_type='Web Section', websection1 = website.newContent(portal_type='Web Section',
title = 'Section 1', title='Section 1',
site_map_section_parent=1, site_map_section_parent=1,
visible=1) visible=1)
websection1_1 = websection1.newContent(portal_type='Web Section', websection1_1 = websection1.newContent(portal_type='Web Section',
title = 'Section 1.1', title='Section 1.1',
site_map_section_parent=1, site_map_section_parent=1,
visible=1) visible=1)
self.stepTic() self.stepTic()
...@@ -1356,7 +1338,6 @@ Hé Hé Hé!""", page.asText().strip()) ...@@ -1356,7 +1338,6 @@ Hé Hé Hé!""", page.asText().strip())
self.assertSameSet([websection1.getTitle()], self.assertSameSet([websection1.getTitle()],
[x['translated_title'] for x in site_map]) [x['translated_title'] for x in site_map])
# hide subsections # hide subsections
websection1_1.setSiteMapSectionParent(0) websection1_1.setSiteMapSectionParent(0)
websection1_1.setVisible(0) websection1_1.setVisible(0)
...@@ -1502,8 +1483,7 @@ class TestERP5WebWithSimpleSecurity(ERP5TypeTestCase): ...@@ -1502,8 +1483,7 @@ class TestERP5WebWithSimpleSecurity(ERP5TypeTestCase):
def test_03_WebSection_getDocumentValueListSecurity(self): def test_03_WebSection_getDocumentValueListSecurity(self):
""" Test WebSection_getDocumentValueList behaviour and security""" """ Test WebSection_getDocumentValueList behaviour and security"""
self.login('admin') self.login('admin')
web_site_module = self.portal.web_site_module site = self.web_site_module.newContent(portal_type='Web Site',
site = web_site_module.newContent(portal_type='Web Site',
id='site') id='site')
site.publish() site.publish()
...@@ -1639,8 +1619,7 @@ class TestERP5WebWithSimpleSecurity(ERP5TypeTestCase): ...@@ -1639,8 +1619,7 @@ class TestERP5WebWithSimpleSecurity(ERP5TypeTestCase):
def test_04_ExpireUserAction(self): def test_04_ExpireUserAction(self):
""" Test the expire user action""" """ Test the expire user action"""
self.login('admin') self.login('admin')
web_site_module = self.portal.web_site_module site = self.web_site_module.newContent(portal_type='Web Site', id='site')
site = web_site_module.newContent(portal_type='Web Site', id='site')
# create websections in a site and in anothers web sections # create websections in a site and in anothers web sections
section_1 = site.newContent(portal_type='Web Section', id='section_1') section_1 = site.newContent(portal_type='Web Section', id='section_1')
...@@ -1670,7 +1649,7 @@ class TestERP5WebWithSimpleSecurity(ERP5TypeTestCase): ...@@ -1670,7 +1649,7 @@ class TestERP5WebWithSimpleSecurity(ERP5TypeTestCase):
def test_05_createWebSite(self): def test_05_createWebSite(self):
""" Test to create or clone web sites with many users """ """ Test to create or clone web sites with many users """
self.login('admin') self.login('admin')
web_site_module = self.portal.web_site_module web_site_module = self.web_site_module
# test for admin # test for admin
try: try:
...@@ -1693,8 +1672,7 @@ class TestERP5WebWithSimpleSecurity(ERP5TypeTestCase): ...@@ -1693,8 +1672,7 @@ class TestERP5WebWithSimpleSecurity(ERP5TypeTestCase):
def test_06_createWebSection(self): def test_06_createWebSection(self):
""" Test to create or clone web sections with many users """ """ Test to create or clone web sections with many users """
self.login('admin') self.login('admin')
web_site_module = self.portal.web_site_module site = self.web_site_module.newContent(portal_type='Web Site', id='site')
site = web_site_module.newContent(portal_type='Web Site', id='site')
# test for admin # test for admin
try: try:
...@@ -1806,7 +1784,7 @@ class TestERP5WebWithSimpleSecurity(ERP5TypeTestCase): ...@@ -1806,7 +1784,7 @@ class TestERP5WebWithSimpleSecurity(ERP5TypeTestCase):
pass pass
try: try:
new_category_3 = publication_section.newContent( new_category_3 = publication_section.newContent(
portal_type='Category',id='new_category_3') portal_type='Category', id='new_category_3')
new_category_4 = new_category_3.newContent(portal_type='Category', new_category_4 = new_category_3.newContent(portal_type='Category',
id='new_category_4') id='new_category_4')
except Unauthorized: except Unauthorized:
...@@ -1839,7 +1817,7 @@ class TestERP5WebWithSimpleSecurity(ERP5TypeTestCase): ...@@ -1839,7 +1817,7 @@ class TestERP5WebWithSimpleSecurity(ERP5TypeTestCase):
project.validate() project.validate()
self.stepTic() self.stepTic()
website = self.portal.web_site_module.newContent(portal_type='Web Site', website = self.web_site_module.newContent(portal_type='Web Site',
id='site') id='site')
website.publish() website.publish()
website.setMembershipCriterionBaseCategory('follow_up') website.setMembershipCriterionBaseCategory('follow_up')
...@@ -1876,9 +1854,8 @@ class TestERP5WebWithSimpleSecurity(ERP5TypeTestCase): ...@@ -1876,9 +1854,8 @@ class TestERP5WebWithSimpleSecurity(ERP5TypeTestCase):
""" """
Test that by default Anonymous User cannot access Web Site Module Test that by default Anonymous User cannot access Web Site Module
""" """
portal = self.portal
self.logout() self.logout()
self.assertRaises(Unauthorized, portal.web_site_module.view) self.assertRaises(Unauthorized, self.web_site_module.view)
class TestERP5WebCategoryPublicationWorkflow(ERP5TypeTestCase): class TestERP5WebCategoryPublicationWorkflow(ERP5TypeTestCase):
...@@ -1911,6 +1888,7 @@ class TestERP5WebCategoryPublicationWorkflow(ERP5TypeTestCase): ...@@ -1911,6 +1888,7 @@ class TestERP5WebCategoryPublicationWorkflow(ERP5TypeTestCase):
self.doActionFor(self.category, 'expire_action') self.doActionFor(self.category, 'expire_action')
self.assertEqual('expired_published', self.category.getValidationState()) self.assertEqual('expired_published', self.category.getValidationState())
def test_suite(): def test_suite():
suite = unittest.TestSuite() suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestERP5Web)) suite.addTest(unittest.makeSuite(TestERP5Web))
......
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