Revize f8581e41
Přidáno uživatelem Stanislav Král před asi 4 roky(ů)
tests/integration_tests/dao/conftest.py | ||
---|---|---|
2 | 2 |
import sqlite3 |
3 | 3 |
from sqlite3 import Connection, Cursor |
4 | 4 |
|
5 |
from src.config.configuration import test_configuration |
|
6 |
from src.config.connection_provider import ConnectionProvider |
|
5 | 7 |
from src.dao.certificate_repository import CertificateRepository |
6 | 8 |
from src.dao.private_key_repository import PrivateKeyRepository |
7 | 9 |
from src.db.init_queries import SCHEMA_SQL, DEFAULT_VALUES_SQL |
... | ... | |
10 | 12 |
# scope="module" means that this fixture is run once per module |
11 | 13 |
@pytest.fixture(scope="module") |
12 | 14 |
def connection(): |
13 |
print("Creating a new SQLITE connection to the test DB") |
|
14 |
connection: Connection = sqlite3.connect(':memory:') |
|
15 |
|
|
16 |
# yield the created connection |
|
17 |
yield connection |
|
15 |
return ConnectionProvider().connect(test_configuration()) |
|
18 | 16 |
|
19 | 17 |
|
20 | 18 |
@pytest.fixture(scope="module") |
21 | 19 |
def cursor(connection): |
22 |
cursor = connection.cursor() |
|
23 |
|
|
24 |
# execute db initialisation script |
|
25 |
cursor.executescript(SCHEMA_SQL) |
|
20 |
return connection.cursor() |
|
26 | 21 |
|
27 |
# insert default values |
|
28 |
cursor.executescript(DEFAULT_VALUES_SQL) |
|
29 |
|
|
30 |
return cursor |
|
31 | 22 |
|
32 | 23 |
@pytest.fixture |
33 | 24 |
def connection_unique(): |
34 |
print("Creating a new SQLITE connection to the test DB") |
|
35 |
connection: Connection = sqlite3.connect(':memory:') |
|
36 |
|
|
37 |
# yield the created connection |
|
38 |
yield connection |
|
25 |
return ConnectionProvider().connect(test_configuration()) |
|
39 | 26 |
|
40 | 27 |
|
41 | 28 |
@pytest.fixture |
42 | 29 |
def cursor_unique(connection): |
43 |
cursor = connection.cursor()
|
|
30 |
return connection.cursor()
|
|
44 | 31 |
|
45 |
# execute db initialisation script |
|
46 |
cursor.executescript(SCHEMA_SQL) |
|
47 |
|
|
48 |
# insert default values |
|
49 |
cursor.executescript(DEFAULT_VALUES_SQL) |
|
50 |
|
|
51 |
return cursor |
|
52 | 32 |
|
53 | 33 |
@pytest.fixture |
54 |
def certificate_repository(connection, cursor): |
|
55 |
return CertificateRepository(connection, cursor) |
|
34 |
def certificate_repository(connection): |
|
35 |
return CertificateRepository(connection) |
|
36 |
|
|
56 | 37 |
|
57 | 38 |
@pytest.fixture |
58 |
def private_key_repository(connection_unique, cursor_unique): |
|
59 |
return PrivateKeyRepository(connection_unique, cursor_unique) |
|
39 |
def private_key_repository_unique(connection_unique, cursor_unique): |
|
40 |
return PrivateKeyRepository(connection_unique) |
Také k dispozici: Unified diff
Fixed failing tests after performing a merge.