/usr/share/pyshared/zope/app/testing/doctest.txt is in python-zope.app.testing 3.10.0-0ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 | ========================
DocTest Functional Tests
========================
This file documents and tests doctest-based functional tests and basic
Zope web-application functionality.
Request/Response Functional Tests
---------------------------------
You can create Functional tests as doctests. Typically, this is done
by using a script such as src/zope/app/testing/dochttp.py to convert
tcpwatch recorded output to a doctest, which is then edited to provide
explanation and to remove uninteresting details. That is how this
file was created.
Here we'll test some of the most basic types of access.
First, we'll test accessing a protected page without credentials:
>>> print http(r"""
... GET /@@contents.html HTTP/1.1
... """)
HTTP/1.1 401 Unauthorized
Cache-Control: no-store, no-cache, must-revalidate
Content-Length: ...
Content-Type: text/html;charset=utf-8
Expires: Mon, 26 Jul 1997 05:00:00 GMT
Pragma: no-cache
WWW-Authenticate: basic realm="Zope"
<BLANKLINE>
<!DOCTYPE html PUBLIC ...
Here we see that we got:
- A 401 response,
- A WWW-Authenticate header, and
- An html body with an error message
- Some technical headers to keep squid happy
Note that we used ellipsis to indicate ininteresting details.
Next, we'll access the same page with credentials:
>>> print http(r"""
... GET /@@contents.html HTTP/1.1
... Authorization: Basic mgr:mgrpw
... """)
HTTP/1.1 200 OK
Content-Length: ...
Content-Type: text/html;charset=utf-8
<BLANKLINE>
<!DOCTYPE html PUBLIC ...
Important note: you must use the user named "mgr" with a password
"mgrpw".
And we get a normal output.
Next we'll try accessing site management. Since we used "/manage",
we got redirected:
>>> print http(r"""
... GET /++etc++site/@@manage HTTP/1.1
... Authorization: Basic mgr:mgrpw
... Referer: http://localhost:8081/
... """)
HTTP/1.1 303 See Other
Content-Length: 0
Content-Type: text/plain;charset=utf-8
Location: @@contents.html
<BLANKLINE>
Note that, in this case, we got a 303 response. A 303 response is the
prefered response for this sort of redirect with HTTP 1.1. If we used
HTTP 1.0, we'd get a 302 response:
>>> print http(r"""
... GET /++etc++site/@@manage HTTP/1.0
... Authorization: Basic mgr:mgrpw
... Referer: http://localhost:8081/
... """)
HTTP/1.0 302 Moved Temporarily
Content-Length: 0
Content-Type: text/plain;charset=utf-8
Location: @@contents.html
<BLANKLINE>
Lets visit the page we were redirected to:
>>> print http(r"""
... GET /++etc++site/@@contents.html HTTP/1.1
... Authorization: Basic mgr:mgrpw
... Referer: http://localhost:8081/
... """)
HTTP/1.1 200 OK
Content-Length: ...
Content-Type: text/html;charset=utf-8
<BLANKLINE>
<!DOCTYPE html PUBLIC ...
Finally, lets access the default page for the site:
>>> print http(r"""
... GET / HTTP/1.1
... Authorization: Basic mgr:mgrpw
... """)
HTTP/1.1 200 OK
Content-Length: ...
Content-Type: text/html;charset=utf-8
<BLANKLINE>
<!DOCTYPE html PUBLIC ...
Access to the object system
---------------------------
You can use the `getRootFolder()` function:
>>> root = getRootFolder()
>>> root
<zope.site.folder.Folder object at ...>
You can intermix HTTP requests with regular Python calls. Note,
however, that making an `http()` call implied a transaction commit.
If you want to throw away changes made in Python code, abort the
transaction before the HTTP request.
>>> print http(r"""
... POST /@@contents.html HTTP/1.1
... Authorization: Basic mgr:mgrpw
... Content-Length: 73
... Content-Type: application/x-www-form-urlencoded
...
... type_name=BrowserAdd__zope.site.folder.Folder&new_value=f1""",
... handle_errors=False)
HTTP/1.1 303 See Other
Content-Length: ...
Content-Type: text/html;charset=utf-8
Location: http://localhost/@@contents.html
<BLANKLINE>
<!DOCTYPE html ...
Now we can see that the new folder was added:
>>> list(root.keys())
[u'f1']
|