Esempio n. 1
0
    def test_fires_edit_finished_event(self):

        # Context and request
        context_mock = self.create_dummy(portal_type=u'testtype', title=u'foo')
        context_mock.absolute_url = \
            lambda *a, **kw: 'http://127.0.0.1/plone/item'
        request_mock = TestRequest()

        # mock status message
        @implementer(IStatusMessage)
        class StatusMessage(object):

            def __init__(self, request):
                pass

            def addStatusMessage(self, msg, type=''):
                pass
        self.mock_adapter(StatusMessage, IStatusMessage, (Interface,))

        # mock notify
        from zope.event import notify
        notify_mock = self.patch_global(notify)

        # Form
        view = DefaultEditForm(context_mock, request_mock)
        view.widgets = Mock()
        view.widgets.extract = Mock(return_value=({'title': u'foo'}, []))
        view.applyChanges = Mock()
        view.handleApply(view, {})

        self.assertTrue(notify_mock.called)
        self.assertTrue(
            IEditFinishedEvent.providedBy(notify_mock.call_args[0][0]))
Esempio n. 2
0
    def test_fires_edit_finished_event(self):

        # Context and request

        context_mock = self.create_dummy(portal_type=u'testtype', title=u'foo')
        context_mock.absolute_url = lambda *a, **kw: 'http://127.0.0.1/plone/item'
        request_mock = TestRequest()

        # mock status message
        class StatusMessage(object):
            implements(IStatusMessage)
            def __init__(self, request):
                pass
            def addStatusMessage(self, msg, type=''):
                pass
        self.mock_adapter(StatusMessage, IStatusMessage, (Interface,))

        # mock notify
        notify_mock = self.mocker.replace('zope.event.notify')
        self.expect(notify_mock(mocker.MATCH(
                    lambda x: IEditFinishedEvent.providedBy(x)
                    )))

        # Form
        view = DefaultEditForm(context_mock, request_mock)
        view.widgets = self.create_dummy()
        view.widgets.extract = lambda *a, **kw: ({'title': u'foo'}, [])
        self.replay()

        view.handleApply(view, {})
Esempio n. 3
0
    def test_fires_edit_finished_event(self):

        # Context and request
        context_mock = self.create_dummy(portal_type=u'testtype', title=u'foo')
        context_mock.absolute_url = \
            lambda *a, **kw: 'http://127.0.0.1/plone/item'
        request_mock = TestRequest()

        # mock status message
        @implementer(IStatusMessage)
        class StatusMessage(object):
            def __init__(self, request):
                pass

            def addStatusMessage(self, msg, type=''):
                pass

        self.mock_adapter(StatusMessage, IStatusMessage, (Interface, ))

        # mock notify
        from zope.event import notify
        notify_mock = self.patch_global(notify)

        # Form
        view = DefaultEditForm(context_mock, request_mock)
        view.widgets = Mock()
        view.widgets.extract = Mock(return_value=({'title': u'foo'}, []))
        view.applyChanges = Mock()
        view.handleApply(view, {})

        self.assertTrue(notify_mock.called)
        self.assertTrue(
            IEditFinishedEvent.providedBy(notify_mock.call_args[0][0]))
Esempio n. 4
0
    def test_fires_edit_finished_event(self):

        # Context and request

        context_mock = self.create_dummy(portal_type=u'testtype', title=u'foo')
        context_mock.absolute_url = \
            lambda *a, **kw: 'http://127.0.0.1/plone/item'
        request_mock = TestRequest()

        # mock status message
        class StatusMessage(object):
            implements(IStatusMessage)

            def __init__(self, request):
                pass

            def addStatusMessage(self, msg, type=''):
                pass

        self.mock_adapter(StatusMessage, IStatusMessage, (Interface, ))

        # mock notify
        notify_mock = self.mocker.replace('zope.event.notify')
        self.expect(
            notify_mock(
                mocker.MATCH(lambda x: IEditFinishedEvent.providedBy(x))))

        # Form
        view = DefaultEditForm(context_mock, request_mock)
        view.widgets = self.create_dummy()
        view.widgets.extract = lambda *a, **kw: ({'title': u'foo'}, [])
        self.replay()

        view.handleApply(view, {})
    def __call__(self, content, event):
        """Called by the event system."""
        if IDexterityTranslatable.providedBy(content):
            self.canonical = ITranslationManager(content).query_canonical()

            if IEditFinishedEvent.providedBy(event):
                self.handle_modified(content)