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