aboutsummaryrefslogtreecommitdiff
path: root/tests/unit/conftest.py
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2023-08-04 10:10:28 +0300
committerFrederick Muriuki Muriithi2023-08-04 10:20:09 +0300
commit8b7c598407a5fea9a3d78473e72df87606998cd4 (patch)
tree8526433a17eca6b511feb082a0574f9b15cb9469 /tests/unit/conftest.py
parentf7fcbbcc014686ac597b783a8dcb38b43024b9d6 (diff)
downloadgn-auth-8b7c598407a5fea9a3d78473e72df87606998cd4.tar.gz
Copy over files from GN3 repository.
Diffstat (limited to 'tests/unit/conftest.py')
-rw-r--r--tests/unit/conftest.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/unit/conftest.py b/tests/unit/conftest.py
new file mode 100644
index 0000000..8005c8e
--- /dev/null
+++ b/tests/unit/conftest.py
@@ -0,0 +1,35 @@
+"""Fixtures for unit tests."""
+from pathlib import Path
+from datetime import datetime
+from tempfile import TemporaryDirectory
+
+import pytest
+
+from gn3.app import create_app
+
+@pytest.fixture(scope="session")
+def fxtr_app():
+ """Fixture: setup the test app"""
+ # Do some setup
+ with TemporaryDirectory() as testdir:
+ testdb = Path(testdir).joinpath(
+ f'testdb_{datetime.now().strftime("%Y%m%dT%H%M%S")}')
+ app = create_app({
+ "TESTING": True, "AUTH_DB": testdb,
+ "OAUTH2_ACCESS_TOKEN_GENERATOR": "tests.unit.auth.test_token.gen_token"
+ })
+ app.testing = True
+ yield app
+ # Clean up after ourselves
+ testdb.unlink(missing_ok=True)
+
+@pytest.fixture(scope="session")
+def client(fxtr_app): # pylint: disable=redefined-outer-name
+ """Create a test client fixture for tests"""
+ with fxtr_app.app_context():
+ yield fxtr_app.test_client()
+
+@pytest.fixture(scope="session")
+def fxtr_app_config(client): # pylint: disable=redefined-outer-name
+ """Return the test application's configuration object"""
+ return client.application.config