mirror of
https://github.com/bellingcat/auto-archiver-api.git
synced 2026-06-11 21:18:35 +03:00
new tests and abstractions
This commit is contained in:
@@ -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
|
||||
Reference in New Issue
Block a user