當前位置: 首頁>>代碼示例>>Python>>正文


Python DefaultAddForm.portal_type方法代碼示例

本文整理匯總了Python中plone.dexterity.browser.add.DefaultAddForm.portal_type方法的典型用法代碼示例。如果您正苦於以下問題:Python DefaultAddForm.portal_type方法的具體用法?Python DefaultAddForm.portal_type怎麽用?Python DefaultAddForm.portal_type使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在plone.dexterity.browser.add.DefaultAddForm的用法示例。


在下文中一共展示了DefaultAddForm.portal_type方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_form_create

# 需要導入模塊: from plone.dexterity.browser.add import DefaultAddForm [as 別名]
# 或者: from plone.dexterity.browser.add.DefaultAddForm import portal_type [as 別名]
    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)
開發者ID:plone,項目名稱:plone.dexterity,代碼行數:35,代碼來源:test_views.py

示例2: test_update_checks_allowed_types

# 需要導入模塊: from plone.dexterity.browser.add import DefaultAddForm [as 別名]
# 或者: from plone.dexterity.browser.add.DefaultAddForm import portal_type [as 別名]
    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)
開發者ID:plone,項目名稱:plone.dexterity,代碼行數:27,代碼來源:test_views.py

示例3: test_update_ignores_type_check_if_security_check_deferred

# 需要導入模塊: from plone.dexterity.browser.add import DefaultAddForm [as 別名]
# 或者: from plone.dexterity.browser.add.DefaultAddForm import portal_type [as 別名]
    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")
開發者ID:plone,項目名稱:plone.dexterity,代碼行數:32,代碼來源:test_views.py

示例4: test_add_raises_value_error_if_type_not_addable

# 需要導入模塊: from plone.dexterity.browser.add import DefaultAddForm [as 別名]
# 或者: from plone.dexterity.browser.add.DefaultAddForm import portal_type [as 別名]
    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)
開發者ID:plone,項目名稱:plone.dexterity,代碼行數:30,代碼來源:test_views.py

示例5: test_fires_add_begun_event

# 需要導入模塊: from plone.dexterity.browser.add import DefaultAddForm [as 別名]
# 或者: from plone.dexterity.browser.add.DefaultAddForm import portal_type [as 別名]
    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]))
開發者ID:plone,項目名稱:plone.dexterity,代碼行數:34,代碼來源:test_views.py

示例6: test_label

# 需要導入模塊: from plone.dexterity.browser.add import DefaultAddForm [as 別名]
# 或者: from plone.dexterity.browser.add.DefaultAddForm import portal_type [as 別名]
    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'])
開發者ID:plone,項目名稱:plone.dexterity,代碼行數:27,代碼來源:test_views.py

示例7: test_update_checks_allowed_types

# 需要導入模塊: from plone.dexterity.browser.add import DefaultAddForm [as 別名]
# 或者: from plone.dexterity.browser.add.DefaultAddForm import portal_type [as 別名]
    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)
開發者ID:adam139,項目名稱:plone.dexterity,代碼行數:32,代碼來源:test_views.py

示例8: test_fires_add_begun_event

# 需要導入模塊: from plone.dexterity.browser.add import DefaultAddForm [as 別名]
# 或者: from plone.dexterity.browser.add.DefaultAddForm import portal_type [as 別名]
    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()
開發者ID:chaoflow,項目名稱:plone.dexterity,代碼行數:33,代碼來源:test_views.py

示例9: test_form_create

# 需要導入模塊: from plone.dexterity.browser.add import DefaultAddForm [as 別名]
# 或者: from plone.dexterity.browser.add.DefaultAddForm import portal_type [as 別名]
 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)
開發者ID:chaoflow,項目名稱:plone.dexterity,代碼行數:33,代碼來源:test_views.py

示例10: test_schema_lookup

# 需要導入模塊: from plone.dexterity.browser.add import DefaultAddForm [as 別名]
# 或者: from plone.dexterity.browser.add.DefaultAddForm import portal_type [as 別名]
    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,))
開發者ID:chaoflow,項目名稱:plone.dexterity,代碼行數:33,代碼來源:test_views.py

示例11: test_label

# 需要導入模塊: from plone.dexterity.browser.add import DefaultAddForm [as 別名]
# 或者: from plone.dexterity.browser.add.DefaultAddForm import portal_type [as 別名]
 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'])
開發者ID:chaoflow,項目名稱:plone.dexterity,代碼行數:29,代碼來源:test_views.py

示例12: test_add_raises_value_error_if_type_not_addable

# 需要導入模塊: from plone.dexterity.browser.add import DefaultAddForm [as 別名]
# 或者: from plone.dexterity.browser.add.DefaultAddForm import portal_type [as 別名]
    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)
開發者ID:chaoflow,項目名稱:plone.dexterity,代碼行數:28,代碼來源:test_views.py

示例13: test_vocabulary_field_allowed_from_add_form

# 需要導入模塊: from plone.dexterity.browser.add import DefaultAddForm [as 別名]
# 或者: from plone.dexterity.browser.add.DefaultAddForm import portal_type [as 別名]
 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()))
開發者ID:mingtak,項目名稱:plone.app.dexterity_for_tpa,代碼行數:13,代碼來源:test_permissions.py

示例14: test_add

# 需要導入模塊: from plone.dexterity.browser.add import DefaultAddForm [as 別名]
# 或者: from plone.dexterity.browser.add.DefaultAddForm import portal_type [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)
開發者ID:CGTIC,項目名稱:Plone_SP,代碼行數:54,代碼來源:test_views.py

示例15: test_add

# 需要導入模塊: from plone.dexterity.browser.add import DefaultAddForm [as 別名]
# 或者: from plone.dexterity.browser.add.DefaultAddForm import portal_type [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)
開發者ID:plone,項目名稱:plone.dexterity,代碼行數:48,代碼來源:test_views.py


注:本文中的plone.dexterity.browser.add.DefaultAddForm.portal_type方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。