[Zope] Offline testing

Chris McDonough chrism@digicool.com
Mon, 26 Feb 2001 14:50:28 -0500


Hi John...

This might have to do with the fact that PythonScripts are looking for
REQUEST.  When you do "import Zope; app=Zope.app()", a REQUEST cannot be
acquired through objects in the system.  In normal operation, they can be.
Here's a way around it:

import ZODB # this is "magical", unfortunately
import os
from os import environ
from sys import stdin
from ZPublisher.HTTPRequest import HTTPRequest
from ZPublisher.HTTPResponse import HTTPResponse
from ZPublisher.BaseRequest import RequestContainer

def makerequest(app):
    resp = HTTPResponse()
    environ['SERVER_NAME']='foo'
    environ['SERVER_PORT']='80'
    environ['REQUEST_METHOD'] = 'GET'
    req = HTTPRequest(stdin, environ, resp)
    return app.__of__(RequestContainer(REQUEST = req))

class ATest(TestCase):
    def setUp(self):
        import Zope
        self.app = makerequest(Zope.app())

self.app will be bound to a Zope instance with a fake request in all your
test cases now.


----- Original Message -----
From: "John R. Daily" <jdaily@progeny.com>
To: <zope@zope.org>
Sent: Monday, February 26, 2001 1:13 PM
Subject: [Zope] Offline testing


> I'm attempting to run offline unit tests (via PyUnit, importing the
> Zope module with Zope turned off) against some functionality I've
> written via Python Scripts. The error messages are not helping much,
> and the online tests work fine, so I'm at a loss to troubleshoot this.
>
> Any suggestions on how to interpret the following, or pointers to Zope
> troubleshooting resources that would help, would be greatly appreciated.
>
> Essentially, I have a /lib/issue/add_issue Python script which takes a
> string argument and creates a new folder by that name in a certain
> path. The add_issue script acts under a proxy to run as a Manager.
>
> Run: 4 ; Failures: 0; Errors: 1
> There was 1 error:
> 1) issues.issuesTest.runTest
> Traceback (innermost last):
>   File "issues.py", line 45, in runTest
>     id.append(libissue.add_issue(self.type))
>   File "/usr/lib/zope/lib/python/Shared/DC/Scripts/Bindings.py", line 324,
in __call__
>     return self._bindAndExec(args, kw, None)
>   File "/usr/lib/zope/lib/python/Shared/DC/Scripts/Bindings.py", line 353,
in _bindAndExec
>     return self._exec(bound_data, args, kw)
>   File "/usr/lib/zope/lib/python/Products/PythonScripts/PythonScript.py",
line 330, in _exec
>     result = apply(f, args, kw)
>   File "Script (Python)", line 32, in add_issue
>   File "/usr/lib/zope/lib/python/OFS/PropertyManager.py", line 355, in
manage_changeProperties
>     return
self.manage_propertiesForm(self,REQUEST,manage_tabs_message=message)
>   File "/usr/lib/zope/lib/python/Shared/DC/Scripts/Bindings.py", line 324,
in __call__
>     return self._bindAndExec(args, kw, None)
>   File "/usr/lib/zope/lib/python/Shared/DC/Scripts/Bindings.py", line 353,
in _bindAndExec
>     return self._exec(bound_data, args, kw)
>   File "/usr/lib/zope/lib/python/App/special_dtml.py", line 236, in _exec
>     try: result = render_blocks(self._v_blocks, ns)
>   File "/usr/lib/zope/lib/python/Shared/DC/Scripts/Bindings.py", line 337,
in __render_with_namespace__
>     return self._bindAndExec((), namevals, namespace)
>   File "/usr/lib/zope/lib/python/Shared/DC/Scripts/Bindings.py", line 353,
in _bindAndExec
>     return self._exec(bound_data, args, kw)
>   File "/usr/lib/zope/lib/python/App/special_dtml.py", line 236, in _exec
>     try: result = render_blocks(self._v_blocks, ns)
>   File "/usr/lib/zope/lib/python/DocumentTemplate/DT_Let.py", line 146, in
render
>     else: d[name]=expr(md)
>   File "/usr/lib/zope/lib/python/DocumentTemplate/DT_Util.py", line 334,
in eval
>     return eval(code,globals,d)
>   File "<string>", line 0, in ?
>   File "/usr/lib/zope/lib/python/DocumentTemplate/DT_Util.py", line 127,
in careful_getattr
>     try: v=getattr(inst, name)
> AttributeError: 'None' object has no attribute 'get'
>
> --                                                                   --
> John R. Daily                                        jdaily@progeny.com
> Systems Programmer                                Progeny Linux Systems
>   Master of the ephemeral epiphany
>
> _______________________________________________
> Zope maillist  -  Zope@zope.org
> http://lists.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists -
>  http://lists.zope.org/mailman/listinfo/zope-announce
>  http://lists.zope.org/mailman/listinfo/zope-dev )
>