Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async def test(backend):
url = "https://foo.bar/1/"
respx.get(re.compile("https://some.thing"))
respx.delete("https://some.thing")
foobar1 = respx.get(url, status_code=202, alias="get_foobar")
foobar2 = respx.delete(url, status_code=200, alias="del_foobar")
assert foobar1.called is False
assert foobar1.call_count == len(foobar1.calls)
assert foobar1.call_count == 0
assert respx.stats.call_count == len(respx.calls)
assert respx.stats.call_count == 0
async with httpx.AsyncClient() as client:
get_response = await client.get(url)
del_response = await client.delete(url)
assert foobar1.called is True
assert foobar2.called is True
async def test(backend):
url = "https://foo.bar/1/"
respx.get(re.compile("https://some.thing"))
respx.delete("https://some.thing")
foobar1 = respx.get(url, status_code=202, alias="get_foobar")
foobar2 = respx.delete(url, status_code=200, alias="del_foobar")
assert foobar1.called is False
assert foobar1.call_count == len(foobar1.calls)
assert foobar1.call_count == 0
assert respx.stats.call_count == len(respx.calls)
assert respx.stats.call_count == 0
async with httpx.AsyncClient() as client:
get_response = await client.get(url)
del_response = await client.delete(url)
assert foobar1.called is True
assert foobar2.called is True
assert foobar1.call_count == 1
assert foobar2.call_count == 1
async def test_http_methods(client):
async with respx.mock:
url = "https://foo.bar/"
m = respx.get(url, status_code=404)
respx.post(url, status_code=201)
respx.put(url, status_code=202)
respx.patch(url, status_code=500)
respx.delete(url, status_code=204)
respx.head(url, status_code=405)
respx.options(url, status_code=501)
response = httpx.get(url)
assert response.status_code == 404
response = await client.get(url)
assert response.status_code == 404
response = httpx.post(url)
assert response.status_code == 201
response = await client.post(url)
assert response.status_code == 201
response = httpx.put(url)
assert response.status_code == 202
response = await client.put(url)