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.assertEquals(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_is_area_in_teasermosaic_should_apply_to_teaserbar(self): bar = self.cp['teaser-mosaic'].create_item('area') r = Rule(""" applicable(is_area and region == 'teaser-mosaic' and position) error_if(True, u'Area in teasermosaic.') """) s = r.apply(bar, IRuleGlobs(bar)) self.assertEquals(zeit.edit.rule.ERROR, s.status)
def test_area_is_not_a_region(self): area = self.cp['teaser-mosaic'].create_item('area') r = Rule(""" applicable(is_region) error_if(True) """) s = r.apply(area, IRuleGlobs(area)) self.assertNotEquals(zeit.edit.rule.ERROR, s.status)
def test_article_glob_should_apply_to_block(self): block = self.get_factory(self.get_article(), 'p')() r = Rule(""" applicable(article) error_if(True, u'foo') """) s = r.apply(block, zeit.edit.interfaces.IRuleGlobs(block)) self.assertEqual(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 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_teaserbar_is_no_block(self): bar = self.cp['teaser-mosaic'].create_item('area') r = Rule(""" applicable(is_block and region == 'teaser-mosaic') error_if(True) """) s = r.apply(bar, IRuleGlobs(bar)) self.assertNotEquals(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.assertNotEquals(zeit.edit.rule.ERROR, s.status)
def test_is_block_in_teasermosaic_should_apply_to_block(self): bar = self.cp['teaser-mosaic'].create_item('area') teaser = bar.create_item('teaser') r = Rule(""" applicable(is_block and region == 'teaser-mosaic') error_if(True, u'Block in teasermosaic.') """) s = r.apply(teaser, IRuleGlobs(teaser)) self.assertEquals(zeit.edit.rule.ERROR, s.status)
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_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_cp_type_glob(self): r = Rule(""" applicable(cp_type == 'homepage') error_if(True) """) s = r.apply(self.teaser, IRuleGlobs(self.teaser)) self.assertNotEquals(zeit.edit.rule.ERROR, s.status) self.cp.type = u'homepage' s = r.apply(self.teaser, IRuleGlobs(self.teaser)) self.assertEquals(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_content_glob(self): r = Rule(""" applicable(is_block and content) error_if(True) """) s = r.apply(self.teaser, IRuleGlobs(self.teaser)) self.assertNotEquals(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.assertEquals(zeit.edit.rule.ERROR, s.status)
def test_IReference_content_returns_referenced_object(self): self.repository['info'] = zeit.content.infobox.infobox.Infobox() block = self.get_factory(self.get_article(), 'infobox')() block.references = self.repository['info'] block = zope.security.proxy.ProxyFactory(block) r = Rule(""" from zeit.content.infobox.interfaces import IInfobox applicable(True) error_if(IInfobox.providedBy(content[0]), u'foo') """) s = r.apply(block, zeit.edit.interfaces.IRuleGlobs(block)) self.assertEqual(zeit.edit.rule.ERROR, s.status)
def test_IImage_content_returns_referenced_object(self): block = self.get_factory(self.get_article(), 'image')() image = 'http://xml.zeit.de/2006/DSC00109_2.JPG' block.references = block.references.create( zeit.cms.interfaces.ICMSContent(image)) r = Rule(""" from zeit.content.image.interfaces import IImage applicable(True) error_if(IImage.providedBy(content[0]), u'foo') """) s = r.apply(block, zeit.edit.interfaces.IRuleGlobs(block)) 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(self.group, IRuleGlobs(self.group)) # error since scale is missing self.assertEquals(zeit.edit.rule.ERROR, s.status) self.repository["group"]["group-120x120.jpg"] = create_local_image("new-hampshire-artikel.jpg") s = r.apply(self.group, IRuleGlobs(self.group)) # added scale, no error anymore self.assertNotEquals(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_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_IVolume_content_returns_referenced_object(self): from zeit.content.volume.volume import Volume volume = Volume() volume.year = 2015 volume.volume = 1 volume.product = zeit.cms.content.sources.Product(u'ZEI') zeit.cms.content.add.find_or_create_folder('2015', '01') self.repository['2015']['01']['ausgabe'] = volume block = self.get_factory(self.get_article(), 'volume')() block.references = block.references.create(volume) r = Rule(""" from zeit.content.volume.interfaces import IVolume applicable(True) error_if(IVolume.providedBy(content[0]), u'bar') """) s = r.apply(block, zeit.edit.interfaces.IRuleGlobs(block)) self.assertEqual(zeit.edit.rule.ERROR, s.status)
def apply_rule(self, rule): from zeit.edit.rule import Rule r = Rule(rule) return r.apply(mock.Mock, {})