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
def test_value_not_in_accept(value): acceptable = headers.parse_accept(value) assert "no/match" not in acceptable assert "no/*" not in acceptable
def test_value_in_accept(value): acceptable = headers.parse_accept(value) assert "foo/bar" in acceptable assert "foo/*" in acceptable assert "*/*" in acceptable
def test_empty_accept(): assert headers.parse_accept("") == []
def test_bad_accept(raw): with pytest.raises(InvalidHeader): headers.parse_accept(raw)
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
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