def test_fires_add_begun_event(self): # Context and request context_mock = self.create_dummy( portal_type=u'testtype', allowedContentTypes=lambda: [self.create_dummy(getId=lambda: 'testtype')]) request_mock = TestRequest() # FTI fti_mock = DexterityFTI(u"testtype") fti_mock.lookupSchema = Mock(return_value=ISchema) self.mock_utility(fti_mock, IDexterityFTI, name=u"testtype") self.mock_adapter( FieldWidgets, IWidgets, (Interface, Interface, Interface) ) self.mock_adapter(Actions, IActions, (Interface, Interface, Interface)) # mock notify from zope.event import notify notify_mock = self.patch_global(notify) # Form view = DefaultAddForm(context_mock, request_mock) view.portal_type = fti_mock.getId() view.update() self.assertTrue(notify_mock.called) self.assertTrue(IAddBegunEvent.providedBy(notify_mock.call_args[0][0]))
def test_update_ignores_type_check_if_security_check_deferred(self): # Context and request context_mock = self.create_dummy( portal_type=u'testtype', allowedContentTypes=lambda: []) request_mock = TestRequest() alsoProvides(request_mock, IDeferSecurityCheck) # FTI fti_mock = DexterityFTI(u"testtype") fti_mock.lookupSchema = Mock(return_value=ISchema) self.mock_utility(fti_mock, IDexterityFTI, name=u"testtype") self.mock_adapter( FieldWidgets, IWidgets, (Interface, Interface, Interface) ) self.mock_adapter(Actions, IActions, (Interface, Interface, Interface)) # Form view = DefaultAddForm(context_mock, request_mock) view.portal_type = fti_mock.getId() try: view.update() except ValueError: self.fail("Update raised Unauthorized with security checks " "deferred")
def test_fires_add_begun_event(self): # Context and request context_mock = self.create_dummy(portal_type=u'testtype') request_mock = TestRequest() # FTI fti_mock = self.mocker.proxy(DexterityFTI(u"testtype")) self.expect(fti_mock.lookupSchema()).result(ISchema) self.mocker.count(0, 100) self.mock_utility(fti_mock, IDexterityFTI, name=u"testtype") self.mock_adapter(FieldWidgets, IWidgets, (Interface, Interface, Interface)) self.mock_adapter(Actions, IActions, (Interface, Interface, Interface)) # mock notify notify_mock = self.mocker.replace('zope.event.notify') self.expect(notify_mock(mocker.MATCH( lambda x: IAddBegunEvent.providedBy(x) ))) # Form self.replay() view = DefaultAddForm(context_mock, request_mock) view.portal_type = fti_mock.getId() view.update()
def test_fires_add_begun_event(self): # Context and request context_mock = self.create_dummy(portal_type=u'testtype') request_mock = TestRequest() # FTI fti_mock = self.mocker.proxy(DexterityFTI(u"testtype")) self.expect(fti_mock.lookupSchema()).result(ISchema) self.mocker.count(0, 100) self.mock_utility(fti_mock, IDexterityFTI, name=u"testtype") self.mock_adapter(FieldWidgets, IWidgets, (Interface, Interface, Interface)) self.mock_adapter(Actions, IActions, (Interface, Interface, Interface)) # mock notify notify_mock = self.mocker.replace('zope.event.notify') self.expect( notify_mock(mocker.MATCH(lambda x: IAddBegunEvent.providedBy(x)))) # Form self.replay() view = DefaultAddForm(context_mock, request_mock) view.portal_type = fti_mock.getId() view.update()
def test_update_ignores_type_check_if_security_check_deferred(self): # Context and request context_mock = self.create_dummy(portal_type=u'testtype', allowedContentTypes=lambda: []) request_mock = TestRequest() alsoProvides(request_mock, IDeferSecurityCheck) # FTI fti_mock = DexterityFTI(u"testtype") fti_mock.lookupSchema = Mock(return_value=ISchema) self.mock_utility(fti_mock, IDexterityFTI, name=u"testtype") self.mock_adapter(FieldWidgets, IWidgets, (Interface, Interface, Interface)) self.mock_adapter(Actions, IActions, (Interface, Interface, Interface)) # Form view = DefaultAddForm(context_mock, request_mock) view.portal_type = fti_mock.getId() try: view.update() except ValueError: self.fail("Update raised Unauthorized with security checks " "deferred")
def test_fires_add_begun_event(self): # Context and request context_mock = self.create_dummy( portal_type=u'testtype', allowedContentTypes=lambda: [self.create_dummy(getId=lambda: 'testtype')]) request_mock = TestRequest() # FTI fti_mock = DexterityFTI(u"testtype") fti_mock.lookupSchema = Mock(return_value=ISchema) self.mock_utility(fti_mock, IDexterityFTI, name=u"testtype") self.mock_adapter(FieldWidgets, IWidgets, (Interface, Interface, Interface)) self.mock_adapter(Actions, IActions, (Interface, Interface, Interface)) # mock notify from zope.event import notify notify_mock = self.patch_global(notify) # Form view = DefaultAddForm(context_mock, request_mock) view.portal_type = fti_mock.getId() view.update() self.assertTrue(notify_mock.called) self.assertTrue(IAddBegunEvent.providedBy(notify_mock.call_args[0][0]))
def update(self): DefaultAddForm.update(self)