Exemplo n.º 1
0
    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
Exemplo n.º 2
0
    def test_on_no_accept_dt_error(self):

        client = Client(application)
        builder = EnvironBuilder(path="/tg/http://www.espn.com",
                                 headers=[("Prefer", "no_accept_dt_error")])
        env = builder.get_environ()
        app_iter, status, headers = client.run_wsgi_app(env)

        assert "400" in status
Exemplo n.º 3
0
    def test_on_valid_internal_redirect(self):
        client = Client(application)
        builder = EnvironBuilder(path="/20160101010101/http://www.espn.com",
                                 headers=[("Prefer", "valid_internal_redirect")
                                          ])
        env = builder.get_environ()
        app_iter, status, headers = client.run_wsgi_app(env)

        assert "302" in status
        assert headers.get("Location") is not None
Exemplo n.º 4
0
    def test_tg_200(self):
        client = Client(application)
        builder = EnvironBuilder(path="/tg/http://www.espn.com",
                                 headers=[("Prefer", "tg_200")])
        env = builder.get_environ()
        app_iter, status, headers = client.run_wsgi_app(env)

        assert "200" in status
        assert headers.get("Link")
        assert "accept-datetime" in headers.get("Vary", "")
        assert headers.get("memento-datetime") is not None
Exemplo n.º 5
0
    def test_on_no_vary_header(self):

        client = Client(application)
        builder = EnvironBuilder(path="/tg/http://www.espn.com",
                                 headers=[("Prefer", "no_vary_header")])
        env = builder.get_environ()
        app_iter, status, headers = client.run_wsgi_app(env)

        assert "302" in status
        assert headers.get("Link")
        assert headers.get("Vary") is None
Exemplo n.º 6
0
    def test_on_no_link_header(self):

        client = Client(application)
        builder = EnvironBuilder(path="/2016/http://www.espn.com",
                                 headers=[("Prefer", "no_link_header")])
        env = builder.get_environ()
        app_iter, status, headers = client.run_wsgi_app(env)

        assert "200" in status
        assert not headers.get("Link")
        assert headers.get("Memento-Datetime") is not None
Exemplo n.º 7
0
    def test_on_invalid_archived_redirect(self):
        client = Client(application)
        builder = EnvironBuilder(path="/2016/http://www.espn.com",
                                 headers=[("Prefer",
                                           "invalid_archived_redirect")])
        env = builder.get_environ()
        app_iter, status, headers = client.run_wsgi_app(env)

        assert "302" in status
        assert headers.get("Location") is None \
               or headers.get("Link") is None \
               or headers.get("Memento-Datetime") is None
Exemplo n.º 8
0
    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
Exemplo n.º 9
0
    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
Exemplo n.º 10
0
    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
Exemplo n.º 11
0
    def test_on_invalid_link_header(self):

        client = Client(application)
        builder = EnvironBuilder(path="/tg/http://www.espn.com",
                                 headers=[("Prefer", "invalid_link_header")])
        env = builder.get_environ()
        app_iter, status, headers = client.run_wsgi_app(env)

        assert "302" in status
        assert headers.get("Link")
        assert headers.get("Vary")

        with self.assertRaises(Exception):
            parse_link_header(headers.get("Link"))
Exemplo n.º 12
0
    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
Exemplo n.º 13
0
    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"])
Exemplo n.º 14
0
    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")
Exemplo n.º 15
0
    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])
Exemplo n.º 16
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"])
Exemplo n.º 17
0
    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