def test_returns_html_and_plain_text(self): content = ExampleContentType() content.uniqueId = 'http://xml.zeit.de/foo/bar' renderer = Renderer('http://localhost:%s' % self.layer['http_port']) result = renderer(content) self.assertEqual('html', result['html']) self.assertEqual('txt', result['text'])
def test_all_volume_contents_should_change_access_value(self, mock): volume = zeit.cms.interfaces.ICMSContent( 'http://xml.zeit.de/2015/01/ausgabe') repo = self.repository['2015']['01'] content01 = ExampleContentType() content02 = ExampleContentType() content03 = ExampleContentType() repo['article01'] = content01 repo['article02'] = content02 repo['article03'] = content03 # XXX We rely quite a bit on query structure here, but cannot test it. self.elastic.search.return_value = zeit.cms.interfaces.Result([ { 'url': '/2015/01/article01' }, { 'url': '/2015/01/article02' }, { 'url': '/2015/01/article03' }, ]) cnt = volume.all_content_via_search() for c in cnt: self.assertEqual('free', c.access) volume.change_contents_access('free', 'abo') for c in cnt: self.assertEqual('abo', c.access)
def test_content_with_year_and_volume_and_product_adapts_to_IVolume(self): content = ExampleContentType() content.year = 2015 content.volume = 1 content.product = zeit.cms.content.sources.Product(u'ZEI') volume = zeit.content.volume.interfaces.IVolume(content) self.assertEqual(volume, self.repository['2015']['01']['ausgabe'])
def setUp(self): from zeit.cms.testcontenttype.testcontenttype import ExampleContentType super(IntegrationTest, self).setUp() content = ExampleContentType() content.title = 'content_title' self.repository['content'] = content self.content = self.repository['content']
def test_materialize_creates_normal_teaser_block(self): self.repository['t1'] = ExampleContentType() self.repository['t2'] = ExampleContentType() lead = self.repository['cp']['lead'] lead.count = 2 lead.automatic = True lead.automatic_type = 'query' self.elastic.search.return_value = zeit.cms.interfaces.Result([{ 'url': '/t1' }, { 'url': '/t2' }]) self.elastic.search.return_value.hits = 2 lead.values()[0].materialize() # since `AutomaticArea.values()` is cached on the transaction boundary # now, we'll only see the change with the next request/transaction... transaction.commit() result = IRenderedArea(lead).values() self.assertEqual(['teaser', 'auto-teaser'], [x.type for x in result])
def test_authorships_should_be_copied_to_freetext_on_create(self): content = ExampleContentType() content.authorships = [ content.authorships.create(self.repository['author'])] zope.event.notify(ObjectCreatedEvent(content)) self.repository['foo'] = content self.assertEqual( ('William Shakespeare',), self.repository['foo'].authors)
def test_cant_adapt_content_with_dependency_defined_to_a_non_volume(self): zecw_content = ExampleContentType() zecw_content.year = 2015 zecw_content.volume = 1 zecw_content.product = zeit.cms.content.sources.Product( u'BADDEPENDENCY') with self.assertRaises(TypeError): zeit.content.volume.interfaces.IVolume(zecw_content)
def test_content_with_year_and_volume_and_product_adapts_to_IVolume(self): content = ExampleContentType() content.year = 2015 content.volume = 1 content.product = zeit.cms.content.sources.Product(u'ZEI') volume = zeit.content.volume.interfaces.IVolume(content) self.assertEqual( volume, self.repository['2015']['01']['ausgabe'])
def test_cant_adapt_content_with_dependency_defined_to_a_non_volume( self): zecw_content = ExampleContentType() zecw_content.year = 2015 zecw_content.volume = 1 zecw_content.product = zeit.cms.content.sources.Product( u'BADDEPENDENCY') with self.assertRaises(TypeError): zeit.content.volume.interfaces.IVolume(zecw_content)
def test_looks_up_centerpage_for_depent_product_content(self): content = ExampleContentType() content.product = zeit.cms.content.sources.Product(u'ZMLB') self.repository['2015']['01']['index'] = content volume = zeit.cms.interfaces.ICMSContent( 'http://xml.zeit.de/2015/01/ausgabe') self.repository['2015']['01']['index'] = zeit.content.cp.centerpage \ .CenterPage() cp = zeit.content.cp.interfaces.ICenterPage(volume) self.assertEqual('http://xml.zeit.de/2015/01/index', cp.uniqueId)
def test_start_job_retracts_urls(self): self.repository['foo'] = ExampleContentType() self.repository['bar'] = ExampleContentType() IPublishInfo(self.repository['bar']).published = True IPublishInfo(self.repository['foo']).published = True job = zeit.cms.retractlog.retractlog.Job() job.urls = ['http://xml.zeit.de/foo', 'http://xml.zeit.de/bar'] job.start() self.assertFalse(IPublishInfo(self.repository['foo']).published) self.assertFalse(IPublishInfo(self.repository['bar']).published)
def test_contents_with_defined_dependency_adapt_to_same_volume(self): zei_content = ExampleContentType() zei_content.year = 2015 zei_content.volume = 1 zei_content.product = zeit.cms.content.sources.Product(u'ZEI') zmlb_content = ExampleContentType() zmlb_content.year = 2015 zmlb_content.volume = 1 zmlb_content.product = zeit.cms.content.sources.Product(u'ZMLB') self.assertEqual(zeit.content.volume.interfaces.IVolume(zei_content), zeit.content.volume.interfaces.IVolume(zmlb_content))
def test_content_is_marked_according_to_ressort(self): obj = ExampleContentType() obj.ressort = u'Sport' self.repository['sport'] = obj obj = self.repository['sport'] self.assertTrue( zeit.cms.section.testing.IExampleContent.providedBy(obj)) self.assertFalse( zeit.cms.section.interfaces.IZONContent.providedBy(obj))
def setUp(self): from zeit.cms.testcontenttype.testcontenttype import ExampleContentType super(CorehandlerTest, self).setUp() self.repository['parent'] = ExampleContentType() self.repository['reference'] = ExampleContentType() reference = self.repository['reference'] related = zeit.cms.related.interfaces.IRelatedContent(reference) related.related = (self.repository['parent'], ) self.repository['reference'] = reference
def test_channels_are_not_set_if_product_forbids_it(self): article = ExampleContentType() article.product = zeit.cms.content.sources.Product(u'ZEI') self.repository['testcontent'] = article with checked_out(self.repository['testcontent']) as co: co.ressort = u'Deutschland' zope.lifecycleevent.modified( co, zope.lifecycleevent.Attributes( zeit.cms.testcontenttype.interfaces.IExampleContentType, 'ressort')) self.assertEqual((), co.channels)
def test_event_dispatched_to_sublocation_should_be_ignored(self): # XXX: I'm not quite sure which use cases actually create this kind of # ObjectAddedEvent, but we've inherited this guard from zeit.solr and # they probably had a good reason. %-) content = ExampleContentType() content.uniqueId = 'xzy://bla/fasel' content_sub = ExampleContentType() content_sub.uniqueId = 'xzy://bla/fasel/sub' event = zope.lifecycleevent.ObjectAddedEvent(content) for ignored in zope.component.subscribers((content_sub, event), None): pass self.assertFalse(self.tms.index.called)
def test_content_online_product_has_no_IVolume(self): # *All* content that is added in vivi gets year and volume from # zeit.cms.settings.interfaces.IGlobalSettings, so we need to ensure # that "online content" has no IVolume, only print content. # In addition we want only handle products with a location template # configured. content = ExampleContentType() content.year = 2015 content.volume = 1 content.product = zeit.cms.content.sources.Product(u'ZEDE') with self.assertRaises(TypeError): zeit.content.volume.interfaces.IVolume(content)
def test_widget_should_render_add_view(self): from zeit.cms.testcontenttype.testcontenttype import ExampleContentType field = self.get_field() content = ExampleContentType() content.ressort = u'Politik' field = field.bind(content) widget = self.get_widget(field) widget.add_type = ( zeit.cms.testcontenttype.interfaces.IExampleContentType) self.assert_ellipsis( '...<a target="_blank"' '...href="http://127.0.0.1/repository/politik/' '...zeit.cms.testcontenttype.Add...', widget())
def test_disabling_automatic_keeps_order_of_teasers(self): from zeit.cms.testcontenttype.testcontenttype import ExampleContentType self.repository['t1'] = ExampleContentType() self.repository['t2'] = ExampleContentType() lead = self.repository['cp']['lead'] lead.count = 2 lead.automatic = True lead.create_item('teaser') lead.count = 3 order = lead.keys() lead.automatic = False self.assertEqual(order, lead.keys())
def test_ICommonMetadata_can_be_adapted_to_added_volume(self): b = self.browser self.open_add_form() b.getControl('Year').value = '2010' b.getControl(name='form.volume').value = '2' b.getControl('Add').click() content = ExampleContentType() content.year = 2010 content.volume = 2 content.product = zeit.cms.content.sources.Product(u'ZEI') self.repository['testcontent'] = content volume = zeit.content.volume.interfaces.IVolume(content) self.assertEqual( u'http://xml.zeit.de/2010/02/ausgabe', volume.uniqueId)
def test_widget_should_render_add_view(self): from zeit.cms.testcontenttype.testcontenttype import ExampleContentType choice = self.get_choice() request = zope.publisher.browser.TestRequest() content = ExampleContentType() content.ressort = u'Politik' choice = choice.bind(content) widget = zeit.cms.browser.widget.DropObjectWidget( choice, choice.source, request) widget.add_type = ( zeit.cms.testcontenttype.interfaces.IExampleContentType) self.assertEllipsis( '...<a target="_blank"' '...href="http://127.0.0.1/repository/politik/' '...zeit.cms.testcontenttype.Add...', widget())
def test_type_markers_are_more_specific_than_general_markers(self): self.repository['example']['test'] = ExampleContentType() obj = self.repository['example']['test'] provides = list(zope.interface.providedBy(obj)) self.assertLess( provides.index(zeit.cms.section.testing.IExampleTestcontent), provides.index(zeit.cms.section.testing.IExampleContent))
def test_specific_types_are_marked_with_type_specific_interface(self): self.repository['example']['test'] = ExampleContentType() obj = self.repository['example']['test'] self.assertTrue( zeit.cms.section.testing.IExampleContent.providedBy(obj)) self.assertTrue( zeit.cms.section.testing.IExampleTestcontent.providedBy(obj))
def test_get_type_of_content_object(self): folder = self.clipboard.addClip('Favoriten') self.repository['test'] = ExampleContentType() content = self.repository['test'] self.clipboard.addContent(folder, content, 'testname', insert=True) clip = list(folder.values())[0] self.assertEqual('testcontenttype', self.view.getType(clip))
def setUp(self): self.elastic = mock.Mock() self.zca.patch_utility(self.elastic, zeit.find.interfaces.ICMSSearch) super(VolumeAdminBrowserTest, self).setUp() 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 content = ExampleContentType() content.year = 2015 content.volume = 1 content.product = zeit.cms.content.sources.Product(u'ZEI') self.repository['testcontent'] = content IPublishInfo(self.repository['testcontent']).urgent = True
def test_rename_menu_item_is_not_displayed_for_folder_with_content(self): folder = self.repository['testing'] folder['foo'] = ExampleContentType() b = self.browser b.open('http://*****:*****@@rename-box')
def test_content_is_marked_on_checkout(self): # The test setup is a little convoluted, we need to put an object into # a folder /without/ it being marked, so we can check that the marking # happens during checkout. self.repository['folder'] = zeit.cms.repository.folder.Folder() self.repository['folder']['test'] = ExampleContentType() # we cannot change the DAV-Properties of an existing folder # while it's checked in -- and checking out folders is not supported, # so we *replace* the folder object... don't try this at home, folks. folder = zeit.cms.repository.folder.Folder() zope.interface.alsoProvides(folder, zeit.cms.section.testing.IExampleSection) self.repository['folder'] = folder # Clear Repository's cache, so we get the replaced folder object, # not the cached version from above. transaction.commit() obj = self.repository['folder']['test'] self.assertFalse( zeit.cms.section.testing.IExampleContent.providedBy(obj)) self.assertTrue( zeit.cms.section.interfaces.IZONContent.providedBy(obj)) with zeit.cms.checkout.helper.checked_out( self.repository['folder']['test']): pass obj = self.repository['folder']['test'] self.assertTrue( zeit.cms.section.testing.IExampleContent.providedBy(obj)) self.assertFalse( zeit.cms.section.interfaces.IZONContent.providedBy(obj))
def setUp(self): super(TestJobView, self).setUp() # Add content test_folder = zeit.cms.content.add.find_or_create_folder('test') test_folder['foo'] = ExampleContentType() test_folder['bar'] = ExampleContentType() # Create test job root = self.getRootFolder() logfolder = root['retractlog'] job = zeit.cms.retractlog.retractlog.Job() job.title = 'foo' logfolder['foo'] = job job.urls = ['http://xml.zeit.de/test/foo', 'http://xml.zeit.de/test/bar'] job.invalid = ['http://xml.zeit.de/online/2007/01/Somalia'] job.unknown = ['http://xml.zeit.de/test/baz']
def test_rename_stores_old_name_on_dav_property(self): self.repository['article'] = ExampleContentType() zope.copypastemove.interfaces.IObjectMover( self.repository['article']).moveTo(self.repository, 'changed') article = self.repository['changed'] self.assertEqual(('http://xml.zeit.de/article', ), IRenameInfo(article).previous_uniqueIds)
def create_content(self, short_text=None): content = ExampleContentType() if short_text is not None: push = zeit.push.interfaces.IPushMessages(content) push.short_text = 'mytext' self.repository['foo'] = content return self.repository['foo']
def test_opening_dialog_from_folder_view_points_to_content(self): # Regression VIV-452 from zeit.cms.testcontenttype.testcontenttype import ExampleContentType from zeit.cms.workflow.interfaces import IPublish, IPublishInfo zope.component.hooks.setSite(self.getRootFolder()) self.repository['other'] = ExampleContentType() self.prepare_content('http://xml.zeit.de/other') self.prepare_content('http://xml.zeit.de/testcontent') transaction.commit() IPublish(self.repository['other']).publish(background=False) IPublish(self.repository['testcontent']).publish(background=False) transaction.commit() self.open('/repository') s = self.selenium s.click('xpath=//*[contains(text(), "testcontent")]') s.waitForElementPresent('css=#bottomcontent a[title=Retract]') s.click('css=#bottomcontent a[title="Additional actions"]') s.click('css=#bottomcontent a[title=Retract]') s.waitForElementPresent('css=ol#worklist') s.waitForElementPresent('css=li.busy[action=start_job]') s.waitForElementNotPresent('css=li.busy[action=start_job]') s.waitForPageToLoad() self.assertFalse( IPublishInfo(self.repository['testcontent']).published) self.assertTrue(IPublishInfo(self.repository['other']).published)
def test_renameinfo_has_security_declaration(self): # Since the IObjectMover for IRepository is a trusted adapter, # we don't usually notice that we need a security declaration for # IRenameInfo. self.repository['article'] = ExampleContentType() wrapped = zope.security.proxy.ProxyFactory(self.repository['article']) self.assertEqual((), IRenameInfo(wrapped).previous_uniqueIds)
def setUp(self): super(TestReferenceSequenceWidget, self).setUp() ExampleContentType.references = \ zeit.cms.content.reference.ReferenceProperty( '.body.references.reference', 'related') self.repository['content'] = ExampleContentType() self.repository['target'] = ExampleContentType() @zope.interface.implementer(zope.schema.interfaces.ISource) class FakeSource(object): def __contains__(self, value): return True self.field = zeit.cms.content.interfaces.ReferenceField( source=FakeSource()) self.field.__name__ = 'references' self.field = self.field.bind(self.repository['content'])
def setUp(self): self.elastic = mock.Mock() zope.component.getGlobalSiteManager().registerUtility( self.elastic, zeit.find.interfaces.ICMSSearch) super(VolumeAdminBrowserTest, self).setUp() 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 content = ExampleContentType() content.year = 2015 content.volume = 1 content.product = zeit.cms.content.sources.Product(u'ZEI') self.repository['testcontent'] = content IPublishInfo(self.repository['testcontent']).urgent = True
def test_resolves_reference_from_source_config(self): self.repository['storystream'] = ExampleContentType() with checked_out(self.repository['testcontent']) as co: co.storystreams = (zeit.cms.content.sources.StorystreamSource()( None).find('test'),) self.assertEqual( self.repository['storystream'], self.repository['testcontent'].storystreams[0].references)