本文整理匯總了Python中plone.dexterity.browser.add.DefaultAddForm.add方法的典型用法代碼示例。如果您正苦於以下問題:Python DefaultAddForm.add方法的具體用法?Python DefaultAddForm.add怎麽用?Python DefaultAddForm.add使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類plone.dexterity.browser.add.DefaultAddForm
的用法示例。
在下文中一共展示了DefaultAddForm.add方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_add
# 需要導入模塊: from plone.dexterity.browser.add import DefaultAddForm [as 別名]
# 或者: from plone.dexterity.browser.add.DefaultAddForm import add [as 別名]
def test_add(self):
# Container, new object, and request
container = self.mocker.mock()
obj = self.mocker.mock()
request = TestRequest()
self.expect(container._setObject(u"newid", obj)).result(u"newid")
self.expect(container._getOb(u"newid")).result(obj)
self.expect(
container.absolute_url()
).result("http://nohost/plone/container")
obj.id = u"newid"
self.expect(obj.id).result(u"newid")
self.expect(obj.id).result(u"newid")
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(True)
self.mock_utility(
container_fti_mock,
IDexterityFTI,
name=u"containertype"
)
self.expect(container.getTypeInfo()).result(container_fti_mock)
# Name chooser
class NameChooser(object):
implements(INameChooser)
def __init__(self, context):
pass
def chooseName(self, name, object):
return u"newid"
self.mock_adapter(NameChooser, INameChooser, (Interface,))
self.replay()
form = DefaultAddForm(container, request)
form.portal_type = u"testtype"
form.add(obj)
示例2: test_add
# 需要導入模塊: from plone.dexterity.browser.add import DefaultAddForm [as 別名]
# 或者: from plone.dexterity.browser.add.DefaultAddForm import add [as 別名]
def test_add(self):
# Container, new object, and request
container = Mock()
obj = Mock()
request = TestRequest()
container._setObject = Mock(return_value=u'newid')
container._getOb = Mock(return_value=obj)
container.absolute_url = Mock(
return_value="http://nohost/plone/container")
obj.id = u"newid"
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=True)
self.mock_utility(
container_fti_mock,
IDexterityFTI,
name=u"containertype"
)
container.getTypeInfo = Mock(return_value=container_fti_mock)
# Name chooser
@implementer(INameChooser)
class NameChooser(object):
def __init__(self, context):
pass
def chooseName(self, name, object):
return u"newid"
self.mock_adapter(NameChooser, INameChooser, (Interface,))
form = DefaultAddForm(container, request)
form.portal_type = u"testtype"
form.add(obj)