Ejemplo n.º 1
0
 def test_checkin_without_IRepositoryContent_adapter_should_raise(self):
     manager = ICheckoutManager(self.content)
     checked_out = manager.checkout()
     self._tear_down_adapters()
     manager = ICheckinManager(checked_out)
     self.assertTrue(manager.canCheckin)
     self.assertRaises(LookupError, manager.checkin)
Ejemplo n.º 2
0
    def setUp(self):
        super(ValidateCheckinTest, self).setUp()
        zope.component.getSiteManager().registerHandler(
            self.provoke_veto, (IValidateCheckinEvent, ))

        self.workingcopy = zeit.cms.workingcopy.interfaces.IWorkingcopy(
            self.principal)

        manager = ICheckoutManager(self.repository['testcontent'])
        self.checked_out = manager.checkout()
Ejemplo n.º 3
0
    def test_validation_errors_should_veto_checkin(self):
        from zeit.cms.checkout.interfaces import ICheckinManager
        from zeit.cms.checkout.interfaces import ICheckoutManager
        import zeit.content.article.article

        self.repository['article'] = zeit.content.article.article.Article()

        manager = ICheckoutManager(self.repository['article'])
        co = manager.checkout()
        manager = ICheckinManager(co)
        self.assertFalse(manager.canCheckin)
        errors = dict(manager.last_validation_error)
        self.assertIsInstance(
            errors['title'], zope.schema.ValidationError)
    def test_updater_suppress_errors(self):
        content = ICheckoutManager(self.repository['testcontent']).checkout()
        content.authorships = (content.authorships.create(self.shakespeare),)

        # This error condition cannot be synthesized easily (would need to make
        # an Author lose its metadata so it's treated as
        # PersistentUnknownResource).

        with mock.patch('zeit.content.author.author.Author.display_name',
                        gocept.testing.mock.Property()) as display_name:
            display_name.side_effect = AttributeError()
            with self.assertNothingRaised():
                updater = zeit.cms.content.interfaces.IXMLReferenceUpdater(
                    content)
                updater.update(content.xml, suppress_errors=True)
Ejemplo n.º 5
0
    def test_security_proxied_fields_should_be_validated_correctly(self):
        from zeit.cms.checkout.interfaces import ICheckinManager
        from zeit.cms.checkout.interfaces import ICheckoutManager
        import zeit.content.article.article

        self.repository['article'] = zeit.content.article.article.Article()

        manager = ICheckoutManager(self.repository['article'])
        co = manager.checkout()
        co = zope.security.proxy.ProxyFactory(co)
        manager = ICheckinManager(co)
        self.assertFalse(manager.canCheckin)
        errors = dict(manager.last_validation_error)
        # the default for keywords is an empty tuple
        self.assertNotIn('keywords', errors)
Ejemplo n.º 6
0
    def test_updater_suppress_errors(self):
        content = ICheckoutManager(self.repository['testcontent']).checkout()
        content.authorships = (content.authorships.create(self.shakespeare), )

        # This error condition cannot be synthesized easily (would need to make
        # an Author lose its metadata so it's treated as
        # PersistentUnknownResource).

        with mock.patch('zeit.content.author.author.Author.display_name',
                        gocept.testing.mock.Property()) as display_name:
            display_name.side_effect = AttributeError()
            with self.assertNothingRaised():
                updater = zeit.cms.content.interfaces.IXMLReferenceUpdater(
                    content)
                updater.update(content.xml, suppress_errors=True)
Ejemplo n.º 7
0
 def test_checked_out_by_somebody_else_steals_lock_first(self):
     zope.security.management.endInteraction()
     zeit.cms.testing.create_interaction('other')
     ICheckoutManager(self.repository['foo']).checkout()
     zope.security.management.endInteraction()
     zeit.cms.testing.create_interaction('zope.user')
     self.publisher.send('mytext', 'http://zeit.de/foo')
Ejemplo n.º 8
0
 def test_article_checked_out_already_does_not_update_xml(self):
     ICheckoutManager(self.repository['foo']).checkout()
     self.publish(self.repository['cp'])
     leadtime = zeit.content.cp.interfaces.ILeadTime(self.repository['foo'])
     self.assertNotEqual(None, leadtime.start)
     self.assertNotIn(
         'leadtime_start',
         zeit.cms.testing.xmltotext(self.repository['foo'].xml))
