generated from department-of-general-services/python-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconftest.py
68 lines (53 loc) · 2.21 KB
/
conftest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import os
from pathlib import Path
import pytest
import sqlalchemy
from sqlalchemy.orm import Session
from dgs_fiscal.config import settings
from dgs_fiscal.systems.sharepoint import SharePoint
from dgs_fiscal.systems.core_integrator.driver import Driver
from dgs_fiscal.systems.citibuy import models
from tests.utils.populate_citibuy_db import populate_db
collect_ignore = ["integration_tests"]
@pytest.fixture(scope="session")
def test_config():
"""Returns the configuration settings for use in tests"""
test_settings = settings.from_env("testing")
return test_settings
@pytest.fixture(scope="session", name="test_sharepoint")
def fixture_test_sharepoint():
"""Creates an authenticated Graph API client for use in integration tests"""
return SharePoint()
@pytest.fixture(scope="session", name="test_archive_dir")
def fixture_archive_dir(tmp_path_factory):
"""Sets up a temporary archive directory for testing"""
basetemp = Path.cwd() / "archives" / "tests"
os.environ["PYTEST_DEBUG_TEMPROOT"] = str(basetemp)
basetemp.mkdir(parents=True, exist_ok=True)
archive_dir = tmp_path_factory.mktemp("archives", numbered=False)
return archive_dir
@pytest.fixture(scope="session", name="test_archive")
def fixture_archive(test_sharepoint, test_archive_dir):
"""Creates an instance of ArchiveFolder for use in integration tests"""
return test_sharepoint.get_archive_folder(test_archive_dir)
@pytest.fixture(scope="module", name="driver")
def fixture_driver(test_archive_dir):
"""Creates a webdriver for testing"""
download_dir = test_archive_dir / "core_integrator"
driver = Driver(download_dir)
yield driver
driver.quit()
@pytest.fixture(scope="session", name="mock_db")
def fixture_citibuy_db(test_archive_dir):
"""Creates a local version of the CitiBuy database for testing"""
db_path = test_archive_dir / "mock.db"
db_path.touch(exist_ok=True)
if os.name == "nt": # Checks if OS is Windows
conn_url = f"sqlite:///{db_path}"
else:
conn_url = f"sqlite:////{db_path}"
engine = sqlalchemy.create_engine(conn_url)
models.Base.metadata.create_all(engine)
with Session(engine) as session:
populate_db(session)
return conn_url