4
Summary: Zope Application Testing Support
5
Home-page: http://pypi.python.org/pypi/zope.app.testing
6
Author: Zope Foundation and Contributors
7
Author-email: zope-dev@zope.org
9
Description: This package provides testing support for Zope 3 applications. Besides
10
providing numerous setup convenience functions, it implements a testing setup
11
that allows the user to make calls to the publisher allowing to write
23
1. Use a clean/missing Data.fs
25
2. Create a manager with the name "mgr", password "mgrpw", and grant
26
the zope.Manager role.
30
4. Create a temporary directory to record tcpwatch output.
32
5. Run tcpwatch using:
33
tcpwatch.py -L 8081:8080 -s -r tmpdir
34
(the ports are the listening port and forwarded-to port; the
35
second need to match the Zope configuration)
37
6. In a browser, connect to the listening port and do whatever needs
40
7. Shut down tcpwatch.
42
8. Run the script src/zope/app/testing/dochttp.py:
43
python2.4 src/zope/app/testing/dochttp.py tmpdir > somefile.txt
45
9. Edit the generated text file to add explanations and elide
46
uninteresting portions of the output.
48
10. In a functional test module (usually ftests.py), import
49
FunctionalDocFileSuite from zope.app.testing.functional and
50
instantiate it, passing the name of the text file containing
56
========================
57
DocTest Functional Tests
58
========================
60
This file documents and tests doctest-based functional tests and basic
61
Zope web-application functionality.
63
Request/Response Functional Tests
64
---------------------------------
66
You can create Functional tests as doctests. Typically, this is done
67
by using a script such as src/zope/app/testing/dochttp.py to convert
68
tcpwatch recorded output to a doctest, which is then edited to provide
69
explanation and to remove uninteresting details. That is how this
72
Here we'll test some of the most basic types of access.
74
First, we'll test accessing a protected page without credentials:
77
... GET /@@contents.html HTTP/1.1
79
HTTP/1.1 401 Unauthorized
80
Cache-Control: no-store, no-cache, must-revalidate
82
Content-Type: text/html;charset=utf-8
83
Expires: Mon, 26 Jul 1997 05:00:00 GMT
85
WWW-Authenticate: basic realm="Zope"
87
<!DOCTYPE html PUBLIC ...
89
Here we see that we got:
92
- A WWW-Authenticate header, and
93
- An html body with an error message
94
- Some technical headers to keep squid happy
96
Note that we used ellipsis to indicate ininteresting details.
98
Next, we'll access the same page with credentials:
101
... GET /@@contents.html HTTP/1.1
102
... Authorization: Basic mgr:mgrpw
106
Content-Type: text/html;charset=utf-8
108
<!DOCTYPE html PUBLIC ...
110
Important note: you must use the user named "mgr" with a password
113
And we get a normal output.
115
Next we'll try accessing site management. Since we used "/manage",
119
... GET /++etc++site/@@manage HTTP/1.1
120
... Authorization: Basic mgr:mgrpw
121
... Referer: http://localhost:8081/
123
HTTP/1.1 303 See Other
125
Content-Type: text/plain;charset=utf-8
126
Location: @@contents.html
129
Note that, in this case, we got a 303 response. A 303 response is the
130
prefered response for this sort of redirect with HTTP 1.1. If we used
131
HTTP 1.0, we'd get a 302 response:
134
... GET /++etc++site/@@manage HTTP/1.0
135
... Authorization: Basic mgr:mgrpw
136
... Referer: http://localhost:8081/
138
HTTP/1.0 302 Moved Temporarily
140
Content-Type: text/plain;charset=utf-8
141
Location: @@contents.html
144
Lets visit the page we were redirected to:
147
... GET /++etc++site/@@contents.html HTTP/1.1
148
... Authorization: Basic mgr:mgrpw
149
... Referer: http://localhost:8081/
153
Content-Type: text/html;charset=utf-8
155
<!DOCTYPE html PUBLIC ...
157
Finally, lets access the default page for the site:
161
... Authorization: Basic mgr:mgrpw
165
Content-Type: text/html;charset=utf-8
167
<!DOCTYPE html PUBLIC ...
169
Access to the object system
170
---------------------------
172
You can use the `getRootFolder()` function:
174
>>> root = getRootFolder()
176
<zope.site.folder.Folder object at ...>
178
You can intermix HTTP requests with regular Python calls. Note,
179
however, that making an `http()` call implied a transaction commit.
180
If you want to throw away changes made in Python code, abort the
181
transaction before the HTTP request.
184
... POST /@@contents.html HTTP/1.1
185
... Authorization: Basic mgr:mgrpw
186
... Content-Length: 73
187
... Content-Type: application/x-www-form-urlencoded
189
... type_name=BrowserAdd__zope.site.folder.Folder&new_value=f1""",
190
... handle_errors=False)
191
HTTP/1.1 303 See Other
193
Content-Type: text/html;charset=utf-8
194
Location: http://localhost/@@contents.html
198
Now we can see that the new folder was added:
200
>>> list(root.keys())
211
- Removed test dependency on ``zope.app.zptpage``.
213
- Switched test dependency from ``zope.app.securitypolicy`` to
214
``zope.securitypolicy``.
219
- Rereleasing 3.7.5 as 3.7.7 to fix brown bag release.
225
- Brown bag release: It broke the tests of ``zope.testbrowser``.
231
- Switch doctests to use the stdlib ``doctest`` module, rather than the
232
deprecated ``zope.testing.doctest`` variant.
238
- Import hooks functionality from zope.component after it was moved there from
241
- Import ISite from zope.component after it was moved there from
242
zope.location. This lifts the dependency on zope.location.
244
- Fix tests using a newer zope.publisher that requires zope.login.
249
- Fixed tests for python 2.4 as well as python 2.5 and 2.6; the change in
250
version 3.7.1 introduced test regressions in python 2.4.
255
- Adjusted tests after the referenced memory leak problem has been fixed in
262
- Fixed failing tests. The code revealed that the tests expected the wrong
269
- Depend on new ``zope.processlifetime`` interfaces instead of using
270
BBB imports from ``zope.app.appsetup``.
272
- Removed unused dependency on ``zope.app.component``.
278
- Removed deprecated back35 module and loose the dependency on
279
``zope.deferredimport``.
281
- Adapt to ``zope.app.authentication`` refactoring. We depend on
282
``zope.password`` now instead.
284
- Adapt to latest ``zope.app.security`` refactoring. We don't need this
290
- Use ISkinnable.providedBy(request) instead of IBrowserRequest as condition
291
for calling setDefaultSkin in HTTPCaller. This at the same time removes
292
dependency to the browser part of zope.publisher.
294
- Adapt to the move of IDefaultViewName from zope.component.interfaces
295
to zope.publisher.interfaces.
297
- Remove the DEPENDENCIES.cfg file for zpkg.
302
- Fix AttributeError in ``zope.app.testing.setup.setUpTestAsModule``
303
(when called without name argument).
305
- Use ``zope.container`` instead of ``zope.app.container``.
307
- Use ``zope.site`` instead of ``zope.app.folder`` and
308
``zope.app.component`` for some parts.
313
- Change argument variable name in provideAdapter to not conflict with
314
buitin keyword in Python 2.6.
319
- Re-configured functional test setup to create test-specific instances
320
of HTTPCaller to ensure that cookies are not shared by doctests
326
- Clean up some transaction management in the functional test setup.
331
- Fix isolation enforcement for product configuration around individual tests.
336
- Added missing dependency information in setup.py.
338
- Added missing import.
340
- Repair memory leak fix released in 3.4.3 to be more sane in the presence of
346
- Correct Fred's "I'm a doofus" release.
351
- Add support for product-configuration as part of functional layers; this
352
more closely mirrors the configuration order for normal operation.
357
- Fix memory leak in all functional tests.
358
see: https://bugs.launchpad.net/zope3/+bug/251273
363
- Fix of 599 error on conflict error in request
364
see: http://mail.zope.org/pipermail/zope-dev/2008-January/030844.html
369
- Fixed deprecation warning for ``ZopeSecurityPolicy``.
374
- Initial release independent of the main Zope tree.
376
Keywords: zope3 test testing setup functional
378
Classifier: Development Status :: 5 - Production/Stable
379
Classifier: Environment :: Web Environment
380
Classifier: Intended Audience :: Developers
381
Classifier: License :: OSI Approved :: Zope Public License
382
Classifier: Programming Language :: Python
383
Classifier: Natural Language :: English
384
Classifier: Operating System :: OS Independent
385
Classifier: Topic :: Internet :: WWW/HTTP
386
Classifier: Framework :: Zope3