1
|
import pytest
|
2
|
import sqlite3
|
3
|
from sqlite3 import Connection, Cursor
|
4
|
|
5
|
from src.dao.certificate_repository import CertificateRepository
|
6
|
from src.dao.private_key_repository import PrivateKeyRepository
|
7
|
from src.db.init_queries import SCHEMA_SQL, DEFAULT_VALUES_SQL
|
8
|
|
9
|
|
10
|
# scope="module" means that this fixture is run once per module
|
11
|
@pytest.fixture(scope="module")
|
12
|
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
|
18
|
|
19
|
|
20
|
@pytest.fixture
|
21
|
def cursor(connection):
|
22
|
cursor = connection.cursor()
|
23
|
|
24
|
# execute db initialisation script
|
25
|
cursor.executescript(SCHEMA_SQL)
|
26
|
|
27
|
# insert default values
|
28
|
cursor.executescript(DEFAULT_VALUES_SQL)
|
29
|
|
30
|
return cursor
|
31
|
|
32
|
@pytest.fixture
|
33
|
def certificate_repository(connection, cursor):
|
34
|
return CertificateRepository(connection, cursor)
|
35
|
|
36
|
@pytest.fixture
|
37
|
def private_key_repository(connection, cursor):
|
38
|
return PrivateKeyRepository(connection, cursor)
|