[Grok-dev] TypeError with adapting a principal, only in functional test

Peter Bengtsson peter at fry-it.com
Thu Jul 3 04:44:19 EDT 2008


Hi, I hope this is not a bug but something I've done wrong. I've got
an app with login and a user class. It works fine when running Zope
but I can't write a functional test that (using the testbrowser)
registers a new user.
Here's the code to save_user() (mentioned in the traceback below)


def save_user(login, password, name, email):
    pau = getUtility(IAuthentication)
    principals = pau['principals']
    # create an instance of InternalPrincipal
    principal = InternalPrincipal(login, password, name,
                                  passwordManagerName='SHA1')

    # add principal to principal folder; we may assume that the login
    # name is unique because of validation on the IUser interface
    # but to be doubly sure, we assert this
    assert login not in principals, "Login already in use"
    principals[login] = principal
    # save the e-mail

    user = IUser(principal)
    user.email = email
    # grant the user permission to view the member listing
    permission_mngr = IPrincipalPermissionManager(grok.getSite())
    permission_mngr.grantPermissionToPrincipal(
           ADD_RECIPE_PERMISSION,
           principals.prefix + login)
    permission_mngr.grantPermissionToPrincipal(
           EDIT_RECIPE_PERMISSION,
           principals.prefix + login)

    return user

And the interface::

class IUser(Interface):
    """Basic user data."""
    login                = TextLine(title=_(u"Login"), required=True,
constraint=unique_login)
    password             = Password(title=_(u"Password"), required=True)
    name                 = TextLine(title=_(u"Full name"), required=False)
    email                = ASCIILine(title=_(u"E-mail"),
required=False, constraint=valid_email)

    def get_name():
        """ return the name of the user """

    def get_email():
        """ return the email of the user """




File "/home/peterbe/dev/GROK/TheGrokWay/src/thegrokway/functional_tests/master.txt",
line 27, in master.txt
Failed example:
    browser.getControl(name='form.actions.save').click()
Exception raised:
    Traceback (most recent call last):
      File "/home/peterbe/buildout-eggs/tmps7zVJa/zope.testing-3.5.1-py2.4.egg/zope/testing/doctest.py",
line 1356, in __run

      File "<doctest master.txt[13]>", line 1, in ?
        browser.getControl(name='form.actions.save').click()
      File "/home/peterbe/buildout-eggs/zope.testbrowser-3.4.1-py2.4.egg/zope/testbrowser/browser.py",
line 591, in click
        self.browser._clickSubmit(self.mech_form, self.mech_control, (1,1))
      File "/home/peterbe/buildout-eggs/zope.testbrowser-3.4.1-py2.4.egg/zope/testbrowser/browser.py",
line 380, in _clickSubmit
        self.mech_browser.open(form.click(
      File "build/bdist.linux-i686/egg/mechanize/_mechanize.py", line
203, in open
      File "build/bdist.linux-i686/egg/mechanize/_mechanize.py", line
229, in _mech_open
      File "build/bdist.linux-i686/egg/mechanize/_opener.py", line 181, in open
      File "/usr/lib/python2.4/urllib2.py", line 376, in _open
        '_open', req)
      File "/usr/lib/python2.4/urllib2.py", line 337, in _call_chain
        result = func(*args)
      File "/home/peterbe/buildout-eggs/zope.testbrowser-3.4.1-py2.4.egg/zope/testbrowser/testing.py",
line 131, in http_open
        return self.do_open(PublisherConnection, req)
      File "/usr/lib/python2.4/urllib2.py", line 993, in do_open
        h.request(req.get_method(), req.get_selector(), req.data, headers)
      File "/home/peterbe/buildout-eggs/zope.testbrowser-3.4.1-py2.4.egg/zope/testbrowser/testing.py",
line 84, in request
        self.response = self.caller(request_string, handle_errors)
      File "/home/peterbe/buildout-eggs/tmpbwL9Bs/zope.app.testing-3.4.0a1-py2.4.egg/zope/app/testing/functional.py",
line 604, in __call__
      File "/home/peterbe/buildout-eggs/tmpLjcktJ/zope.publisher-3.5.0a1.dev_r78838-py2.4.egg/zope/publisher/publish.py",
line 133, in publish
      File "/home/peterbe/buildout-eggs/tmp_TGW-i/grok-0.12.1-py2.4.egg/grok/publication.py",
line 45, in callObject
      File "/home/peterbe/buildout-eggs/tmpbJjpQ5/zope.app.publication-3.4.2-py2.4.egg/zope/app/publication/zopepublication.py",
line 167, in callObject
      File "/home/peterbe/buildout-eggs/tmpLjcktJ/zope.publisher-3.5.0a1.dev_r78838-py2.4.egg/zope/publisher/publish.py",
line 108, in mapply
      File "/home/peterbe/buildout-eggs/tmpLjcktJ/zope.publisher-3.5.0a1.dev_r78838-py2.4.egg/zope/publisher/publish.py",
line 114, in debug_call
      File "/home/peterbe/buildout-eggs/tmp_TGW-i/grok-0.12.1-py2.4.egg/grok/components.py",
line 500, in __call__
      File "/home/peterbe/buildout-eggs/tmp_TGW-i/grok-0.12.1-py2.4.egg/grok/components.py",
line 472, in update_form
      File "/home/peterbe/buildout-eggs/zope.formlib-3.4.0-py2.4.egg/zope/formlib/form.py",
line 754, in update
        result = action.success(data)
      File "/home/peterbe/buildout-eggs/tmp_TGW-i/grok-0.12.1-py2.4.egg/grok/formlib.py",
line 18, in success
      File "/home/peterbe/dev/GROK/TheGrokWay/src/thegrokway/app.py",
line 236, in save
        save_user(login, password, name, email)
      File "/home/peterbe/dev/GROK/TheGrokWay/src/thegrokway/app.py",
line 71, in save_user
        user = IUser(principal)
    TypeError: ('Could not adapt',
<zope.app.authentication.principalfolder.InternalPrincipal object at
0x9804d2c>, <InterfaceClass thegrokway.interfaces.IUser>)



-- 
Peter Bengtsson,
work www.fry-it.com
home www.peterbe.com
hobby www.issuetrackerproduct.com


More information about the Grok-dev mailing list