如何在plone.app.testing中添加Members文件夹?

前端之家收集整理的这篇文章主要介绍了如何在plone.app.testing中添加Members文件夹?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

如何在plone.app.testing中为我的功能测试添加Members文件夹,以便在真实站点中找到它?

在我正在测试的产品安装步骤中设置了成员区域创建标志.

membership.memberareaCreationFlag = 1 

我需要让这个测试工作:

class TestMemberFolder(unittest.TestCase):          
    layer = MY_FUNCTIONAL_TESTING         

    def setUp(self):                                
        portal = self.portal = self.layer['portal'] 

    def test_members_folder(self):

        membership = getToolByName(self.portal,'portal_membership')  
        membership.addMember("basicuser","secret",["Member"],[])
        transaction.commit()

        login(self.portal,"basicuser")                               

        # This works just fine,because it was set by my product
        self.assertEquals(membership.memberareaCreationFlag,1,"memberareaCreationFlag must be 1 when it is enabled")    


        members_folder = membership.getMembersFolder()                
        # But this fails
        self.assertIsNotNone(members_folder)     
        # Also we should have the user folder here
        self.assertTrue(members_folder.hasObject('basicuser'))

我特别需要会员文件功能.只是测试用户拥有的文件夹不会削减它.

此外,我尝试使用acl_users.userFolderAddUser创建新用户,但这无助于更好.

memberareaCreationFlag在现场Plone网站上运行得很好.

最佳答案
我终于弄明白了.

首先,membership.memberareaCreationFlag = 1不足以启用成员文件夹.

必须在plone.app.controlpanel.security中使用SecurityControlPanelAdapter启用它

from plone.app.controlpanel.security import ISecuritySchema
# Fetch the adapter
security_adapter =  ISecuritySchema(portal)
security_adapter.set_enable_user_folders(True)

此外,功能测试夹具不会自动创建成员文件夹,但可以在夹具类中手动安装

class YourPloneFixture(PloneSandBoxLayer):
    defaultBases = (PLONE_FIXTURE,)

    def setUpZope(self,app,configurationContext):

        # required by Products.CMFPlone:plone-content
        z2.installProduct(app,'Products.PythonScripts')

    def setUpPloneSite(self,portal):

        # Installs all the Plone stuff. Workflows etc.
        self.applyProfile(portal,'Products.CMFPlone:plone')

        # Install portal content. Including the Members folder!
        self.applyProfile(portal,'Products.CMFPlone:plone-content')

最后,因为会员文件夹是通过用户登录创建的,但plone.app.testing中的登录帮助程序函数似乎太低了.使用zope.testbrowser登录似乎可以解决问题

browser = Browser(self.layer['app'])
browser.open(self.portal.absolute_url() + '/login_form')
browser.getControl(name='__ac_name').value = TEST_USER_NAME
browser.getControl(name='__ac_password').value = TEST_USER_PASSWOR
browser.getControl(name='submit').click()

唷.

原文链接:https://www.f2er.com/python/439161.html

猜你在找的Python相关文章