-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
75 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# -*- coding: utf-8 -*- | ||
"""Defines fixtures available to all tests.""" | ||
# pylint: disable=redefined-outer-name | ||
import pytest | ||
from _pytest.monkeypatch import MonkeyPatch | ||
|
||
from fd_device.database.base import create_all_tables, drop_all_tables, get_session | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
# pylint: disable=unused-argument | ||
def monkeysession(request): | ||
"""Create a MonkeyPatch object that can be scoped to a session. | ||
https://github.com/pytest-dev/pytest/issues/363#issuecomment-289830794 | ||
""" | ||
mpatch = MonkeyPatch() | ||
yield mpatch | ||
mpatch.undo() | ||
|
||
|
||
@pytest.fixture(scope="session", autouse=True) | ||
def set_testing_env(monkeysession): | ||
"""Set the environment variable for testing. | ||
This executes once for the entire session of testing. | ||
The environment variables are set back to the default after. | ||
""" | ||
monkeysession.setenv("FD_DEVICE_CONFIG", "test") | ||
yield | ||
monkeysession.setenv("FD_DEVICE_CONFIG", "dev") | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def dbsession(): | ||
"""Returns an sqlalchemy session.""" | ||
yield get_session() | ||
|
||
|
||
@pytest.fixture() | ||
def tables(dbsession): | ||
"""Create all tables for testing. Delete when done.""" | ||
create_all_tables() | ||
yield | ||
dbsession.close() | ||
drop_all_tables() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
"""Test functional aspects of the app.""" | ||
|
||
from fd_device.settings import TestConfig, get_config | ||
|
||
|
||
def test_main_env(): | ||
"""Test that the main environment variable is set for testing.""" | ||
|
||
config = get_config() | ||
assert config == TestConfig |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# pylint: disable=unused-argument | ||
"""Test settings.""" | ||
from fd_device.settings import DevConfig, ProdConfig, TestConfig, get_config | ||
|
||
|
||
def test_retrieving_settings(): | ||
"""Test that the correct settings are retrieved.""" | ||
test_config = get_config(override_default="test") | ||
dev_config = get_config(override_default="dev") | ||
prod_config = get_config(override_default="prod") | ||
wrong_config = get_config(override_default="wrong") | ||
|
||
assert test_config == TestConfig | ||
assert dev_config == DevConfig | ||
assert prod_config == ProdConfig | ||
assert wrong_config == DevConfig |