Make Huey run immediately when testing

This commit is contained in:
inexcode 2022-08-20 22:47:32 +04:00
parent cd5ae80931
commit c92294350f
3 changed files with 23 additions and 5 deletions

View file

@ -1,8 +1,14 @@
"""MiniHuey singleton."""
import os
from huey import SqliteHuey
HUEY_DATABASE = "/etc/nixos/userdata/tasks.db"
# 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",
)

View file

@ -1,10 +1,15 @@
"""Tests configuration."""
# pylint: disable=redefined-outer-name
# pylint: disable=unused-argument
import os
import pytest
from fastapi.testclient import TestClient
def pytest_generate_tests(metafunc):
os.environ["TEST_MODE"] = "true"
@pytest.fixture
def tokens_file(mocker, shared_datadir):
"""Mock tokens file."""
@ -17,10 +22,7 @@ def tokens_file(mocker, shared_datadir):
@pytest.fixture
def jobs_file(mocker, shared_datadir):
"""Mock tokens file."""
mock = mocker.patch(
"selfprivacy_api.utils.JOBS_FILE",
shared_datadir / "jobs.json"
)
mock = mocker.patch("selfprivacy_api.utils.JOBS_FILE", shared_datadir / "jobs.json")
return mock

View file

@ -1,6 +1,7 @@
# pylint: disable=redefined-outer-name
# pylint: disable=unused-argument
import json
import os
import pytest
from selfprivacy_api.utils import WriteUserData, ReadUserData
@ -28,3 +29,12 @@ def test_write_invalid_user_data():
with pytest.raises(ValueError):
with WriteUserData("invalid") as user_data:
pass
@pytest.fixture
def test_mode():
return os.environ.get("TEST_MODE")
def test_the_test_mode(test_mode):
assert test_mode == "true"