本文整理匯總了Python中plone.dexterity.browser.add.DefaultAddForm類的典型用法代碼示例。如果您正苦於以下問題:Python DefaultAddForm類的具體用法?Python DefaultAddForm怎麽用?Python DefaultAddForm使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了DefaultAddForm類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_update_checks_allowed_types
def test_update_checks_allowed_types(self):
# Context and request
context_mock = self.create_dummy(
portal_type=u'testtype',
allowedContentTypes=lambda: [])
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))
# Form
self.mocker.replay()
view = DefaultAddForm(context_mock, request_mock)
view.portal_type = fti_mock.getId()
self.assertRaises(ValueError, view.update)
示例2: test_fires_add_begun_event
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()
示例3: test_fires_add_begun_event
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]))
示例4: test_label
def test_label(self):
# Add view should take its label from the FTI title
# Context and request
context_mock = Mock()
request_mock = TestRequest()
request_mock.form['disable_border'] = True
# FTI
fti_mock = DexterityFTI(u"testtype")
fti_mock.Title = Mock(return_value=u'Test title')
self.mock_utility(fti_mock, IDexterityFTI, name=u"testtype")
# Form
addform = DefaultAddForm(context_mock, request_mock)
addform.portal_type = u"testtype"
label = addform.label
self.assertEqual(u"Add ${name}", six.text_type(label))
self.assertEqual(u"Test title", label.mapping['name'])
示例5: test_update_ignores_type_check_if_security_check_deferred
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")
示例6: test_fires_add_cancelled_event
def test_fires_add_cancelled_event(self):
# Context and request
context_mock = self.create_dummy(portal_type=u'testtype')
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 = DefaultAddForm(context_mock, request_mock)
view.handleCancel(view, {})
self.assertTrue(notify_mock.called)
self.assertTrue(
IAddCancelledEvent.providedBy(notify_mock.call_args[0][0]))
示例7: test_add_raises_value_error_if_type_not_addable
def test_add_raises_value_error_if_type_not_addable(self):
# Container, new object, and request
container = Mock()
obj = Mock()
request = TestRequest()
obj.portal_type = 'testtype'
# New object's FTI
fti_mock = DexterityFTI(u"testtype")
fti_mock.isConstructionAllowed = Mock(return_value=True)
self.mock_utility(fti_mock, IDexterityFTI, name=u"testtype")
# Container FTI
container_fti_mock = DexterityFTI(u"containertype")
container_fti_mock.allowType = Mock(return_value=False)
self.mock_utility(
container_fti_mock,
IDexterityFTI,
name=u"containertype"
)
container.getTypeInfo = Mock(return_value=container_fti_mock)
form = DefaultAddForm(container, request)
form.portal_type = u"testtype"
self.assertRaises(ValueError, form.add, obj)
示例8: test_form_create
def test_form_create(self):
# Context and request
context = Container(u"container")
request = TestRequest()
# FTI - returns dummy factory name
fti_mock = self.mocker.proxy(DexterityFTI(u"testtype"))
self.expect(fti_mock.factory).result(u"testfactory")
self.mock_utility(fti_mock, IDexterityFTI, name=u"testtype")
# The form we're testing
form = DefaultAddForm(context, request)
form.portal_type = u"testtype"
# createObject and applyChanges
obj_dummy = Item(id="dummy")
data_dummy = {u"foo": u"bar"}
createObject_mock = self.mocker.replace('zope.component.createObject')
self.expect(createObject_mock(u"testfactory")).result(obj_dummy)
applyChanges_mock = self.mocker.replace('z3c.form.form.applyChanges')
self.expect(applyChanges_mock(form, obj_dummy, data_dummy))
self.replay()
self.assertEquals(obj_dummy, form.create(data_dummy))
self.assertEquals("testtype", obj_dummy.portal_type)
示例9: test_form_create
def test_form_create(self):
# Context and request
context = Container(u"container")
request = TestRequest()
# FTI - returns dummy factory name
fti_mock = DexterityFTI(u"testtype")
fti_mock.factory = u'testfactory'
self.mock_utility(fti_mock, IDexterityFTI, name=u"testtype")
# The form we're testing
form = DefaultAddForm(context, request)
form.portal_type = u"testtype"
class ISchema(Interface):
foo = schema.TextLine()
form.fields = Fields(ISchema)
# createObject and applyChanges
obj_dummy = Item(id="dummy")
alsoProvides(obj_dummy, ISchema)
data_dummy = {u"foo": u"bar"}
from zope.component import createObject
self.patch_global(createObject, return_value=obj_dummy)
provideAdapter(AttributeField)
self.assertEqual(obj_dummy, form.create(data_dummy))
self.assertEqual("testtype", obj_dummy.portal_type)
示例10: test_update_checks_allowed_types
def test_update_checks_allowed_types(self):
# Context and request
context_mock = self.create_dummy(
portal_type=u'testtype',
allowedContentTypes=lambda: [])
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))
# Form
view = DefaultAddForm(context_mock, request_mock)
view.portal_type = fti_mock.getId()
self.assertRaises(ValueError, view.update)
示例11: test_fires_add_cancelled_event
def test_fires_add_cancelled_event(self):
# Context and request
context_mock = self.create_dummy(portal_type=u'testtype')
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: IAddCancelledEvent.providedBy(x)
)))
# Form
self.replay()
view = DefaultAddForm(context_mock, request_mock)
view.handleCancel(view, {})
示例12: test_schema_lookup
def test_schema_lookup(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.expect(fti_mock.behaviors).result((IBehaviorOne.__identifier__,
IBehaviorTwo.__identifier__,
IBehaviorThree.__identifier__))
self.mock_utility(fti_mock, IDexterityFTI, name=u"testtype")
self.expect(fti_mock.behaviors).result([])
# Form
self.replay()
view = DefaultAddForm(context_mock, request_mock)
view.portal_type = u"testtype"
self.assertEquals(ISchema, view.schema)
self.assertEquals([IBehaviorOne, IBehaviorTwo], list(view.additionalSchemata,))
# When we register our own IBehaviorAssignable we can
# influence what goes into the additionalSchemata:
provideAdapter(NoBehaviorAssignable)
self.assertEquals([], list(view.additionalSchemata,))
示例13: test_label
def test_label(self):
# Add view should take its label from the FTI title
# Context and request
context_mock = self.mocker.mock()
request_mock = self.mocker.proxy(TestRequest())
request_mock['disable_border'] = True
# FTI
fti_mock = self.mocker.proxy(DexterityFTI(u"testtype"))
self.expect(fti_mock.Title()).result(u"Test title")
self.mock_utility(fti_mock, IDexterityFTI, name=u"testtype")
# Form
self.replay()
addform = DefaultAddForm(context_mock, request_mock)
addform.portal_type = u"testtype"
label = addform.label
self.assertEquals(u"Add ${name}", unicode(label))
self.assertEquals(u"Test title", label.mapping['name'])
示例14: test_add_raises_value_error_if_type_not_addable
def test_add_raises_value_error_if_type_not_addable(self):
# Container, new object, and request
container = self.mocker.mock()
obj = self.mocker.mock()
request = TestRequest()
self.expect(obj.portal_type).result("testtype").count(0,None)
# New object's FTI
fti_mock = self.mocker.proxy(DexterityFTI(u"testtype"))
self.expect(fti_mock.isConstructionAllowed(container)).result(True)
self.mock_utility(fti_mock, IDexterityFTI, name=u"testtype")
# Container FTI
container_fti_mock = self.mocker.proxy(DexterityFTI(u"containertype"))
self.expect(container_fti_mock.allowType(u"testtype")).result(False)
self.mock_utility(container_fti_mock, IDexterityFTI, name=u"containertype")
self.expect(container.getTypeInfo()).result(container_fti_mock)
self.replay()
form = DefaultAddForm(container, request)
form.portal_type = u"testtype"
self.assertRaises(ValueError, form.add, obj)
示例15: test_vocabulary_field_allowed_from_add_form
def test_vocabulary_field_allowed_from_add_form(self):
add_form = DefaultAddForm(self.portal, self.request)
add_form.portal_type = 'dx_mock'
view = VocabularyView(add_form, self.request)
self.request.form.update({
'name': 'plone.app.vocabularies.PortalTypes',
'field': 'allowed_field',
})
data = json.loads(view())
self.assertEquals(len(data['results']),
len(self.portal.portal_types.objectIds()))