def test_on_invalid_link_header(self): client = Client(application) builder = EnvironBuilder(path="/2016/http://www.espn.com", headers=[("Prefer", "invalid_link_header")]) 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 with self.assertRaises(Exception): parse_link_header(headers.get("Link"))
def test_tg_302(self): client = Client(application) builder = EnvironBuilder(path="/tg/http://www.espn.com", headers=[("Prefer", "tg_302")]) env = builder.get_environ() app_iter, status, headers = client.run_wsgi_app(env) assert "302" in status assert headers.get("Link") assert "accept-datetime" in headers.get("Vary", "") assert headers.get("Location") is not None lh = parse_link_header(headers.get("Link")) assert get_uri_dt_for_rel(lh, ["original"]) assert get_uri_dt_for_rel(lh, ["first"]) f_dt = get_uri_dt_for_rel(lh, ["first"]).get("first") assert convert_to_datetime(f_dt["datetime"][0]) is not None assert get_uri_dt_for_rel(lh, ["last"]) l_dt = get_uri_dt_for_rel(lh, ["last"]).get("last") assert convert_to_datetime(l_dt["datetime"][0]) is not None assert get_uri_dt_for_rel(lh, ["memento"]) m_dt = get_uri_dt_for_rel(lh, ["memento"]).get("memento") assert convert_to_datetime(m_dt["datetime"][0]) is not None
def test_on_redirect(self): client = Client(application) builder = EnvironBuilder(path="/", headers=[("Prefer", "redirect")]) env = builder.get_environ() app_iter, status, headers = client.run_wsgi_app(env) assert "302" in status lh = parse_link_header(headers.get("Link")) assert get_uri_dt_for_rel(lh, ["timegate"]) is None assert headers.get("Location") is not None
def test_on_no_native_tg_url(self): client = Client(application) builder = EnvironBuilder(path="/", headers=[("Prefer", "no_native_tg_url")]) env = builder.get_environ() app_iter, status, headers = client.run_wsgi_app(env) assert "200" in status lh = parse_link_header(headers.get("Link")) assert get_uri_dt_for_rel(lh, ["timegate"]) is None
def test_on_no_memento_dt_header(self): client = Client(application) builder = EnvironBuilder(path="/2016/http://www.espn.com", headers=[("Prefer", "no_memento_dt_header")]) 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 None lh = parse_link_header(headers.get("Link")) assert get_uri_dt_for_rel(lh, ["original"]) is not None
def test_on_valid_archived_redirect(self): client = Client(application) builder = EnvironBuilder(path="/20160101010101/http://www.espn.com", headers=[("Prefer", "valid_archived_redirect") ]) env = builder.get_environ() app_iter, status, headers = client.run_wsgi_app(env) assert "302" in status assert headers.get("Link") is not None assert headers.get("Memento-Datetime") is not None lh = parse_link_header(headers.get("Link")) assert get_uri_dt_for_rel(lh, ["original"]) is not None assert headers.get("Location") is not None
def test_on_no_original_link_header(self): client = Client(application) builder = EnvironBuilder(path="/tg/http://www.espn.com", headers=[("Prefer", "no_original_link_header") ]) env = builder.get_environ() app_iter, status, headers = client.run_wsgi_app(env) assert "302" in status assert headers.get("Link") is not None assert headers.get("Vary") is not None lh = parse_link_header(headers.get("link")) assert not get_uri_dt_for_rel(lh, ["original"]) assert get_uri_dt_for_rel(lh, ["memento"])
def test_tg_no_accept_dt_redirect_to_last_memento(self): client = Client(application) builder = EnvironBuilder( path="/tg/http://www.espn.com", headers=[("Prefer", "tg_no_accept_dt_redirect_to_last_memento")]) env = builder.get_environ() app_iter, status, headers = client.run_wsgi_app(env) assert "302" in status assert headers.get("Link") assert "accept-datetime" in headers.get("Vary", "") assert headers.get("Location") is not None lh = parse_link_header(headers.get("Link")) assert get_uri_dt_for_rel(lh, ["last"]) l_uri = get_uri_dt_for_rel(lh, ["last"]).get("last").get("uri") assert l_uri == headers.get("Location")
def test_on_invalid_datetime_in_link_header(self): client = Client(application) builder = EnvironBuilder(path="/2016/http://www.espn.com", headers=[("Prefer", "invalid_datetime_in_link_header")]) 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 lh = parse_link_header(headers.get("Link")) memento = get_uri_dt_for_rel(lh, ["memento"]).get("memento") with self.assertRaises(ValueError): convert_to_datetime(memento.get("datetime")[0])
def test_on_required_headers(self): client = Client(application) builder = EnvironBuilder(path="/tg/http://www.espn.com", headers=[("Prefer", "required_headers")]) env = builder.get_environ() app_iter, status, headers = client.run_wsgi_app(env) assert "302" in status assert headers.get("Link") assert "accept-datetime" in headers.get("Vary", "") lh = parse_link_header(headers.get("Link")) assert get_uri_dt_for_rel(lh, ["original"]) assert not get_uri_dt_for_rel(lh, ["first"]) assert not get_uri_dt_for_rel(lh, ["last"]) assert not get_uri_dt_for_rel(lh, ["memento"])
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 lh = parse_link_header(headers.get("Link")) assert get_uri_dt_for_rel(lh, ["original"]) is not None assert get_uri_dt_for_rel(lh, ["first"]) is not None f_dt = get_uri_dt_for_rel(lh, ["first"]).get("first") assert convert_to_datetime(f_dt["datetime"][0]) is not None assert get_uri_dt_for_rel(lh, ["last"]) l_dt = get_uri_dt_for_rel(lh, ["last"]).get("last") assert convert_to_datetime(l_dt["datetime"][0]) is not None assert get_uri_dt_for_rel(lh, ["memento"]) m_dt = get_uri_dt_for_rel(lh, ["memento"]).get("memento") assert convert_to_datetime(m_dt["datetime"][0]) is not None