1
|
import pytest
|
2
|
import sqlite3
|
3
|
import os
|
4
|
from sqlite3 import Connection, Cursor
|
5
|
|
6
|
from src.dao.certificate_repository import CertificateRepository
|
7
|
from src.dao.private_key_repository import PrivateKeyRepository
|
8
|
from src.services.certificate_service import CertificateService
|
9
|
from src.services.cryptography import CryptographyService
|
10
|
from src.services.key_service import KeyService
|
11
|
|
12
|
|
13
|
@pytest.fixture
|
14
|
def connection():
|
15
|
try:
|
16
|
os.remove("../../../test.sqlite")
|
17
|
except FileNotFoundError:
|
18
|
pass
|
19
|
connection: Connection = sqlite3.connect("../../../" + "test.sqlite")
|
20
|
return connection
|
21
|
|
22
|
|
23
|
@pytest.fixture
|
24
|
def cursor(connection):
|
25
|
cursor = connection.cursor()
|
26
|
|
27
|
# execute db initialisation script
|
28
|
with open('../../../SQLite_database.sql', 'r') as sql_file:
|
29
|
sql_script = sql_file.read()
|
30
|
cursor.executescript(sql_script)
|
31
|
|
32
|
# insert default values
|
33
|
with open('../../../SQLite_default_values.sql', 'r') as sql_file:
|
34
|
sql_script = sql_file.read()
|
35
|
cursor.executescript(sql_script)
|
36
|
|
37
|
return cursor
|
38
|
|
39
|
|
40
|
@pytest.fixture
|
41
|
def certificate_repository(connection, cursor):
|
42
|
return CertificateRepository(connection, cursor)
|
43
|
|
44
|
|
45
|
@pytest.fixture
|
46
|
def private_key_repository(connection, cursor):
|
47
|
return PrivateKeyRepository(connection, cursor)
|
48
|
|
49
|
|
50
|
@pytest.fixture
|
51
|
def cryptography_service():
|
52
|
return CryptographyService()
|
53
|
|
54
|
|
55
|
@pytest.fixture
|
56
|
def private_key_service(private_key_repository, cryptography_service):
|
57
|
return KeyService(cryptography_service, private_key_repository)
|
58
|
|
59
|
|
60
|
@pytest.fixture
|
61
|
def certificate_service(certificate_repository, cryptography_service):
|
62
|
return CertificateService(cryptography_service, certificate_repository)
|