示例#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
示例#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
示例#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
示例#4
0
def test_empty_accept():
    assert headers.parse_accept("") == []
示例#5
0
def test_bad_accept(raw):
    with pytest.raises(InvalidHeader):
        headers.parse_accept(raw)
示例#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
示例#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