Memento Test Server that can be used by Memento clients for testing various scenarios from the Memento Protocol. TimeGate and Memento endpoints are provided in this server.
This server recognizes the "Prefer" HTTP header and clients should use this header to express the kind of response that they expect from a Memento endpoint.
For example, for the TimeGate to respond with only the minimum required Memento headers, add the value "required_headers" to the Prefer header of the request.
$ curl -H "Prefer: required_headers" -I http://localhost:4000/tg/http://www.test.com
HTTP/1.0 302 FOUND
Link: <http://www.test.com>; rel="original"
Vary: accept-datetime
Location: http://www.example.com/20170713121257/http://www.test.com
Preference-Applied: required_headers
Content-Type: text/plain; charset=utf-8
A list of all the Preferences that the server recognizes are provided in the docs.
$ pip install memento_test
$ memento_test_server
This library can be invoked by another Python application without running this as a server. Meaning, another application or library can make virtual requests to this library and receive responses without starting up this up as a server. Typical use case for this is in unit testing, whereby, an application will not have to start a server every time the test cases need to be run. For this, memento_test uses werkzeug's test suite to create a mock server.
For example:
import unittest
from memento_test.server import application
from werkzeug.test import Client, EnvironBuilder
class MementoTest(unittest.TestCase):
def test_on_all_headers(self):
client = Client(application)
builder = EnvironBuilder(path="/2016/http://www.espn.com",
headers=[("Prefer", "all_headers")])
env = builder.get_environ()
app_iter, status, headers = client.run_wsgi_app(env)
assert "200" in status
assert headers.get("Link")
assert headers.get("Memento-Datetime") is not None
More examples can be found in the tests.
For complete information on the Memento headers, please refer to the Memento RFC
For each of the parameters below, the TimeGate will respond by providing:
all_headers
: All required and recommended Memento headers.required_headers
: Only the required Memento headers.no_headers
: No Memento headers.no_link_header
: NoLink
header, but other relevant Memento headers will be returned.no_vary_header
: NoVary
header, but other relevant Memento headers will be returned.no_original_link_header
: Norel="original"
URL will be provided in theLink
header.invalid_vary_header
: An invalid value in theVary
header instead ofaccept-datetime
.invalid_link_header
: An invalid, un-parseableLink
header value.invalid_datetime_in_link_header
: Invalid datetime values in theLink
header.no_accept_dt_error
: HTTP 400 error is returned as the TG cannot handle requests withoutAccept-Datetime
.tg_no_redirect
: TG not redirecting by providing noLocation
header and a non30*
HTTP response code.tg_302
: A valid TG response with a302
response. Identical toall_headers
.tg_303
: A valid TG response with a303
response.tg_200
: A valid200
style response from TG withContent-Location
header.tg_302_no_location_header
: Atg_302
response without theLocation
header.tg_303_no_location_header
: Atg_303
response without the `Location header.tg_200_no_memento_dt_header
: Atg_200
response withtout the requiredMemento-Datetime
header.tg_no_accept_dt_no_redirect_to_last_memento
: No redirect to thelast memento
URL when noAccept-Datetime
is provided in the request.tg_no_accept_dt_redirect_to_last_memento
: Redirect correctly to thelast memento
URL when noAccept-Datetime
is provided in the request.tg_302_memento_dt_header
: AMemento-Datetime
header is returned for a302
TG response.
all_headers
: All required and recommended Memento headers.required_headers
: Only the required Memento headers.no_headers
: No Memento headers.no_link_header
: NoLink
header, but other relevant Memento headers will be returned.no_original_link_header
: Norel="original"
URL will be provided in theLink
header.invalid_link_header
: An invalid, un-parseableLink
header value.invalid_datetime_in_link_header
: Invalid datetime values in theLink
header.no_memento_dt_header
: NoMemento-Datetime
header.invalid_memento_dt_header
: Invalid value for theMemento-Datetime
header.valid_archived_redirect
: All the required and recommended headers for an archived redirect.valid_internal_redirect
: All the required and recommended headers for an internal redirect.invalid_archived_redirect
: Invalid headers for an archived redirect.invalid_internal_redirect
: Invalid headers for an internal redirect.
TODO:
invalid_accept_dt_header
relative_url_in_location_header
tg_200_no_vary_header
vary_header
for memento