Commit 906da8af authored by Xiaowu Zhang's avatar Xiaowu Zhang

erp5_web: test

parent de10f6e3
if context.getValidationState() == 'published' and context.getAggregateReference(): if context.getValidationState() == 'published' and context.getAggregateReference():
return context.generatePredicate() return context.generatePredicate(criterion_property_list = ('start_date',))
return None return None
...@@ -37,15 +37,14 @@ class TestWebCampaign(ERP5TypeTestCase): ...@@ -37,15 +37,14 @@ class TestWebCampaign(ERP5TypeTestCase):
Initial Test Data: Initial Test Data:
object type publication section follow up causality object type publication section follow up causality
test web page Web Page test_category_1 follow_up_project_1 test web page_1 Web Page test_category_1 follow_up_project_1
test web page_2 Web Page test_category_2 follow_up_project_2 test web page_2 Web Page test_category_2 follow_up_project_2
test_web_site Web Site test_web_site Web Site
test_valide_web_campaign_1 Web Campaign test_category_1 follow_up_project_1 test_valide_web_campaign_1 Web Campaign test_category_1 follow_up_project_1
test_valide_web_campaign_2 Web Campaign test_category_2 follow_up_project_2 test_valide_web_campaign_2 Web Campaign test_category_2 follow_up_project_2
test_valide_web_campaign_only_web_page Web Campaign test_web_page test_valide_web_campaign_only_web_page_1 Web Campaign test_web_page_1
test_valide_web_campaign_only_web_site Web Campaign test_web_site test_valide_web_campaign_only_web_site Web Campaign test_web_site
test_valide_web_campaign_both Web Campaign test_web_page test_web_site test_valide_web_campaign_only_web_page_2 test_web_page_1
''' '''
now = DateTime() now = DateTime()
...@@ -75,13 +74,13 @@ class TestWebCampaign(ERP5TypeTestCase): ...@@ -75,13 +74,13 @@ class TestWebCampaign(ERP5TypeTestCase):
id='test_web_campaign_default_page', id='test_web_campaign_default_page',
reference='test_web_campaign_default_page' reference='test_web_campaign_default_page'
) )
test_web_page = getattr(self.portal.web_page_module, 'test_web_page', None) test_web_page_1 = getattr(self.portal.web_page_module, 'test_web_page_1', None)
if not test_web_page: if not test_web_page_1:
test_web_page = self.portal.web_page_module.newContent( test_web_page_1 = self.portal.web_page_module.newContent(
portal_type='Web Page', portal_type='Web Page',
id='test_web_page' id='test_web_page_1'
) )
test_web_page.edit( test_web_page_1.edit(
publication_section='test_category_1', publication_section='test_category_1',
follow_up_value=follow_up_project_1, follow_up_value=follow_up_project_1,
reference='test_web_page_for_web_campaign' reference='test_web_page_for_web_campaign'
...@@ -107,11 +106,11 @@ class TestWebCampaign(ERP5TypeTestCase): ...@@ -107,11 +106,11 @@ class TestWebCampaign(ERP5TypeTestCase):
) )
self.test_web_site = test_web_site self.test_web_site = test_web_site
self.test_web_page = test_web_page self.test_web_page_1 = test_web_page_1
self.test_web_page_2 = test_web_page_2 self.test_web_page_2 = test_web_page_2
self.test_web_campaign_default_page = test_web_campaign_default_page self.test_web_campaign_default_page = test_web_campaign_default_page
if self.portal.portal_workflow.isTransitionPossible(test_web_page, 'publish'): if self.portal.portal_workflow.isTransitionPossible(test_web_page_1, 'publish'):
test_web_page.publish() test_web_page_1.publish()
if self.portal.portal_workflow.isTransitionPossible(test_web_page_2, 'publish'): if self.portal.portal_workflow.isTransitionPossible(test_web_page_2, 'publish'):
test_web_page_2.publish() test_web_page_2.publish()
...@@ -119,7 +118,7 @@ class TestWebCampaign(ERP5TypeTestCase): ...@@ -119,7 +118,7 @@ class TestWebCampaign(ERP5TypeTestCase):
test_web_campaign_default_page.publish() test_web_campaign_default_page.publish()
self.tic() self.tic()
for web_campaign_id in ['test_valide_web_campaign_1', 'test_valide_web_campaign_2', 'test_valide_web_campaign_only_web_page', 'test_valide_web_campaign_only_web_site', 'test_valide_web_campaign_both']: for web_campaign_id in ['test_valide_web_campaign_1', 'test_valide_web_campaign_2', 'test_valide_web_campaign_only_web_page_1', 'test_valide_web_campaign_only_web_site', 'test_valide_web_campaign_only_web_page_2']:
web_campaign = getattr(self.portal.web_campaign_module, web_campaign_id, None) web_campaign = getattr(self.portal.web_campaign_module, web_campaign_id, None)
if not web_campaign: if not web_campaign:
web_campaign = self.portal.web_campaign_module.newContent( web_campaign = self.portal.web_campaign_module.newContent(
...@@ -132,34 +131,40 @@ class TestWebCampaign(ERP5TypeTestCase): ...@@ -132,34 +131,40 @@ class TestWebCampaign(ERP5TypeTestCase):
web_campaign.edit( web_campaign.edit(
start_date_range_min = now -1, start_date_range_min = now -1,
start_date_range_max = now + 1, start_date_range_max = now + 1,
aggregate_value=test_web_campaign_default_page, aggregate_value=test_web_campaign_default_page
causality_value=None,
publication_section='',
follow_up=''
) )
self.portal.web_campaign_module.test_valide_web_campaign_1.edit( self.portal.web_campaign_module.test_valide_web_campaign_1.edit(
publication_section='test_category_1', membership_criterion_base_category_list = ['publication_section', 'follow_up'],
follow_up_value=follow_up_project_1 membership_criterion_category_list = ['publication_section/test_category_1', 'follow_up/project_module/follow_up_project_1']
) )
self.portal.web_campaign_module.test_valide_web_campaign_2.edit( self.portal.web_campaign_module.test_valide_web_campaign_2.edit(
publication_section='test_category_2', membership_criterion_base_category_list = ['publication_section', 'follow_up'],
follow_up_value=follow_up_project_2 membership_criterion_category_list = ['publication_section/test_category_2', 'follow_up/project_module/follow_up_project_2']
) )
self.portal.web_campaign_module.test_valide_web_campaign_only_web_page.edit( self.portal.web_campaign_module.test_valide_web_campaign_only_web_page_1.edit(
causality_value = self.test_web_page membership_criterion_base_category_list = [],
membership_criterion_category_list = []
) )
self.portal.web_campaign_module.test_valide_web_campaign_only_web_site.edit( self.portal.web_campaign_module.test_valide_web_campaign_only_web_page_2.edit(
causality_value = self.test_web_site membership_criterion_base_category_list = [],
membership_criterion_category_list = []
) )
self.portal.web_campaign_module.test_valide_web_campaign_both.edit( self.portal.web_campaign_module.test_valide_web_campaign_only_web_site.edit(
causality_value = [self.test_web_page, self.test_web_site] membership_criterion_base_category_list = [],
membership_criterion_category_list = []
) )
self.portal.web_campaign_module.test_valide_web_campaign_only_web_page_1.setCriterion('reference', self.test_web_page_1.getReference())
self.portal.web_campaign_module.test_valide_web_campaign_only_web_page_2.setCriterion('reference', self.test_web_page_1.getReference())
self.portal.web_campaign_module.test_valide_web_campaign_only_web_site.setCriterion('relative_url', self.test_web_site.getRelativeUrl())
self.portal.web_campaign_module.test_valide_web_campaign_only_web_site.setCriterion('reference', '')
self.test_valide_web_campaign_1 = self.portal.web_campaign_module.test_valide_web_campaign_1 self.test_valide_web_campaign_1 = self.portal.web_campaign_module.test_valide_web_campaign_1
self.test_valide_web_campaign_2 = self.portal.web_campaign_module.test_valide_web_campaign_2 self.test_valide_web_campaign_2 = self.portal.web_campaign_module.test_valide_web_campaign_2
self.test_valide_web_campaign_only_web_page = self.portal.web_campaign_module.test_valide_web_campaign_only_web_page self.test_valide_web_campaign_only_web_page_1 = self.portal.web_campaign_module.test_valide_web_campaign_only_web_page_1
self.test_valide_web_campaign_only_web_page_2 = self.portal.web_campaign_module.test_valide_web_campaign_only_web_page_2
self.test_valide_web_campaign_only_web_site = self.portal.web_campaign_module.test_valide_web_campaign_only_web_site self.test_valide_web_campaign_only_web_site = self.portal.web_campaign_module.test_valide_web_campaign_only_web_site
self.test_valide_web_campaign_both = self.portal.web_campaign_module.test_valide_web_campaign_both
self.web_page_to_delete_list = [] self.web_page_to_delete_list = []
self.tic() self.tic()
...@@ -171,7 +176,6 @@ class TestWebCampaign(ERP5TypeTestCase): ...@@ -171,7 +176,6 @@ class TestWebCampaign(ERP5TypeTestCase):
def testSearchWebCampaignForOnlyWebPageContext(self): def testSearchWebCampaignForOnlyWebPageContext(self):
web_campaign_list = self.test_web_page_2.Base_getWebCampaignValue(batch=1) web_campaign_list = self.test_web_page_2.Base_getWebCampaignValue(batch=1)
self.assertEqual(len(web_campaign_list), 1) self.assertEqual(len(web_campaign_list), 1)
#only test_valide_web_campaign_2 match
self.assertEqual(web_campaign_list[0], self.test_valide_web_campaign_2) self.assertEqual(web_campaign_list[0], self.test_valide_web_campaign_2)
self.test_valide_web_campaign_2.unpublish() self.test_valide_web_campaign_2.unpublish()
self.tic() self.tic()
...@@ -218,93 +222,84 @@ class TestWebCampaign(ERP5TypeTestCase): ...@@ -218,93 +222,84 @@ class TestWebCampaign(ERP5TypeTestCase):
self.assertEqual(self.test_web_page_2.Base_getWebCampaignValue(), None) self.assertEqual(self.test_web_page_2.Base_getWebCampaignValue(), None)
def testSearchWebCampaignForWebPage(self): def testSearchWebCampaignForWebPage(self):
web_campaign_list = self.test_web_page.Base_getWebCampaignValue(batch=1) web_campaign_list = self.test_web_page_1.Base_getWebCampaignValue(batch=1)
self.assertEqual(len(web_campaign_list), 3) self.assertEqual(len(web_campaign_list), 3)
self.assertTrue(self.test_valide_web_campaign_1 in web_campaign_list) self.assertTrue(self.test_valide_web_campaign_1 in web_campaign_list)
self.assertTrue(self.test_valide_web_campaign_only_web_page in web_campaign_list) self.assertTrue(self.test_valide_web_campaign_only_web_page_1 in web_campaign_list)
self.assertTrue(self.test_valide_web_campaign_both in web_campaign_list) self.assertTrue(self.test_valide_web_campaign_only_web_page_2 in web_campaign_list)
self.test_valide_web_campaign_only_web_page.edit( self.portal.web_campaign_module.test_valide_web_campaign_only_web_page_1.setCriterion('reference', self.test_web_page_2.getReference())
causality_value = self.test_web_page_2)
self.tic()
web_campaign_list = self.test_web_page.Base_getWebCampaignValue(batch=1) self.tic()
web_campaign_list = self.test_web_page_1.Base_getWebCampaignValue(batch=1)
self.assertEqual(len(web_campaign_list), 2) self.assertEqual(len(web_campaign_list), 2)
self.assertTrue(self.test_valide_web_campaign_1 in web_campaign_list) self.assertTrue(self.test_valide_web_campaign_1 in web_campaign_list)
self.assertTrue(self.test_valide_web_campaign_both in web_campaign_list) self.assertTrue(self.test_valide_web_campaign_only_web_page_2 in web_campaign_list)
self.test_valide_web_campaign_only_web_page.edit( self.portal.web_campaign_module.test_valide_web_campaign_only_web_page_1.setCriterion('reference', self.test_web_page_1.getReference())
causality_value = self.test_web_page, self.portal.web_campaign_module.test_valide_web_campaign_only_web_page_1.edit(
publication_section='test_category_2' membership_criterion_base_category_list = ['publication_section', 'follow_up'],
membership_criterion_category_list = ['publication_section/test_category_2', 'follow_up/project_module/follow_up_project_2']
) )
self.tic() self.tic()
web_campaign_list = self.test_web_page.Base_getWebCampaignValue(batch=1) web_campaign_list = self.test_web_page_1.Base_getWebCampaignValue(batch=1)
self.assertEqual(len(web_campaign_list), 2) self.assertEqual(len(web_campaign_list), 2)
self.assertTrue(self.test_valide_web_campaign_1 in web_campaign_list) self.assertTrue(self.test_valide_web_campaign_1 in web_campaign_list)
self.assertTrue(self.test_valide_web_campaign_both in web_campaign_list) self.assertTrue(self.test_valide_web_campaign_only_web_page_2 in web_campaign_list)
def testSearchWebCampaignForWebSite(self):
web_campaign_list = self.test_web_site.Base_getWebCampaignValue(batch=1)
self.assertEqual(len(web_campaign_list), 2)
self.assertTrue(self.test_valide_web_campaign_only_web_site in web_campaign_list)
self.assertTrue(self.test_valide_web_campaign_both in web_campaign_list)
self.test_valide_web_campaign_only_web_site.edit(
causality_value = self.test_web_page_2)
self.tic()
def testSearchWebCampaignForWebSite(self):
web_campaign_list = self.test_web_site.Base_getWebCampaignValue(batch=1) web_campaign_list = self.test_web_site.Base_getWebCampaignValue(batch=1)
self.assertEqual(len(web_campaign_list), 1) self.assertEqual(len(web_campaign_list), 1)
self.assertTrue(self.test_valide_web_campaign_both in web_campaign_list) self.assertTrue(self.test_valide_web_campaign_only_web_site in web_campaign_list)
self.test_valide_web_campaign_only_web_site.edit( self.portal.web_campaign_module.test_valide_web_campaign_only_web_site.setCriterion('reference', self.test_web_page_1.getReference())
causality_value = self.test_web_site,
publication_section='test_category_2'
)
self.tic() self.tic()
web_campaign_list = self.test_web_site.Base_getWebCampaignValue(batch=1)
self.assertEqual(len(web_campaign_list), 1)
self.assertTrue(self.test_valide_web_campaign_both in web_campaign_list)
web_campaign = self.test_web_site.Base_getWebCampaignValue()
self.assertEqual(web_campaign, None)
def testSearchWebCampaignForWebPageVersioning(self): def testSearchWebCampaignForWebPageVersioning(self):
# almost same as testSearchWebCampaignForWebPage, but we test with cloned web page # almost same as testSearchWebCampaignForWebPage, but we test with cloned web page
new_web_page = self.test_web_page.Base_createCloneDocument(batch_mode=True) new_web_page = self.test_web_page_1.Base_createCloneDocument(batch_mode=True)
new_web_page.edit(language='fr') new_web_page.edit(language='fr')
self.web_page_to_delete_list.append(new_web_page.getId()) self.web_page_to_delete_list.append(new_web_page.getId())
self.tic() self.tic()
web_campaign_list = new_web_page.Base_getWebCampaignValue(batch=1) web_campaign_list = new_web_page.Base_getWebCampaignValue(batch=1)
#self.assertEqual(len(web_campaign_list), 3) self.assertEqual(len(web_campaign_list), 3)
self.assertTrue(self.test_valide_web_campaign_1 in web_campaign_list) self.assertTrue(self.test_valide_web_campaign_1 in web_campaign_list)
self.assertTrue(self.test_valide_web_campaign_only_web_page in web_campaign_list) self.assertTrue(self.test_valide_web_campaign_only_web_page_1 in web_campaign_list)
self.assertTrue(self.test_valide_web_campaign_both in web_campaign_list) self.assertTrue(self.test_valide_web_campaign_only_web_page_2 in web_campaign_list)
self.test_valide_web_campaign_only_web_page.edit(
causality_value = self.test_web_page_2)
self.tic()
web_campaign_list = self.test_web_page.Base_getWebCampaignValue(batch=1) self.test_valide_web_campaign_only_web_page_1.setCriterion('reference', self.test_web_page_2.getReference())
self.tic()
web_campaign_list = self.test_web_page_1.Base_getWebCampaignValue(batch=1)
self.assertEqual(len(web_campaign_list), 2) self.assertEqual(len(web_campaign_list), 2)
self.assertTrue(self.test_valide_web_campaign_1 in web_campaign_list) self.assertTrue(self.test_valide_web_campaign_1 in web_campaign_list)
self.assertTrue(self.test_valide_web_campaign_both in web_campaign_list) self.assertTrue(self.test_valide_web_campaign_only_web_page_2 in web_campaign_list)
self.test_valide_web_campaign_only_web_page.edit(
causality_value = self.test_web_page, self.portal.web_campaign_module.test_valide_web_campaign_only_web_page_1.edit(
publication_section='test_category_2' membership_criterion_base_category_list = ['publication_section', 'follow_up'],
membership_criterion_category_list = ['publication_section/test_category_2', 'follow_up/project_module/follow_up_project_1']
) )
self.test_valide_web_campaign_only_web_page_1.setCriterion('reference', self.test_web_page_1.getReference())
self.tic() self.tic()
web_campaign_list = self.test_web_page.Base_getWebCampaignValue(batch=1) web_campaign_list = self.test_web_page_1.Base_getWebCampaignValue(batch=1)
self.assertEqual(len(web_campaign_list), 2) self.assertEqual(len(web_campaign_list), 2)
self.assertTrue(self.test_valide_web_campaign_1 in web_campaign_list) self.assertTrue(self.test_valide_web_campaign_1 in web_campaign_list)
self.assertTrue(self.test_valide_web_campaign_both in web_campaign_list) self.assertTrue(self.test_valide_web_campaign_only_web_page_2 in web_campaign_list)
def testSearchWebCampaignWithMultiMatch(self): def testSearchWebCampaignWithMultiMatch(self):
start_date_range_min = self.test_valide_web_campaign_1.getStartDateRangeMin() start_date_range_min = self.test_valide_web_campaign_1.getStartDateRangeMin()
self.test_valide_web_campaign_only_web_page.edit( self.test_valide_web_campaign_only_web_page_1.edit(
start_date_range_min= start_date_range_min - 1 start_date_range_min= start_date_range_min - 1
) )
self.test_valide_web_campaign_both.edit( self.test_valide_web_campaign_only_web_page_2.edit(
start_date_range_min=start_date_range_min - 2 start_date_range_min=start_date_range_min - 2
) )
self.tic() self.tic()
web_campaign_list = self.test_web_page.Base_getWebCampaignValue(batch=1) web_campaign_list = self.test_web_page_1.Base_getWebCampaignValue(batch=1)
self.assertEqual(len(web_campaign_list), 3) self.assertEqual(len(web_campaign_list), 3)
self.assertEqual(web_campaign_list[2], self.test_valide_web_campaign_1) self.assertEqual(web_campaign_list[2], self.test_valide_web_campaign_1)
self.assertEqual(web_campaign_list[1], self.test_valide_web_campaign_only_web_page) self.assertEqual(web_campaign_list[1], self.test_valide_web_campaign_only_web_page_1)
self.assertEqual(web_campaign_list[0], self.test_valide_web_campaign_both) self.assertEqual(web_campaign_list[0], self.test_valide_web_campaign_only_web_page_2)
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