Example #1
0
def test_bitwise_operators(method, url, expected):
    pattern = ((Method("GET") | Method("post") | Method("Patch"))
               & URL("https://foo.bar/")) | (Method("POST")
                                             & ~URL("https://foo.bar/"))
    request = httpx.Request(method, url)
    assert bool(pattern.match(request)) is expected
    assert bool(~pattern.match(request)) is not expected
Example #2
0
def test_match_context():
    request = httpx.Request("GET", "https://foo.bar/baz/?ham=spam")
    pattern = (URL(r"https?://foo.bar/(?P<slug>\w+)/", Lookup.REGEX)
               & URL(r"https://(?P<host>[^/]+)/baz/", Lookup.REGEX)
               & Params({"ham": "spam"}))
    match = pattern.match(request)
    assert bool(match)
    assert match.context == {"host": "foo.bar", "slug": "baz"}
Example #3
0
def test_url_pattern_invalid():
    with pytest.raises(ValueError, match="Invalid"):
        URL(["invalid"])
Example #4
0
def test_url_pattern(lookup, value, context, url, expected):
    request = httpx.Request("GET", url)
    match = URL(value, lookup=lookup).match(request)
    assert bool(match) is expected
    assert match.context == context
Example #5
0
def test_url_pattern__contains(url, expected):
    _request = httpx.Request("GET", "https://foo.bar/baz/?ham=spam&egg=yolk")
    for request in (_request, encode(_request)):
        assert bool(URL(url,
                        lookup=Lookup.CONTAINS).match(request)) is expected
Example #6
0
def test_url_pattern(lookup, url, context, expected):
    _request = httpx.Request("GET", "https://foo.bar/baz/")
    for request in (_request, encode(_request)):
        match = URL(url, lookup=lookup).match(request)
        assert bool(match) is expected
        assert match.context == context