Record activity from a WSGI application, and generate WebTest tests from that record
Project description
This package lets you record all the requests and responses of an
application, and then create a doctest from that. (There's no real
reason it couldn't be a unit test... just haven't written that yet.)
The recorder is a piece of middleware. You use it like this::
from webtestrecorder import record_file
app = ... instantiate app ...
app = record_file(app, '/tmp/record.txt')
All requests and responses will be written to this file. You can read
them out like so::
from webtestrecorder import get_records
records = get_records(open('/tmp/record.txt', 'rb'))
``records`` is a list of requests, and each request has a
``.response`` attribute. You can then create a test::
from webtestrecorder import write_doctest
write_doctest(records, open('/tmp/doctest.txt', 'wb'))
You can also use this like a shell script::
$ python -m webtestrecorder < /tmp/record.txt > /tmp/doctest.txt
Apache Logs
-----------
You can read requests and responses from Apache logs via
:func:`webtestrecorder.apachelog.parse_apache_log()`. A constraint of
this is that request bodies won't be present, and responses just have
a status code and Content-Length, the Content-Type is unknown and the body
is padded with null bytes.
Rerunning requests
------------------
The module :mod:`webtestrecorder.http` can take a list of
requests/responses and send them to a server, effectively replaying
requests. This is also a command-line program usable like::
$ python -m webtestrecorder.http apache_access.log --host localhost:8000
You can filter or rewrite these requests with a custom filter
function. See ``python -m webtestrecorder.http -h`` for more.
application, and then create a doctest from that. (There's no real
reason it couldn't be a unit test... just haven't written that yet.)
The recorder is a piece of middleware. You use it like this::
from webtestrecorder import record_file
app = ... instantiate app ...
app = record_file(app, '/tmp/record.txt')
All requests and responses will be written to this file. You can read
them out like so::
from webtestrecorder import get_records
records = get_records(open('/tmp/record.txt', 'rb'))
``records`` is a list of requests, and each request has a
``.response`` attribute. You can then create a test::
from webtestrecorder import write_doctest
write_doctest(records, open('/tmp/doctest.txt', 'wb'))
You can also use this like a shell script::
$ python -m webtestrecorder < /tmp/record.txt > /tmp/doctest.txt
Apache Logs
-----------
You can read requests and responses from Apache logs via
:func:`webtestrecorder.apachelog.parse_apache_log()`. A constraint of
this is that request bodies won't be present, and responses just have
a status code and Content-Length, the Content-Type is unknown and the body
is padded with null bytes.
Rerunning requests
------------------
The module :mod:`webtestrecorder.http` can take a list of
requests/responses and send them to a server, effectively replaying
requests. This is also a command-line program usable like::
$ python -m webtestrecorder.http apache_access.log --host localhost:8000
You can filter or rewrite these requests with a custom filter
function. See ``python -m webtestrecorder.http -h`` for more.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
WebTestRecorder-0.1.tar.gz
(7.9 kB
view details)
File details
Details for the file WebTestRecorder-0.1.tar.gz
.
File metadata
- Download URL: WebTestRecorder-0.1.tar.gz
- Upload date:
- Size: 7.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 62e9a3d2282b55bc44f01499cd16e52aed511c557ea0d283457f97f4f0681218 |
|
MD5 | 77c9da4c825c03aed44fe9990d561af3 |
|
BLAKE2b-256 | 27f5a858741aa556fe0d6e9d100c39e6cf97a025e1b4f14d78a11f89fe2bceb2 |