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 |
20b33bd4
|
Jan Pašek
|
from src.config.configuration import test_configuration, Configuration
|
8 |
2bb3759c
|
Stanislav Král
|
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 |
7313994f
|
Stanislav Král
|
from src.services.crl.crl_service import CrlService
|
14 |
d3fa9147
|
Stanislav Král
|
from src.services.cryptography import CryptographyService
|
15 |
|
|
from src.services.key_service import KeyService
|
16 |
|
|
|
17 |
|
|
|
18 |
e39e138f
|
Stanislav Král
|
# scope="module" means that this fixture is run once per module
|
19 |
|
|
@pytest.fixture(scope="module")
|
20 |
d3fa9147
|
Stanislav Král
|
def connection():
|
21 |
2bb3759c
|
Stanislav Král
|
return ConnectionProvider().connect(test_configuration())
|
22 |
d3fa9147
|
Stanislav Král
|
|
23 |
|
|
|
24 |
e39e138f
|
Stanislav Král
|
# scope defaults to "function" which means that the fixture is run once per test (function)
|
25 |
d3fa9147
|
Stanislav Král
|
@pytest.fixture
|
26 |
2bb3759c
|
Stanislav Král
|
def certificate_repository(connection):
|
27 |
3195e946
|
Jan Pašek
|
return CertificateRepository(connection)
|
28 |
d3fa9147
|
Stanislav Král
|
|
29 |
|
|
|
30 |
|
|
@pytest.fixture
|
31 |
2bb3759c
|
Stanislav Král
|
def private_key_repository(connection):
|
32 |
3195e946
|
Jan Pašek
|
return PrivateKeyRepository(connection)
|
33 |
d3fa9147
|
Stanislav Král
|
|
34 |
|
|
|
35 |
|
|
@pytest.fixture
|
36 |
|
|
def cryptography_service():
|
37 |
|
|
return CryptographyService()
|
38 |
|
|
|
39 |
|
|
|
40 |
20b33bd4
|
Jan Pašek
|
@pytest.fixture
|
41 |
|
|
def configuration():
|
42 |
|
|
return Configuration()
|
43 |
|
|
|
44 |
|
|
|
45 |
d3fa9147
|
Stanislav Král
|
@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 |
20b33bd4
|
Jan Pašek
|
def certificate_service(certificate_repository, cryptography_service, configuration):
|
52 |
|
|
return CertificateService(cryptography_service, certificate_repository, configuration)
|
53 |
2a90f4fd
|
Stanislav Král
|
|
54 |
|
|
|
55 |
|
|
@pytest.fixture
|
56 |
|
|
def connection_unique():
|
57 |
2bb3759c
|
Stanislav Král
|
return ConnectionProvider().connect(test_configuration())
|
58 |
2a90f4fd
|
Stanislav Král
|
|
59 |
|
|
|
60 |
|
|
# scope defaults to "function" which means that the fixture is run once per test (function)
|
61 |
|
|
@pytest.fixture
|
62 |
2bb3759c
|
Stanislav Král
|
def certificate_repository_unique(connection_unique):
|
63 |
3195e946
|
Jan Pašek
|
return CertificateRepository(connection_unique)
|
64 |
2a90f4fd
|
Stanislav Král
|
|
65 |
|
|
|
66 |
|
|
@pytest.fixture
|
67 |
2bb3759c
|
Stanislav Král
|
def private_key_repository_unique(connection_unique):
|
68 |
3195e946
|
Jan Pašek
|
return PrivateKeyRepository(connection_unique)
|
69 |
2a90f4fd
|
Stanislav Král
|
|
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 |
20b33bd4
|
Jan Pašek
|
def certificate_service_unique(certificate_repository_unique, cryptography_service_unique, configuration):
|
83 |
|
|
return CertificateService(cryptography_service_unique, certificate_repository_unique, configuration)
|
84 |
7313994f
|
Stanislav Král
|
|
85 |
|
|
|
86 |
|
|
@pytest.fixture
|
87 |
|
|
def crl_service_unique(certificate_repository_unique, cryptography_service):
|
88 |
|
|
return CrlService(certificate_repository_unique, cryptography_service)
|