Ejemplo n.º 1
0
def test_wildcard_accept_set_ok():
    accept = headers.parse_accept("*/*")[0]
    assert accept.type_.is_wildcard
    assert accept.subtype.is_wildcard

    accept = headers.parse_accept("foo/bar")[0]
    assert not accept.type_.is_wildcard
    assert not accept.subtype.is_wildcard
Ejemplo n.º 2
0
def test_value_not_in_accept(value):
    acceptable = headers.parse_accept(value)
    assert "no/match" not in acceptable
    assert "no/*" not in acceptable
Ejemplo n.º 3
0
def test_value_in_accept(value):
    acceptable = headers.parse_accept(value)
    assert "foo/bar" in acceptable
    assert "foo/*" in acceptable
    assert "*/*" in acceptable
Ejemplo n.º 4
0
def test_empty_accept():
    assert headers.parse_accept("") == []
Ejemplo n.º 5
0
def test_bad_accept(raw):
    with pytest.raises(InvalidHeader):
        headers.parse_accept(raw)
Ejemplo n.º 6
0
def test_parse_accept_ordered_okay(raw):
    ordered = headers.parse_accept(raw)
    expected_subtype = ("*" if all(q.subtype.is_wildcard
                                   for q in ordered) else "first")
    assert ordered[0].type_ == "show"
    assert ordered[0].subtype == expected_subtype
Ejemplo n.º 7
0
 def accept(self) -> AcceptContainer:
     if self.parsed_accept is None:
         accept_header = self.headers.getone("accept", "")
         self.parsed_accept = parse_accept(accept_header)
     return self.parsed_accept