new tests and abstractions

This commit is contained in:
msramalho
2024-10-18 19:46:56 +01:00
parent 56a81f6ec0
commit 6b9d6e2245
5 changed files with 45 additions and 32 deletions

View File

@@ -70,9 +70,10 @@ def client(app):
@pytest.fixture()
def app_with_auth(app):
from security import get_token_or_user_auth, get_user_auth
from security import get_token_or_user_auth, get_user_auth, token_api_key_auth
app.dependency_overrides[get_token_or_user_auth] = lambda: "rick@example.com"
app.dependency_overrides[get_user_auth] = lambda: "morty@example.com"
app.dependency_overrides[token_api_key_auth] = lambda: "jerry@example.com"
return app
@@ -80,3 +81,13 @@ def app_with_auth(app):
def client_with_auth(app_with_auth):
client = TestClient(app_with_auth)
return client
@pytest.fixture()
def test_no_auth():
# reusable code to ensure a method/endpoint combination is unauthorized
def no_auth(http_method, endpoint):
response = http_method(endpoint)
assert response.status_code == 403
assert response.json() == {"detail": "Not authenticated"}
return no_auth