def test_all_modules_glob(self): r = Rule(""" applicable(is_block) error_if(len(list(all_modules)) == 2) """) s = r.apply(self.teaser, IRuleGlobs(self.teaser)) self.assertNotEqual(zeit.edit.rule.ERROR, s.status) self.cp['lead'].create_item('teaser') s = r.apply(self.teaser, IRuleGlobs(self.teaser)) self.assertEqual(zeit.edit.rule.ERROR, s.status)
def test_cp_type_glob(self): r = Rule(""" applicable(cp_type == 'homepage') error_if(True) """) s = r.apply(self.teaser, IRuleGlobs(self.teaser)) self.assertNotEqual(zeit.edit.rule.ERROR, s.status) self.cp.type = u'homepage' s = r.apply(self.teaser, IRuleGlobs(self.teaser)) self.assertEqual(zeit.edit.rule.ERROR, s.status)
def test_centerpage_glob(self): r = Rule(""" applicable(is_block) error_if(centerpage.title == 'foo') """) s = r.apply(self.teaser, IRuleGlobs(self.teaser)) self.assertNotEqual(zeit.edit.rule.ERROR, s.status) self.cp.title = u'foo' s = r.apply(self.teaser, IRuleGlobs(self.teaser)) self.assertEqual(zeit.edit.rule.ERROR, s.status)
def test_content_glob(self): r = Rule(""" applicable(is_block and content) error_if(True) """) s = r.apply(self.teaser, IRuleGlobs(self.teaser)) self.assertNotEqual(zeit.edit.rule.ERROR, s.status) self.teaser.insert( 0, zeit.cms.interfaces.ICMSContent('http://xml.zeit.de/testcontent')) s = r.apply(self.teaser, IRuleGlobs(self.teaser)) self.assertEqual(zeit.edit.rule.ERROR, s.status)
def test_gives_error_if_required_image_scale_is_missing(self): r = Rule(""" applicable(imagegroup) error_if('120x120' not in provided_scales, u'Scale 120x120 is missing') """) s = r.apply( # error since scale is missing self.group, IRuleGlobs(self.group)) self.assertEquals(zeit.edit.rule.ERROR, s.status) self.repository['group']['group-120x120.jpg'] = create_local_image( 'new-hampshire-artikel.jpg') s = r.apply( # added scale, no error anymore self.group, IRuleGlobs(self.group)) self.assertNotEquals(zeit.edit.rule.ERROR, s.status)
def test_imagegroup_is_only_applicable_for_IImageGroup(self): r = Rule(""" applicable(imagegroup) error_if(True, u'Context is an ImageGroup') """) # applicable for image group s = r.apply(self.group, IRuleGlobs(self.group)) self.assertEquals(zeit.edit.rule.ERROR, s.status) # not applicable for image self.repository['group']['group-120x120.jpg'] = create_local_image( 'new-hampshire-artikel.jpg') s = r.apply(self.group['group-120x120.jpg'], IRuleGlobs(self.group['group-120x120.jpg'])) self.assertNotEquals(zeit.edit.rule.ERROR, s.status)
def test_feature_is_a_region(self): r = Rule(""" applicable(is_region) error_if(True) """) s = r.apply(self.cp['feature'], IRuleGlobs(self.cp['feature'])) self.assertEqual(zeit.edit.rule.ERROR, s.status)
def test_area_is_not_a_region(self): area = self.cp['feature'].create_item('area') r = Rule(""" applicable(is_region) error_if(True) """) s = r.apply(area, IRuleGlobs(area)) self.assertNotEqual(zeit.edit.rule.ERROR, s.status)
def test_content_glob_is_empty_for_non_content_blocks(self): r = Rule(""" applicable(is_block) error_unless(content == []) """) area = self.cp['informatives'].create_item('xml') s = r.apply(area, IRuleGlobs(area)) self.assertNotEqual(zeit.edit.rule.ERROR, s.status)
def setUp(self): super(RuleTest, self).setUp() from zeit.newsletter.newsletter import Newsletter from zeit.newsletter.category import NewsletterCategory category = NewsletterCategory() category.ad_middle_groups_above = 42 category.ad_thisweeks_groups_above = 63 self.repository['category'] = category self.category = self.repository['category'] self.category['newsletter'] = Newsletter() self.newsletter = self.category['newsletter'] factory = zope.component.getAdapter( self.newsletter.body, zeit.edit.interfaces.IElementFactory, name='group') group = factory() self.globs = IRuleGlobs(group)
class RuleTest(zeit.newsletter.testing.TestCase): def setUp(self): super(RuleTest, self).setUp() from zeit.newsletter.newsletter import Newsletter from zeit.newsletter.category import NewsletterCategory category = NewsletterCategory() category.ad_middle_groups_above = 42 category.ad_thisweeks_groups_above = 63 self.repository['category'] = category self.category = self.repository['category'] self.category['newsletter'] = Newsletter() self.newsletter = self.category['newsletter'] factory = zope.component.getAdapter( self.newsletter.body, zeit.edit.interfaces.IElementFactory, name='group') group = factory() self.globs = IRuleGlobs(group) def test_newsletter_can_be_determined_from_body_element(self): self.assertTrue(self.globs.get('newsletter', False)) def test_newsletter_retrieval_handles_non_newsletter_elements(self): body = self.newsletter.body body.__parent__ = None globs = IRuleGlobs(body.values()[0]) self.assertFalse(globs.get('newsletter', False)) def test_middle_ad_position_is_read_from_newsletter_category(self): self.assertEqual(43, self.globs['middle_ad_position']) def test_thisweeks_ad_position_is_read_from_newsletter_category(self): self.assertEqual(64, self.globs['thisweeks_ad_position']) def test_middle_ad_position_handles_non_news_letter_elements(self): body = self.newsletter.body body.__parent__ = None globs = IRuleGlobs(body.values()[0]) self.assertEqual('__NONE__', globs['middle_ad_position']) def test_thisweeks_ad_position_handles_non_news_letter_elements(self): body = self.newsletter.body body.__parent__ = None globs = IRuleGlobs(body.values()[0]) self.assertEqual('__NONE__', globs['thisweeks_ad_position']) def test_middle_ad_position_handles_missing_category(self): self.repository['newsletter'] = self.newsletter globs = IRuleGlobs(self.newsletter.body.values()[0]) self.assertEqual('__NONE__', globs['middle_ad_position']) def test_thisweeks_ad_position_handles_missing_category(self): self.repository['newsletter'] = self.newsletter globs = IRuleGlobs(self.newsletter.body.values()[0]) self.assertEqual('__NONE__', globs['thisweeks_ad_position']) def test_last_position_is_determined_from_newsletter_body(self): self.assertEqual(1, self.globs['last_position'])
def test_thisweeks_ad_position_handles_missing_category(self): self.repository['newsletter'] = self.newsletter globs = IRuleGlobs(self.newsletter.body.values()[0]) self.assertEqual('__NONE__', globs['thisweeks_ad_position'])
def test_thisweeks_ad_position_handles_non_news_letter_elements(self): body = self.newsletter.body body.__parent__ = None globs = IRuleGlobs(body.values()[0]) self.assertEqual('__NONE__', globs['thisweeks_ad_position'])
def test_newsletter_retrieval_handles_non_newsletter_elements(self): body = self.newsletter.body body.__parent__ = None globs = IRuleGlobs(body.values()[0]) self.assertFalse(globs.get('newsletter', False))