Revize 2a90f4fd
Přidáno uživatelem Stanislav Král před asi 4 roky(ů)
tests/integration_tests/services/conftest.py | ||
---|---|---|
68 | 68 |
@pytest.fixture |
69 | 69 |
def certificate_service(certificate_repository, cryptography_service): |
70 | 70 |
return CertificateService(cryptography_service, certificate_repository) |
71 |
|
|
72 |
|
|
73 |
# TODO improve this (lots of duplicated code) - some test cases need a DB connection that is not shared with other tests |
|
74 |
@pytest.fixture |
|
75 |
def connection_unique(): |
|
76 |
print("Creating a new unique SQLITE connection to the test DB") |
|
77 |
test_db_file = "test_unique.sqlite" |
|
78 |
connection: Connection = sqlite3.connect(test_db_file) |
|
79 |
|
|
80 |
# yield the created connection |
|
81 |
yield connection |
|
82 |
|
|
83 |
# after tests have finished delete the created db file |
|
84 |
try: |
|
85 |
print("Deleting the unique test DB") |
|
86 |
os.unlink(test_db_file) |
|
87 |
except FileNotFoundError: |
|
88 |
print(f"Could not delete {test_db_file} file containing the unique test DB") |
|
89 |
pass |
|
90 |
|
|
91 |
|
|
92 |
@pytest.fixture |
|
93 |
def cursor_unique(connection_unique): |
|
94 |
cursor = connection_unique.cursor() |
|
95 |
|
|
96 |
# execute db initialisation script |
|
97 |
cursor.executescript(SCHEMA_SQL) |
|
98 |
|
|
99 |
# insert default values |
|
100 |
cursor.executescript(DEFAULT_VALUES_SQL) |
|
101 |
|
|
102 |
return cursor |
|
103 |
|
|
104 |
|
|
105 |
# scope defaults to "function" which means that the fixture is run once per test (function) |
|
106 |
@pytest.fixture |
|
107 |
def certificate_repository_unique(connection_unique, cursor_unique): |
|
108 |
return CertificateRepository(connection_unique, cursor_unique) |
|
109 |
|
|
110 |
|
|
111 |
@pytest.fixture |
|
112 |
def private_key_repository_unique(connection_unique, cursor_unique): |
|
113 |
return PrivateKeyRepository(connection_unique, cursor_unique) |
|
114 |
|
|
115 |
|
|
116 |
@pytest.fixture |
|
117 |
def cryptography_service_unique(): |
|
118 |
return CryptographyService() |
|
119 |
|
|
120 |
|
|
121 |
@pytest.fixture |
|
122 |
def private_key_service_unique(private_key_repository_unique, cryptography_service_unique): |
|
123 |
return KeyService(cryptography_service_unique, private_key_repository_unique) |
|
124 |
|
|
125 |
|
|
126 |
@pytest.fixture |
|
127 |
def certificate_service_unique(certificate_repository_unique, cryptography_service_unique): |
|
128 |
return CertificateService(cryptography_service_unique, certificate_repository_unique) |
Také k dispozici: Unified diff
Re #8472 - Implemented get_certificates method and added an integration test validating it
Added fixtures providing a unique DB connection for each test