2022-07-05 12:54:21 +00:00
|
|
|
"""Tests configuration."""
|
|
|
|
# pylint: disable=redefined-outer-name
|
|
|
|
# pylint: disable=unused-argument
|
2021-11-29 19:16:08 +00:00
|
|
|
import pytest
|
2022-08-10 23:36:36 +00:00
|
|
|
from fastapi.testclient import TestClient
|
2021-11-29 19:16:08 +00:00
|
|
|
|
2022-01-24 20:01:37 +00:00
|
|
|
|
2022-01-18 15:20:47 +00:00
|
|
|
@pytest.fixture
|
|
|
|
def tokens_file(mocker, shared_datadir):
|
2022-07-05 12:54:21 +00:00
|
|
|
"""Mock tokens file."""
|
2022-01-24 20:01:37 +00:00
|
|
|
mock = mocker.patch(
|
|
|
|
"selfprivacy_api.utils.TOKENS_FILE", shared_datadir / "tokens.json"
|
|
|
|
)
|
2022-01-18 15:20:47 +00:00
|
|
|
return mock
|
2021-11-29 19:16:08 +00:00
|
|
|
|
2022-08-17 20:58:56 +00:00
|
|
|
|
2022-08-15 21:31:24 +00:00
|
|
|
@pytest.fixture
|
|
|
|
def jobs_file(mocker, shared_datadir):
|
|
|
|
"""Mock tokens file."""
|
2022-08-17 21:38:38 +00:00
|
|
|
mock = mocker.patch(
|
|
|
|
"selfprivacy_api.utils.JOBS_FILE",
|
|
|
|
shared_datadir / "jobs.json"
|
|
|
|
)
|
2022-08-15 21:31:24 +00:00
|
|
|
return mock
|
2022-01-24 20:01:37 +00:00
|
|
|
|
2022-08-17 20:58:56 +00:00
|
|
|
|
2021-11-29 19:16:08 +00:00
|
|
|
@pytest.fixture
|
2022-08-10 23:36:36 +00:00
|
|
|
def huey_database(mocker, shared_datadir):
|
|
|
|
"""Mock huey database."""
|
|
|
|
mock = mocker.patch(
|
|
|
|
"selfprivacy_api.utils.huey.HUEY_DATABASE", shared_datadir / "huey.db"
|
2021-11-30 21:53:39 +00:00
|
|
|
)
|
2022-08-10 23:36:36 +00:00
|
|
|
return mock
|
2021-11-29 19:16:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
2022-08-15 21:31:24 +00:00
|
|
|
def client(tokens_file, huey_database, jobs_file):
|
2022-08-10 23:36:36 +00:00
|
|
|
from selfprivacy_api.app import app
|
2021-11-29 19:16:08 +00:00
|
|
|
|
2022-08-10 23:36:36 +00:00
|
|
|
return TestClient(app)
|
2022-01-10 20:35:00 +00:00
|
|
|
|
|
|
|
|
2021-11-29 19:16:08 +00:00
|
|
|
@pytest.fixture
|
2022-08-15 21:31:24 +00:00
|
|
|
def authorized_client(tokens_file, huey_database, jobs_file):
|
2022-07-05 12:54:21 +00:00
|
|
|
"""Authorized test client fixture."""
|
2022-08-10 23:36:36 +00:00
|
|
|
from selfprivacy_api.app import app
|
|
|
|
|
|
|
|
client = TestClient(app)
|
|
|
|
client.headers.update({"Authorization": "Bearer TEST_TOKEN"})
|
|
|
|
return client
|
2021-11-29 19:16:08 +00:00
|
|
|
|
2021-11-30 21:53:39 +00:00
|
|
|
|
2022-01-10 20:35:00 +00:00
|
|
|
@pytest.fixture
|
2022-08-15 21:31:24 +00:00
|
|
|
def wrong_auth_client(tokens_file, huey_database, jobs_file):
|
2022-07-05 12:54:21 +00:00
|
|
|
"""Wrong token test client fixture."""
|
2022-08-10 23:36:36 +00:00
|
|
|
from selfprivacy_api.app import app
|
2022-01-10 20:35:00 +00:00
|
|
|
|
2022-08-10 23:36:36 +00:00
|
|
|
client = TestClient(app)
|
|
|
|
client.headers.update({"Authorization": "Bearer WRONG_TOKEN"})
|
|
|
|
return client
|