From bbc5cd989fba1fc94c4a40d0df1478591655d2d8 Mon Sep 17 00:00:00 2001 From: Jamie Bliss Date: Thu, 11 Jan 2024 23:20:15 -0500 Subject: [PATCH] Use httpx_mock instead of httpbin --- tests/core/test_httpy.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/tests/core/test_httpy.py b/tests/core/test_httpy.py index d8d5a98..d3fd34d 100644 --- a/tests/core/test_httpy.py +++ b/tests/core/test_httpy.py @@ -1,7 +1,7 @@ -# FIXME: Better way than hitting live httpbin? import dataclasses import pytest +from pytest_httpx import HTTPXMock from core.httpy import BlockedIPError, Client # TODO: Test async client @@ -22,20 +22,27 @@ def signing_actor(keypair): ) -def test_basics(): +def test_basics(httpx_mock: HTTPXMock): + httpx_mock.add_response() + with Client() as client: resp = client.get("https://httpbin.org/status/200") assert resp.status_code == 200 -def test_signature_exists(signing_actor): +def test_signature_exists(httpx_mock: HTTPXMock, signing_actor): + httpx_mock.add_response() + with Client(actor=signing_actor) as client: resp = client.get("https://httpbin.org/headers") resp.raise_for_status() - body = resp.json() - assert "Signature" in body["headers"] + + request = httpx_mock.get_request() + assert request is not None + assert "Signature" in request.headers def test_ip_block(): + # httpx_mock actually really hates not being called, so don't use it. with pytest.raises(BlockedIPError), Client() as client: client.get("http://localhost/")