aboutsummaryrefslogtreecommitdiff
path: root/tests/http/conftest.py
diff options
context:
space:
mode:
authorMax Nanis2026-02-19 20:11:41 -0500
committerMax Nanis2026-02-19 20:11:41 -0500
commit8b31678c6e44400967d4934cd9f3c6c6ac0da721 (patch)
tree41c5f4479c353a16da1a8b6fa9088abd084ea388 /tests/http/conftest.py
parentf0f96f83c2630e890a2cbcab53f77fd4c37e1684 (diff)
downloadamt-jb-8b31678c6e44400967d4934cd9f3c6c6ac0da721.tar.gz
amt-jb-8b31678c6e44400967d4934cd9f3c6c6ac0da721.zip
Carer dir into project, some initial pytest, part of the flow tasks. License and Readme update
Diffstat (limited to 'tests/http/conftest.py')
-rw-r--r--tests/http/conftest.py50
1 files changed, 50 insertions, 0 deletions
diff --git a/tests/http/conftest.py b/tests/http/conftest.py
new file mode 100644
index 0000000..200bf1c
--- /dev/null
+++ b/tests/http/conftest.py
@@ -0,0 +1,50 @@
+import httpx
+import pytest
+import requests_mock
+from asgi_lifespan import LifespanManager
+from httpx import AsyncClient, ASGITransport
+
+from jb.main import app
+
+
+@pytest.fixture(scope="session")
+def anyio_backend():
+ return "asyncio"
+
+
+@pytest.fixture(scope="session")
+async def httpxclient():
+ # limiter.enabled = True
+ # limiter.reset()
+ app.testing = True
+
+ async with LifespanManager(app):
+ # await FastAPICache.clear()
+ transport = ASGITransport(app=app)
+ async with AsyncClient(
+ transport=transport, base_url="http://127.0.0.1:8001/"
+ ) as client:
+ yield client
+ await client.aclose()
+
+
+@pytest.fixture()
+def no_limit():
+ """Fixture to execute asserts before and after a test is run"""
+ # limiter.enabled = False
+ yield # this is where the testing happens
+ # limiter.enabled = True
+
+
+@pytest.fixture()
+def httpxclient_ip(httpxclient):
+ """Fixture to execute asserts before and after a test is run"""
+ httpxclient._transport = httpx.ASGITransport(app=app, client=("1.2.3.4", 8001))
+ yield httpxclient # this is where the testing happens
+ httpxclient._transport = httpx.ASGITransport(app=app)
+
+
+@pytest.fixture
+def mock_requests():
+ with requests_mock.Mocker() as m:
+ yield m