Ejemplo n.º 9
0
    def test_removes_excessive_ghosts_before_creating_ghosts(self):
        wc = zeit.cms.checkout.interfaces.IWorkingcopy(None)
        for i in range(zeit.ghost.ghost.TARGET_WORKINGCOPY_SIZE):
            name = 'test-%s' % i
            self.repository[name] = ExampleContentType()
            ICheckoutManager(self.repository[name]).checkout()

        zeit.ghost.ghost.create_ghost(self.repository['testcontent'])
        self.assertEqual(zeit.ghost.ghost.TARGET_WORKINGCOPY_SIZE + 1, len(wc))
Ejemplo n.º 10
0
 def test_article_checked_out_by_somebody_else_steals_lock_first(self):
     zope.security.management.endInteraction()
     zeit.cms.testing.create_interaction('other')
     ICheckoutManager(self.repository['foo']).checkout()
     zope.security.management.endInteraction()
     zeit.cms.testing.create_interaction('zope.user')
     self.publish(self.repository['cp'])
     self.assertEllipsis(
         '...<attribute...name="leadtime_start">...',
         zeit.cms.testing.xmltotext(self.repository['foo'].xml))
Ejemplo n.º 11
0
    def test_event_is_not_sent_for_temporary_workingcopy(self):
        # thus, no validation is performed during publishing, for example
        # XXX this needs to be conceptualized more clearly, see #12701

        # undo setUp, since it doesn't apply for this test
        manager = ICheckinManager(self.checked_out)
        manager.delete()

        manager = ICheckoutManager(self.repository['testcontent'])
        checked_out = manager.checkout(temporary=True)
        manager = ICheckinManager(checked_out)
        self.assertTrue(manager.canCheckin)
Ejemplo n.º 12
0
 def test_checkin_does_not_unlock_while_publishing(self):
     manager = ICheckoutManager(self.repository['testcontent'])
     checked_out = manager.checkout()
     manager = ICheckinManager(checked_out)
     manager.checkin(publishing=True)
     lockable = zope.app.locking.interfaces.ILockable(
         self.repository['testcontent'])
     self.assertTrue(lockable.locked())
    def test_updater_suppress_errors(self):
        image = ICMSContent('http://xml.zeit.de/2006/DSC00109_2.JPG')
        content = ICheckoutManager(self.repository['testcontent']).checkout()
        zeit.content.image.interfaces.IImages(content).image = image

        # This error condition cannot be synthesized easily (would need to make
        # an ImageGroup lose its metadata so it's treated as a Folder), and
        # even mocking it is rather complicated, sigh.
        def mock_query(*args, **kw):
            if kw.get('name') == 'image':
                return None
            return queryAdapter(*args, **kw)

        queryAdapter = zope.component.queryAdapter

        with mock.patch('zope.component.queryAdapter', mock_query):
            with self.assertNothingRaised():
                updater = zeit.cms.content.interfaces.IXMLReferenceUpdater(
                    content)
                updater.update(content.xml, suppress_errors=True)
Ejemplo n.º 14
0
 def test_delete_issues_events_and_deletes_context(self):
     manager = ICheckoutManager(self.content)
     checked_out = manager.checkout()
     parent = checked_out.__parent__
     name = checked_out.__name__
     manager = ICheckinManager(checked_out)
     with mock.patch('zope.event.notify', mock.Mock()) as notify:
         manager.delete()
         self.assertNotIn(name, parent.keys())
         self.assertEqual(2, len(notify.call_args_list))
         before, after = notify.call_args_list
         self.assertTrue(
             zeit.cms.checkout.interfaces.IBeforeDeleteEvent.providedBy(
                 before[0][0]))
         self.assertTrue(
             zeit.cms.checkout.interfaces.IAfterDeleteEvent.providedBy(
                 after[0][0]))
Ejemplo n.º 15
0
 def test_checkout_needs_adapter_to_ILocalContent(self):
     manager = ICheckoutManager(self.content)
     checked_out = manager.checkout()
     self.assertTrue(checked_out.are_you_local)
Ejemplo n.º 16
0
 def test_checked_out_already_deletes_from_workingcopy_first(self):
     ICheckoutManager(self.repository['foo']).checkout()
     self.publisher.send('mytext', 'http://zeit.de/foo')
Ejemplo n.º 17
0
 def test_checkout_without_ILocalContent_adapter_should_raise(self):
     self._tear_down_adapters()
     manager = ICheckoutManager(self.content)
     self.assertFalse(manager.canCheckout)
     self.assertRaises(CheckinCheckoutError, manager.checkout)
Ejemplo n.º 18
0
 def test_checkin_needs_adapter_to_IRepositoryContent(self):
     manager = ICheckoutManager(self.content)
     checked_out = manager.checkout()
     manager = ICheckinManager(checked_out)
     checked_in = manager.checkin()
     self.assertFalse(checked_in.are_you_local)