commit 2bb3759c87eddb0f7489a0413316ecf89de5a13e
Author: Stanislav Král <stanislav.kral3@gmail.com>
Date:   Sun Apr 11 16:15:14 2021 +0200

    Re #8579 - Changed conftest.py of service and DAO tests in such way that test_configuration is now used

diff --git a/tests/integration_tests/dao/certificate_repository/conftest.py b/tests/integration_tests/dao/certificate_repository/conftest.py
index e7c8235..a952b40 100644
--- a/tests/integration_tests/dao/certificate_repository/conftest.py
+++ b/tests/integration_tests/dao/certificate_repository/conftest.py
@@ -1,12 +1,10 @@
 import pytest
-import sqlite3
-from sqlite3 import Connection, Cursor
 
+from src.config.configuration import test_configuration
+from src.config.connection_provider import ConnectionProvider
 from src.dao.certificate_repository import CertificateRepository
-from src.constants import DATABASE_FILE
 
 
 @pytest.fixture
 def repository():
-    connection: Connection = sqlite3.connect(DATABASE_FILE)
-    return CertificateRepository(connection)
+    return CertificateRepository(ConnectionProvider().connect(test_configuration()))
diff --git a/tests/integration_tests/services/conftest.py b/tests/integration_tests/services/conftest.py
index 158a05e..c448b75 100644
--- a/tests/integration_tests/services/conftest.py
+++ b/tests/integration_tests/services/conftest.py
@@ -4,6 +4,8 @@ from sqlite3 import Connection
 
 import pytest
 
+from src.config.configuration import test_configuration
+from src.config.connection_provider import ConnectionProvider
 from src.dao.certificate_repository import CertificateRepository
 from src.dao.private_key_repository import PrivateKeyRepository
 from src.db.init_queries import SCHEMA_SQL, DEFAULT_VALUES_SQL
@@ -15,43 +17,17 @@ from src.services.key_service import KeyService
 # scope="module" means that this fixture is run once per module
 @pytest.fixture(scope="module")
 def connection():
-    print("Creating a new SQLITE connection to the test DB")
-    test_db_file = "test.sqlite"
-    connection: Connection = sqlite3.connect(test_db_file)
-
-    # yield the created connection
-    yield connection
-
-    # after tests have finished delete the created db file
-    try:
-        print("Deleting the test DB")
-        os.unlink(test_db_file)
-    except FileNotFoundError:
-        print(f"Could not delete {test_db_file} file containing the test DB")
-        pass
-
-
-@pytest.fixture(scope="module")
-def cursor(connection):
-    cursor = connection.cursor()
-
-    # execute db initialisation script
-    cursor.executescript(SCHEMA_SQL)
-
-    # insert default values
-    cursor.executescript(DEFAULT_VALUES_SQL)
-
-    return cursor
+    return ConnectionProvider().connect(test_configuration())
 
 
 # scope defaults to "function" which means that the fixture is run once per test (function)
 @pytest.fixture
-def certificate_repository(connection, cursor):
+def certificate_repository(connection):
     return CertificateRepository(connection)
 
 
 @pytest.fixture
-def private_key_repository(connection, cursor):
+def private_key_repository(connection):
     return PrivateKeyRepository(connection)
 
 
@@ -70,46 +46,19 @@ def certificate_service(certificate_repository, cryptography_service):
     return CertificateService(cryptography_service, certificate_repository)
 
 
-# TODO improve this (lots of duplicated code) - some test cases need a DB connection that is not shared with other tests
 @pytest.fixture
 def connection_unique():
-    print("Creating a new unique SQLITE connection to the test DB")
-    test_db_file = "test_unique.sqlite"
-    connection: Connection = sqlite3.connect(test_db_file)
-
-    # yield the created connection
-    yield connection
-
-    # after tests have finished delete the created db file
-    try:
-        print("Deleting the unique test DB")
-        os.unlink(test_db_file)
-    except FileNotFoundError:
-        print(f"Could not delete {test_db_file} file containing the unique test DB")
-        pass
-
-
-@pytest.fixture
-def cursor_unique(connection_unique):
-    cursor = connection_unique.cursor()
-
-    # execute db initialisation script
-    cursor.executescript(SCHEMA_SQL)
-
-    # insert default values
-    cursor.executescript(DEFAULT_VALUES_SQL)
-
-    return cursor
+    return ConnectionProvider().connect(test_configuration())
 
 
 # scope defaults to "function" which means that the fixture is run once per test (function)
 @pytest.fixture
-def certificate_repository_unique(connection_unique, cursor_unique):
+def certificate_repository_unique(connection_unique):
     return CertificateRepository(connection_unique)
 
 
 @pytest.fixture
-def private_key_repository_unique(connection_unique, cursor_unique):
+def private_key_repository_unique(connection_unique):
     return PrivateKeyRepository(connection_unique)
 
 
