1
|
import os
|
2
|
import sqlite3
|
3
|
from sqlite3 import Connection
|
4
|
|
5
|
import pytest
|
6
|
|
7
|
from src.config.configuration import test_configuration, Configuration
|
8
|
from src.config.connection_provider import ConnectionProvider
|
9
|
from src.dao.certificate_repository import CertificateRepository
|
10
|
from src.dao.private_key_repository import PrivateKeyRepository
|
11
|
from src.db.init_queries import SCHEMA_SQL, DEFAULT_VALUES_SQL
|
12
|
from src.services.certificate_service import CertificateService
|
13
|
from src.services.crl.crl_service import CrlService
|
14
|
from src.services.cryptography import CryptographyService
|
15
|
from src.services.key_service import KeyService
|
16
|
|
17
|
|
18
|
# scope="module" means that this fixture is run once per module
|
19
|
@pytest.fixture(scope="module")
|
20
|
def connection():
|
21
|
return ConnectionProvider().connect(test_configuration())
|
22
|
|
23
|
|
24
|
# scope defaults to "function" which means that the fixture is run once per test (function)
|
25
|
@pytest.fixture
|
26
|
def certificate_repository(connection):
|
27
|
return CertificateRepository(connection)
|
28
|
|
29
|
|
30
|
@pytest.fixture
|
31
|
def private_key_repository(connection):
|
32
|
return PrivateKeyRepository(connection)
|
33
|
|
34
|
|
35
|
@pytest.fixture
|
36
|
def cryptography_service():
|
37
|
return CryptographyService()
|
38
|
|
39
|
|
40
|
@pytest.fixture
|
41
|
def configuration():
|
42
|
return Configuration()
|
43
|
|
44
|
|
45
|
@pytest.fixture
|
46
|
def private_key_service(private_key_repository, cryptography_service):
|
47
|
return KeyService(cryptography_service, private_key_repository)
|
48
|
|
49
|
|
50
|
@pytest.fixture
|
51
|
def certificate_service(certificate_repository, cryptography_service, configuration):
|
52
|
return CertificateService(cryptography_service, certificate_repository, configuration)
|
53
|
|
54
|
|
55
|
@pytest.fixture
|
56
|
def connection_unique():
|
57
|
return ConnectionProvider().connect(test_configuration())
|
58
|
|
59
|
|
60
|
# scope defaults to "function" which means that the fixture is run once per test (function)
|
61
|
@pytest.fixture
|
62
|
def certificate_repository_unique(connection_unique):
|
63
|
return CertificateRepository(connection_unique)
|
64
|
|
65
|
|
66
|
@pytest.fixture
|
67
|
def private_key_repository_unique(connection_unique):
|
68
|
return PrivateKeyRepository(connection_unique)
|
69
|
|
70
|
|
71
|
@pytest.fixture
|
72
|
def cryptography_service_unique():
|
73
|
return CryptographyService()
|
74
|
|
75
|
|
76
|
@pytest.fixture
|
77
|
def private_key_service_unique(private_key_repository_unique, cryptography_service_unique):
|
78
|
return KeyService(cryptography_service_unique, private_key_repository_unique)
|
79
|
|
80
|
|
81
|
@pytest.fixture
|
82
|
def certificate_service_unique(certificate_repository_unique, cryptography_service_unique, configuration):
|
83
|
return CertificateService(cryptography_service_unique, certificate_repository_unique, configuration)
|
84
|
|
85
|
|
86
|
@pytest.fixture
|
87
|
def crl_service_unique(certificate_repository_unique, cryptography_service):
|
88
|
return CrlService(certificate_repository_unique, cryptography_service)
|