commit 8ceb3f795f298ea35080cc9a893350a7767b743e
Author: Jan Pašek <janpasek97@gmail.com>
Date:   Wed Apr 7 11:48:55 2021 +0200

    Re #8476 - Changed structure of tests
    - Renamed DAO integration tests so that they are found by pytest
    - Moved RestAPI tests from UnitTests to IntegrationTests

diff --git a/tests/integration_tests/dao/certificate_repository/conftest.py b/tests/integration_tests/dao/certificate_repository/conftest.py
index 1c6c3ec..45e2561 100644
--- a/tests/integration_tests/dao/certificate_repository/conftest.py
+++ b/tests/integration_tests/dao/certificate_repository/conftest.py
@@ -8,6 +8,6 @@ from src.constants import DATABASE_FILE
 
 @pytest.fixture
 def repository():
-    connection: Connection = sqlite3.connect("../../../" + DATABASE_FILE)
+    connection: Connection = sqlite3.connect(DATABASE_FILE)
     cursor: Cursor = connection.cursor()
     return CertificateRepository(connection, cursor)
diff --git a/tests/integration_tests/dao/certificate_repository/create_certificate.py b/tests/integration_tests/dao/certificate_repository/create_certificate.py
deleted file mode 100644
index a2264f6..0000000
--- a/tests/integration_tests/dao/certificate_repository/create_certificate.py
+++ /dev/null
@@ -1,13 +0,0 @@
-import pytest
-from src.constants import *
-
-
-def test_connection(repository):
-    sql = f"SELECT * FROM {TAB_CERTIFICATE_TYPES}"
-    repository.cursor.execute(sql)
-    selected_rows = repository.cursor.fetchall()
-
-    assert len(selected_rows) > 1
-    assert selected_rows[ROOT_CA_ID - 1][1] == "ROOT_CA"
-    assert selected_rows[INTERMEDIATE_CA_ID - 1][1] == "INTERMEDIATE_CA"
-    assert selected_rows[CERTIFICATE_ID - 1][1] == "CERTIFICATE"
diff --git a/tests/integration_tests/dao/certificate_repository/create_certificate_test.py b/tests/integration_tests/dao/certificate_repository/create_certificate_test.py
new file mode 100644
index 0000000..a2264f6
--- /dev/null
+++ b/tests/integration_tests/dao/certificate_repository/create_certificate_test.py
@@ -0,0 +1,13 @@
+import pytest
+from src.constants import *
+
+
+def test_connection(repository):
+    sql = f"SELECT * FROM {TAB_CERTIFICATE_TYPES}"
+    repository.cursor.execute(sql)
+    selected_rows = repository.cursor.fetchall()
+
+    assert len(selected_rows) > 1
+    assert selected_rows[ROOT_CA_ID - 1][1] == "ROOT_CA"
+    assert selected_rows[INTERMEDIATE_CA_ID - 1][1] == "INTERMEDIATE_CA"
+    assert selected_rows[CERTIFICATE_ID - 1][1] == "CERTIFICATE"
diff --git a/tests/integration_tests/rest_api/__init__.py b/tests/integration_tests/rest_api/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/tests/integration_tests/rest_api/certificates_test.py b/tests/integration_tests/rest_api/certificates_test.py
new file mode 100644
index 0000000..ce2c34d
--- /dev/null
+++ b/tests/integration_tests/rest_api/certificates_test.py
@@ -0,0 +1,534 @@
+# structure:
+# 1->10
+# 2->3->4->5->6->7
+# 2->8->9
+
+
+def make_root_ca(server, title="Root CA s.r.o."):
+    return server.post("/api/certificates", content_type="application/json", json={
+        "subject": {
+            "C": "CZ",
+            "CN": title,
+            "L": "Pilsen",
+            "O": title,
+            "OU": "IT department",
+            "ST": "Pilsen Region",
+            "emailAddress": "root@ca.com"
+        },
+        "usage": {
+            "CA": True,
+            "SSL": True,
+            "authentication": True,
+            "digitalSignature": True
+        },
+        "validityDays": 30
+    })
+
+
+def make_inter_ca(server, parent, title="Intermediate CA s.r.o."):
+    return server.post("/api/certificates", content_type="application/json", json={
+        "CA": parent,
+        "subject": {
+            "C": "CZ",
+            "CN": title,
+            "L": "Pilsen",
+            "O": title,
+            "OU": "IT department",
+            "ST": "Pilsen Region",
+            "emailAddress": "inter@ca.com"
+        },
+        "usage": {
+            "CA": True,
+            "SSL": True,
+            "authentication": True,
+            "digitalSignature": True
+        },
+        "validityDays": 30
+    })
+
+
+def make_end_cert(server, parent, title="End certificate s.r.o.", usage=None):
+    if usage is None:
+        usage = {
+            "CA": False,
+            "SSL": True,
+            "authentication": True,
+            "digitalSignature": True
+        }
+
+    return server.post("/api/certificates", content_type="application/json", json={
+        "CA": parent,
+        "subject": {
+            "C": "CZ",
+            "CN": title,
+            "L": "Pilsen",
+            "O": title,
+            "OU": "IT department",
+            "ST": "Pilsen Region",
+            "emailAddress": "end@ca.com"
+        },
+        "usage": usage,
+        "validityDays": 30
+    })
+
+
+def test_import(server):
+    assert 1 + 2 + 3 + 4 != -1 / 12
+
+    ret = server.get("/")
+    assert ret.status_code == 200
+    assert str(ret.data, encoding='utf-8') == "Welcome to the X.509 management application homepage!"
+
+
+def test_root_ca(server):
+    ret = make_root_ca(server)
+
+    assert ret.status_code == 201
+
+    d = ret.json
+
+    assert "data" in d
+    assert d["data"] == 1
+    assert "success" in d
+    assert d["success"]
+
+
+def test_invalid_params_1(server):
+    ret = server.post("/api/certificates", content_type="application/json", json={
+        "subject": {
+            "C": "CZ",
+            "CN": "Root CA s.r.o.",
+            "L": "Pilsen",
+            "O": "Root CA s.r.o.",
+            "OU": "IT department",
+            "ST": "Pilsen Region",
+            "emailAddress": "root@ca.com"
+        },
+        "validityDays": 30
+    })
+
+    assert ret.status_code == 400
+
+    d = ret.json
+
+    assert "data" in d
+    assert d["data"] == "Invalid request, missing parameters."
+    assert "success" in d
+    assert not d["success"]
+
+
+def test_invalid_params_2(server):
+    ret = server.post("/api/certificates", content_type="application/json", json={
+        "subject": {
+            "C": "CZ",
+            "CN": "Root CA s.r.o.",
+            "L": "Pilsen",
+            "O": "Root CA s.r.o.",
+            "OU": "IT department",
+            "ST": "Pilsen Region",
+            "emailAddress": "root@ca.com"
+        },
+        "usage": {
+            "CA": True,
+            "SSL": True,
+            "authentication": True,
+            "digitalSignature": True
+        },
+        "validityDays": "tak mesic treba plus minus"
+    })
+
+    assert ret.status_code == 400
+
+    d = ret.json
+
+    assert "data" in d
+    assert d["data"] == "Invalid request, wrong parameters."
+    assert "success" in d
+    assert not d["success"]
+
+
+def test_invalid_params_3(server):
+    ret = server.post("/api/certificates", content_type="application/json", json={
+        "subject": {
+            "C": "CZ",
+            "CN": "Root CA s.r.o.",
+            "L": "Pilsen",
+            "O": "Root CA s.r.o.",
+            "OU": "IT department",
+            "ST": ["Bosna", "Herzegovina"],
+            "emailAddress": "root@ca.com"
+        },
+        "usage": {
+            "CA": True,
+            "SSL": True,
+            "authentication": True,
+            "digitalSignature": True
+        },
+        "validityDays": 30
+    })
+
+    assert ret.status_code == 400
+
+    d = ret.json
+
+    assert "data" in d
+    assert d["data"] == "Invalid request, wrong parameters."
+    assert "success" in d
+    assert not d["success"]
+
+
+def test_invalid_params_4(server):
+    ret = server.post("/api/certificates", content_type="application/json", json={
+        "CA": 80081358008135,
+        "subject": {
+            "C": "CZ",
+            "CN": "Root CA s.r.o.",
+            "L": "Pilsen",
+            "O": "Root CA s.r.o.",
+            "OU": "IT department",
+            "ST": "Pilsen",
+            "emailAddress": "root@ca.com"
+        },
+        "usage": {
+            "CA": True,
+            "SSL": True,
+            "authentication": True,
+            "digitalSignature": True
+        },
+        "validityDays": 30
+    })
+
+    assert ret.status_code == 400
+
+    d = ret.json
+
+    assert "data" in d
+    assert d["data"] == "No certificate authority with such unique ID exists."
+    assert "success" in d
+    assert not d["success"]
+
+
+def test_create_chain(server):
+    ret = make_root_ca(server, "Another Root CA s.r.o.")
+
+    assert ret.status_code == 201
+
+    d = ret.json
+
+    assert "data" in d
+    assert d["data"] == 2
+    assert "success" in d
+    assert d["success"]
+
+    ret = make_inter_ca(server, 2)
+
+    assert ret.status_code == 201
+
+    d = ret.json
+
+    assert "data" in d
+    assert d["data"] == 3
+    assert "success" in d
+    assert d["success"]
+
+    ret = make_inter_ca(server, 3)
+
+    assert ret.status_code == 201
+
+    d = ret.json
+
+    assert "data" in d
+    assert d["data"] == 4
+    assert "success" in d
+    assert d["success"]
+
+    ret = make_inter_ca(server, 4)
+
+    assert ret.status_code == 201
+
+    d = ret.json
+
+    assert "data" in d
+    assert d["data"] == 5
+    assert "success" in d
+    assert d["success"]
+
+    ret = make_inter_ca(server, 5)
+
+    assert ret.status_code == 201
+
+    d = ret.json
+
+    assert "data" in d
+    assert d["data"] == 6
+    assert "success" in d
+    assert d["success"]
+
+    ret = make_end_cert(server, 6)
+
+    assert ret.status_code == 201
+
+    d = ret.json
+
+    assert "data" in d
+    assert d["data"] == 7
+    assert "success" in d
+    assert d["success"]
+
+
+def test_list_of_certificates(server):
+    ret = server.get("/api/certificates")
+
+    assert ret.status_code == 200
+
+    usage_dict = {'CA': True, 'SSL': True, 'authentication': True, 'digitalSignature': True}
+    s1 = "Root CA s.r.o."
+    s2 = "Another Root CA s.r.o."
+    s3 = "Intermediate CA s.r.o."
+
+    assert "data" in ret.json
+    assert "success" in ret.json
+    assert ret.json["success"]
+
+    d = ret.json["data"]
+
+    # print(d)
+
+    assert d[0]['CN'] == s1
+    assert d[1]['CN'] == s2
+    assert d[2]['CN'] == s3
+
+    assert all(d[i]['id'] == i + 1 for i in range(3))
+    assert all(d[i]['usage'] == usage_dict for i in range(3))
+
+    assert d[0]['issuer']['CN'] == s1
+    assert d[1]['issuer']['CN'] == s2
+    assert d[2]['issuer']['CN'] == s2
+
+    assert d[0]['issuer']['id'] == 1
+    assert d[1]['issuer']['id'] == 2
+    assert d[2]['issuer']['id'] == 2
+
+
+def test_sign_by_non_ca(server):
+    ret = make_end_cert(server, 2, "Fake intermediate cert s.r.o.", usage={
+            "CA": False,
+            "SSL": True,
+            "authentication": True,
+            "digitalSignature": True
+        })
+
+    assert ret.status_code == 201
+
+    d = ret.json
+
+    assert "data" in d
+    assert d["data"] == 8
+    assert "success" in d
+    assert d["success"]
+
+    ret = make_end_cert(server, 8, "End certificate signed by end certificate s.r.o.", usage={
+            "CA": False,
+            "SSL": True,
+            "authentication": False,
+            "digitalSignature": False
+        })
+
+    # TODO discussion -> assert ret.status_code == 400
+    assert ret.status_code == 201
+
+    d = ret.json
+
+    assert "data" in d
+    assert d["data"] == 9
+    assert "success" in d
+    assert d["success"]
+
+
+def test_filtering(server):
+    ret = server.get("/api/certificates", json={"filtering": {"CA": True}})
+
+    assert ret.status_code == 200
+
+    assert "data" in ret.json
+    assert "success" in ret.json
+    assert ret.json["success"]
+
+    d = ret.json["data"]
+
+    assert all(c["usage"]["CA"] for c in d)
+
+    all_certs_expected = list(d)
+
+    ret = server.get("/api/certificates", json={"filtering": {"CA": False}})
+
+    assert ret.status_code == 200
+
+    assert "data" in ret.json
+    assert "success" in ret.json
+    assert ret.json["success"]
+
+    d = ret.json["data"]
+
+    assert all(not c["usage"]["CA"] for c in d)
+
+    for v in d:
+        all_certs_expected.append(v)
+
+    ret = server.get("/api/certificates")
+
+    assert ret.status_code == 200
+
+    assert "data" in ret.json
+    assert "success" in ret.json
+    assert ret.json["success"]
+
+    all_certs_actual = ret.json["data"]
+
+    assert len(all_certs_actual) == len(all_certs_expected)
+    # TODO assert set(all_certs_expected) == set(all_certs_actual) or something like that instead
+
+
+def test_get_one(server):
+    ret = server.get("/api/certificates/1")
+
+    assert ret.status_code == 200
+
+    assert "data" in ret.json
+    assert "success" in ret.json
+    assert ret.json["success"]
+
+    d = ret.json["data"]
+
+    assert str(d).startswith("-----BEGIN CERTIFICATE-----")
+
+
+def test_get_one_bad_param(server):
+    ret = server.get("/api/certificates/whoopsie")
+
+    assert ret.status_code == 400
+    assert "data" in ret.json
+    assert "success" in ret.json
+    assert not ret.json["success"]
+    assert ret.json["data"] == "Invalid request, wrong parameters."
+
+
+def test_get_one_bad_param_2(server):
+    ret = server.get("/api/certificates/805")
+
+    assert ret.status_code == 205
+    assert "data" in ret.json
+    assert "success" in ret.json
+    assert not ret.json["success"]
+    assert ret.json["data"] == "No such certificate found."
+
+
+def test_get_detes(server):
+    original = {
+        "CA": 1,
+        "subject": {
+            "C": "CZ",
+            "CN": "Good boy end cert s.r.o.",
+            "L": "Pilsen",
+            "O": "This is most likely a good s.r.o.",
+            "OU": "IT department",
+            "ST": "Pilsen Region",
+            "emailAddress": "end@ca.com"
+        },
+        "usage": {
+            "CA": False,
+            "SSL": True,
+            "authentication": False,
+            "digitalSignature": True
+        },
+        "validityDays": 30
+    }
+    ret = server.post("/api/certificates", content_type="application/json", json=original)
+
+    assert ret.status_code == 201
+
+    assert "data" in ret.json
+    assert "success" in ret.json
+    assert ret.json["success"]
+
+    d = ret.json
+
+    assert d["data"] == 10
+
+    id = d["data"]
+
+    ret = server.get(f"/api/certificates/{id}/details")
+
+    assert ret.status_code == 200
+
+    assert "data" in ret.json
+    assert "success" in ret.json
+    assert ret.json["success"]
+
+    d = ret.json
+
+    new = d["data"]
+
+    assert original["CA"] == new["CA"]
+    assert original["subject"] == new["subject"]
+    assert original["usage"] == new["usage"]
+
+
+def test_get_root(server):
+    ret = server.get("/api/certificates/2")
+
+    assert ret.status_code == 200
+
+    assert "data" in ret.json
+    assert "success" in ret.json
+    assert ret.json["success"]
+
+    original = ret.json["data"]
+
+    ret = server.get("/api/certificates/4/root")
+
+    assert ret.status_code == 200
+
+    assert "data" in ret.json
+    assert "success" in ret.json
+    assert ret.json["success"]
+
+    new = ret.json["data"]
+
+    assert original == new
+
+
+def test_get_root_invalid(server):
+    ret = server.get("/api/certificates/805/root")
+
+    assert ret.status_code == 205
+    assert "data" in ret.json
+    assert "success" in ret.json
+    assert not ret.json["success"]
+    assert ret.json["data"] == "No such certificate found."
+
+
+def test_chain_of_trust(server):
+    expected = []
+    for i in range(6, 2, -1):
+        ret = server.get(f"/api/certificates/{i}")
+
+        assert ret.status_code == 200
+
+        assert "data" in ret.json
+        assert "success" in ret.json
+        assert ret.json["success"]
+
+        d = ret.json["data"]
+        expected.append(d)
+
+    ret = server.get(f"/api/certificates/7/chain")
+    assert ret.status_code == 200
+
+    assert "data" in ret.json
+    assert "success" in ret.json
+    assert ret.json["success"]
+
+    actual = ret.json["data"]
+
+    assert "".join(expected) == actual
\ No newline at end of file
diff --git a/tests/integration_tests/rest_api/conftest.py b/tests/integration_tests/rest_api/conftest.py
new file mode 100644
index 0000000..dc168d4
--- /dev/null
+++ b/tests/integration_tests/rest_api/conftest.py
@@ -0,0 +1,11 @@
+import pytest
+from app import app as flask_app
+from src.db.setup_database import setup_database
+
+
+@pytest.fixture(scope="session")
+def server():
+    setup_database()
+    flask_app.testing = True
+    with flask_app.test_client() as s:
+        yield s
diff --git a/tests/unit_tests/rest_api/__init__.py b/tests/unit_tests/rest_api/__init__.py
deleted file mode 100644
index e69de29..0000000
diff --git a/tests/unit_tests/rest_api/certificates.py b/tests/unit_tests/rest_api/certificates.py
deleted file mode 100644
index ce2c34d..0000000
--- a/tests/unit_tests/rest_api/certificates.py
+++ /dev/null
@@ -1,534 +0,0 @@
-# structure:
-# 1->10
-# 2->3->4->5->6->7
-# 2->8->9
-
-
-def make_root_ca(server, title="Root CA s.r.o."):
-    return server.post("/api/certificates", content_type="application/json", json={
-        "subject": {
-            "C": "CZ",
-            "CN": title,
-            "L": "Pilsen",
-            "O": title,
-            "OU": "IT department",
-            "ST": "Pilsen Region",
-            "emailAddress": "root@ca.com"
-        },
-        "usage": {
-            "CA": True,
-            "SSL": True,
-            "authentication": True,
-            "digitalSignature": True
-        },
-        "validityDays": 30
-    })
-
-
-def make_inter_ca(server, parent, title="Intermediate CA s.r.o."):
-    return server.post("/api/certificates", content_type="application/json", json={
-        "CA": parent,
-        "subject": {
-            "C": "CZ",
-            "CN": title,
-            "L": "Pilsen",
-            "O": title,
-            "OU": "IT department",
-            "ST": "Pilsen Region",
-            "emailAddress": "inter@ca.com"
-        },
-        "usage": {
-            "CA": True,
-            "SSL": True,
-            "authentication": True,
-            "digitalSignature": True
-        },
-        "validityDays": 30
-    })
-
-
-def make_end_cert(server, parent, title="End certificate s.r.o.", usage=None):
-    if usage is None:
-        usage = {
-            "CA": False,
-            "SSL": True,
-            "authentication": True,
-            "digitalSignature": True
-        }
-
-    return server.post("/api/certificates", content_type="application/json", json={
-        "CA": parent,
-        "subject": {
-            "C": "CZ",
-            "CN": title,
-            "L": "Pilsen",
-            "O": title,
-            "OU": "IT department",
-            "ST": "Pilsen Region",
-            "emailAddress": "end@ca.com"
-        },
-        "usage": usage,
-        "validityDays": 30
-    })
-
-
-def test_import(server):
-    assert 1 + 2 + 3 + 4 != -1 / 12
-
-    ret = server.get("/")
-    assert ret.status_code == 200
-    assert str(ret.data, encoding='utf-8') == "Welcome to the X.509 management application homepage!"
-
-
-def test_root_ca(server):
-    ret = make_root_ca(server)
-
-    assert ret.status_code == 201
-
-    d = ret.json
-
-    assert "data" in d
-    assert d["data"] == 1
-    assert "success" in d
-    assert d["success"]
-
-
-def test_invalid_params_1(server):
-    ret = server.post("/api/certificates", content_type="application/json", json={
-        "subject": {
-            "C": "CZ",
-            "CN": "Root CA s.r.o.",
-            "L": "Pilsen",
-            "O": "Root CA s.r.o.",
-            "OU": "IT department",
-            "ST": "Pilsen Region",
-            "emailAddress": "root@ca.com"
-        },
-        "validityDays": 30
-    })
-
-    assert ret.status_code == 400
-
-    d = ret.json
-
-    assert "data" in d
-    assert d["data"] == "Invalid request, missing parameters."
-    assert "success" in d
-    assert not d["success"]
-
-
-def test_invalid_params_2(server):
-    ret = server.post("/api/certificates", content_type="application/json", json={
-        "subject": {
-            "C": "CZ",
-            "CN": "Root CA s.r.o.",
-            "L": "Pilsen",
-            "O": "Root CA s.r.o.",
-            "OU": "IT department",
-            "ST": "Pilsen Region",
-            "emailAddress": "root@ca.com"
-        },
-        "usage": {
-            "CA": True,
-            "SSL": True,
-            "authentication": True,
-            "digitalSignature": True
-        },
-        "validityDays": "tak mesic treba plus minus"
-    })
-
-    assert ret.status_code == 400
-
-    d = ret.json
-
-    assert "data" in d
-    assert d["data"] == "Invalid request, wrong parameters."
-    assert "success" in d
-    assert not d["success"]
-
-
-def test_invalid_params_3(server):
-    ret = server.post("/api/certificates", content_type="application/json", json={
-        "subject": {
-            "C": "CZ",
-            "CN": "Root CA s.r.o.",
-            "L": "Pilsen",
-            "O": "Root CA s.r.o.",
-            "OU": "IT department",
-            "ST": ["Bosna", "Herzegovina"],
-            "emailAddress": "root@ca.com"
-        },
-        "usage": {
-            "CA": True,
-            "SSL": True,
-            "authentication": True,
-            "digitalSignature": True
-        },
-        "validityDays": 30
-    })
-
-    assert ret.status_code == 400
-
-    d = ret.json
-
-    assert "data" in d
-    assert d["data"] == "Invalid request, wrong parameters."
-    assert "success" in d
-    assert not d["success"]
-
-
-def test_invalid_params_4(server):
-    ret = server.post("/api/certificates", content_type="application/json", json={
-        "CA": 80081358008135,
-        "subject": {
-            "C": "CZ",
-            "CN": "Root CA s.r.o.",
-            "L": "Pilsen",
-            "O": "Root CA s.r.o.",
-            "OU": "IT department",
-            "ST": "Pilsen",
-            "emailAddress": "root@ca.com"
-        },
-        "usage": {
-            "CA": True,
-            "SSL": True,
-            "authentication": True,
-            "digitalSignature": True
-        },
-        "validityDays": 30
-    })
-
-    assert ret.status_code == 400
-
-    d = ret.json
-
-    assert "data" in d
-    assert d["data"] == "No certificate authority with such unique ID exists."
-    assert "success" in d
-    assert not d["success"]
-
-
-def test_create_chain(server):
-    ret = make_root_ca(server, "Another Root CA s.r.o.")
-
-    assert ret.status_code == 201
-
-    d = ret.json
-
-    assert "data" in d
-    assert d["data"] == 2
-    assert "success" in d
-    assert d["success"]
-
-    ret = make_inter_ca(server, 2)
-
-    assert ret.status_code == 201
-
-    d = ret.json
-
-    assert "data" in d
-    assert d["data"] == 3
-    assert "success" in d
-    assert d["success"]
-
-    ret = make_inter_ca(server, 3)
-
-    assert ret.status_code == 201
-
-    d = ret.json
-
-    assert "data" in d
-    assert d["data"] == 4
-    assert "success" in d
-    assert d["success"]
-
-    ret = make_inter_ca(server, 4)
-
-    assert ret.status_code == 201
-
-    d = ret.json
-
-    assert "data" in d
-    assert d["data"] == 5
-    assert "success" in d
-    assert d["success"]
-
-    ret = make_inter_ca(server, 5)
-
-    assert ret.status_code == 201
-
-    d = ret.json
-
-    assert "data" in d
-    assert d["data"] == 6
-    assert "success" in d
-    assert d["success"]
-
-    ret = make_end_cert(server, 6)
-
-    assert ret.status_code == 201
-
-    d = ret.json
-
-    assert "data" in d
-    assert d["data"] == 7
-    assert "success" in d
-    assert d["success"]
-
-
-def test_list_of_certificates(server):
-    ret = server.get("/api/certificates")
-
-    assert ret.status_code == 200
-
-    usage_dict = {'CA': True, 'SSL': True, 'authentication': True, 'digitalSignature': True}
-    s1 = "Root CA s.r.o."
-    s2 = "Another Root CA s.r.o."
-    s3 = "Intermediate CA s.r.o."
-
-    assert "data" in ret.json
-    assert "success" in ret.json
-    assert ret.json["success"]
-
-    d = ret.json["data"]
-
-    # print(d)
-
-    assert d[0]['CN'] == s1
-    assert d[1]['CN'] == s2
-    assert d[2]['CN'] == s3
-
-    assert all(d[i]['id'] == i + 1 for i in range(3))
-    assert all(d[i]['usage'] == usage_dict for i in range(3))
-
-    assert d[0]['issuer']['CN'] == s1
-    assert d[1]['issuer']['CN'] == s2
-    assert d[2]['issuer']['CN'] == s2
-
-    assert d[0]['issuer']['id'] == 1
-    assert d[1]['issuer']['id'] == 2
-    assert d[2]['issuer']['id'] == 2
-
-
-def test_sign_by_non_ca(server):
-    ret = make_end_cert(server, 2, "Fake intermediate cert s.r.o.", usage={
-            "CA": False,
-            "SSL": True,
-            "authentication": True,
-            "digitalSignature": True
-        })
-
-    assert ret.status_code == 201
-
-    d = ret.json
-
-    assert "data" in d
-    assert d["data"] == 8
-    assert "success" in d
-    assert d["success"]
-
-    ret = make_end_cert(server, 8, "End certificate signed by end certificate s.r.o.", usage={
-            "CA": False,
-            "SSL": True,
-            "authentication": False,
-            "digitalSignature": False
-        })
-
-    # TODO discussion -> assert ret.status_code == 400
-    assert ret.status_code == 201
-
-    d = ret.json
-
-    assert "data" in d
-    assert d["data"] == 9
-    assert "success" in d
-    assert d["success"]
-
-
-def test_filtering(server):
-    ret = server.get("/api/certificates", json={"filtering": {"CA": True}})
-
-    assert ret.status_code == 200
-
-    assert "data" in ret.json
-    assert "success" in ret.json
-    assert ret.json["success"]
-
-    d = ret.json["data"]
-
-    assert all(c["usage"]["CA"] for c in d)
-
-    all_certs_expected = list(d)
-
-    ret = server.get("/api/certificates", json={"filtering": {"CA": False}})
-
-    assert ret.status_code == 200
-
-    assert "data" in ret.json
-    assert "success" in ret.json
-    assert ret.json["success"]
-
-    d = ret.json["data"]
-
-    assert all(not c["usage"]["CA"] for c in d)
-
-    for v in d:
-        all_certs_expected.append(v)
-
-    ret = server.get("/api/certificates")
-
-    assert ret.status_code == 200
-
-    assert "data" in ret.json
-    assert "success" in ret.json
-    assert ret.json["success"]
-
-    all_certs_actual = ret.json["data"]
-
-    assert len(all_certs_actual) == len(all_certs_expected)
-    # TODO assert set(all_certs_expected) == set(all_certs_actual) or something like that instead
-
-
-def test_get_one(server):
-    ret = server.get("/api/certificates/1")
-
-    assert ret.status_code == 200
-
-    assert "data" in ret.json
-    assert "success" in ret.json
-    assert ret.json["success"]
-
-    d = ret.json["data"]
-
-    assert str(d).startswith("-----BEGIN CERTIFICATE-----")
-
-
-def test_get_one_bad_param(server):
-    ret = server.get("/api/certificates/whoopsie")
-
-    assert ret.status_code == 400
-    assert "data" in ret.json
-    assert "success" in ret.json
-    assert not ret.json["success"]
-    assert ret.json["data"] == "Invalid request, wrong parameters."
-
-
-def test_get_one_bad_param_2(server):
-    ret = server.get("/api/certificates/805")
-
-    assert ret.status_code == 205
-    assert "data" in ret.json
-    assert "success" in ret.json
-    assert not ret.json["success"]
-    assert ret.json["data"] == "No such certificate found."
-
-
-def test_get_detes(server):
-    original = {
-        "CA": 1,
-        "subject": {
-            "C": "CZ",
-            "CN": "Good boy end cert s.r.o.",
-            "L": "Pilsen",
-            "O": "This is most likely a good s.r.o.",
-            "OU": "IT department",
-            "ST": "Pilsen Region",
-            "emailAddress": "end@ca.com"
-        },
-        "usage": {
-            "CA": False,
-            "SSL": True,
-            "authentication": False,
-            "digitalSignature": True
-        },
-        "validityDays": 30
-    }
-    ret = server.post("/api/certificates", content_type="application/json", json=original)
-
-    assert ret.status_code == 201
-
-    assert "data" in ret.json
-    assert "success" in ret.json
-    assert ret.json["success"]
-
-    d = ret.json
-
-    assert d["data"] == 10
-
-    id = d["data"]
-
-    ret = server.get(f"/api/certificates/{id}/details")
-
-    assert ret.status_code == 200
-
-    assert "data" in ret.json
-    assert "success" in ret.json
-    assert ret.json["success"]
-
-    d = ret.json
-
-    new = d["data"]
-
-    assert original["CA"] == new["CA"]
-    assert original["subject"] == new["subject"]
-    assert original["usage"] == new["usage"]
-
-
-def test_get_root(server):
-    ret = server.get("/api/certificates/2")
-
-    assert ret.status_code == 200
-
-    assert "data" in ret.json
-    assert "success" in ret.json
-    assert ret.json["success"]
-
-    original = ret.json["data"]
-
-    ret = server.get("/api/certificates/4/root")
-
-    assert ret.status_code == 200
-
-    assert "data" in ret.json
-    assert "success" in ret.json
-    assert ret.json["success"]
-
-    new = ret.json["data"]
-
-    assert original == new
-
-
-def test_get_root_invalid(server):
-    ret = server.get("/api/certificates/805/root")
-
-    assert ret.status_code == 205
-    assert "data" in ret.json
-    assert "success" in ret.json
-    assert not ret.json["success"]
-    assert ret.json["data"] == "No such certificate found."
-
-
-def test_chain_of_trust(server):
-    expected = []
-    for i in range(6, 2, -1):
-        ret = server.get(f"/api/certificates/{i}")
-
-        assert ret.status_code == 200
-
-        assert "data" in ret.json
-        assert "success" in ret.json
-        assert ret.json["success"]
-
-        d = ret.json["data"]
-        expected.append(d)
-
-    ret = server.get(f"/api/certificates/7/chain")
-    assert ret.status_code == 200
-
-    assert "data" in ret.json
-    assert "success" in ret.json
-    assert ret.json["success"]
-
-    actual = ret.json["data"]
-
-    assert "".join(expected) == actual
\ No newline at end of file
diff --git a/tests/unit_tests/rest_api/conftest.py b/tests/unit_tests/rest_api/conftest.py
deleted file mode 100644
index dc168d4..0000000
--- a/tests/unit_tests/rest_api/conftest.py
+++ /dev/null
@@ -1,11 +0,0 @@
-import pytest
-from app import app as flask_app
-from src.db.setup_database import setup_database
-
-
-@pytest.fixture(scope="session")
-def server():
-    setup_database()
-    flask_app.testing = True
-    with flask_app.test_client() as s:
-        yield s
