mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2024-12-01 19:06:45 +00:00
Make Huey run immediately when testing
This commit is contained in:
parent
cd5ae80931
commit
c92294350f
|
@ -1,8 +1,14 @@
|
||||||
"""MiniHuey singleton."""
|
"""MiniHuey singleton."""
|
||||||
|
import os
|
||||||
from huey import SqliteHuey
|
from huey import SqliteHuey
|
||||||
|
|
||||||
HUEY_DATABASE = "/etc/nixos/userdata/tasks.db"
|
HUEY_DATABASE = "/etc/nixos/userdata/tasks.db"
|
||||||
|
|
||||||
# Singleton instance containing the huey database.
|
# Singleton instance containing the huey database.
|
||||||
|
|
||||||
huey = SqliteHuey(HUEY_DATABASE)
|
test_mode = os.environ.get("TEST_MODE")
|
||||||
|
|
||||||
|
huey = SqliteHuey(
|
||||||
|
HUEY_DATABASE,
|
||||||
|
immediate=test_mode == "true",
|
||||||
|
)
|
||||||
|
|
|
@ -1,10 +1,15 @@
|
||||||
"""Tests configuration."""
|
"""Tests configuration."""
|
||||||
# pylint: disable=redefined-outer-name
|
# pylint: disable=redefined-outer-name
|
||||||
# pylint: disable=unused-argument
|
# pylint: disable=unused-argument
|
||||||
|
import os
|
||||||
import pytest
|
import pytest
|
||||||
from fastapi.testclient import TestClient
|
from fastapi.testclient import TestClient
|
||||||
|
|
||||||
|
|
||||||
|
def pytest_generate_tests(metafunc):
|
||||||
|
os.environ["TEST_MODE"] = "true"
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def tokens_file(mocker, shared_datadir):
|
def tokens_file(mocker, shared_datadir):
|
||||||
"""Mock tokens file."""
|
"""Mock tokens file."""
|
||||||
|
@ -17,10 +22,7 @@ def tokens_file(mocker, shared_datadir):
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def jobs_file(mocker, shared_datadir):
|
def jobs_file(mocker, shared_datadir):
|
||||||
"""Mock tokens file."""
|
"""Mock tokens file."""
|
||||||
mock = mocker.patch(
|
mock = mocker.patch("selfprivacy_api.utils.JOBS_FILE", shared_datadir / "jobs.json")
|
||||||
"selfprivacy_api.utils.JOBS_FILE",
|
|
||||||
shared_datadir / "jobs.json"
|
|
||||||
)
|
|
||||||
return mock
|
return mock
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
# pylint: disable=redefined-outer-name
|
# pylint: disable=redefined-outer-name
|
||||||
# pylint: disable=unused-argument
|
# pylint: disable=unused-argument
|
||||||
import json
|
import json
|
||||||
|
import os
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from selfprivacy_api.utils import WriteUserData, ReadUserData
|
from selfprivacy_api.utils import WriteUserData, ReadUserData
|
||||||
|
@ -28,3 +29,12 @@ def test_write_invalid_user_data():
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError):
|
||||||
with WriteUserData("invalid") as user_data:
|
with WriteUserData("invalid") as user_data:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def test_mode():
|
||||||
|
return os.environ.get("TEST_MODE")
|
||||||
|
|
||||||
|
|
||||||
|
def test_the_test_mode(test_mode):
|
||||||
|
assert test_mode == "true"
|
||||||
|
|
Loading…
Reference in a new issue