Projekt

Obecné

Profil

Stáhnout (2.86 KB) Statistiky
| Větev: | Tag: | Revize:
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 b484b79b Stanislav Král
from src.model.subject import Subject
12 d3fa9147 Stanislav Král
from src.services.certificate_service import CertificateService
13 5cd65ab4 Captain_Trojan
from src.services.crl_ocsp.crl_ocsp_service import CrlOcspService
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 b484b79b Stanislav Král
@pytest.fixture
61
def sample_private_key(private_key_service):
62
    return private_key_service.create_new_key()
63
64
65
@pytest.fixture
66
def sample_certificate(certificate_service, sample_private_key):
67
    return certificate_service.create_root_ca(sample_private_key, Subject("Foo"))
68
69
70 2a90f4fd Stanislav Král
# scope defaults to "function" which means that the fixture is run once per test (function)
71
@pytest.fixture
72 2bb3759c Stanislav Král
def certificate_repository_unique(connection_unique):
73 3195e946 Jan Pašek
    return CertificateRepository(connection_unique)
74 2a90f4fd Stanislav Král
75
76
@pytest.fixture
77 2bb3759c Stanislav Král
def private_key_repository_unique(connection_unique):
78 3195e946 Jan Pašek
    return PrivateKeyRepository(connection_unique)
79 2a90f4fd Stanislav Král
80
81
@pytest.fixture
82 9896ec36 Stanislav Král
def private_key_service_unique(private_key_repository_unique, cryptography_service):
83
    return KeyService(cryptography_service, private_key_repository_unique)
84 2a90f4fd Stanislav Král
85
86
@pytest.fixture
87 9896ec36 Stanislav Král
def certificate_service_unique(certificate_repository_unique, cryptography_service, configuration):
88
    return CertificateService(cryptography_service, certificate_repository_unique, configuration)
89 7313994f Stanislav Král
90
91
@pytest.fixture
92 94e89bb1 Jan Pašek
def crl_service_unique(certificate_repository_unique, private_key_repository_unique, cryptography_service):
93 5cd65ab4 Captain_Trojan
    return CrlOcspService(certificate_repository_unique, private_key_repository_unique, cryptography_service)