commit a0d4dda10831964baaaf6b1bedee1cc59ae59318
Author: Captain_Trojan <sejakm@students.zcu.cz>
Date:   Tue Apr 6 20:28:47 2021 +0200

    Re #8476 - Created basic unit tests for `create_certificate`.

diff --git a/tests/unit_tests/rest_api/__init__.py b/tests/unit_tests/rest_api/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/tests/unit_tests/rest_api/certificates.py b/tests/unit_tests/rest_api/certificates.py
new file mode 100644
index 0000000..45784f5
--- /dev/null
+++ b/tests/unit_tests/rest_api/certificates.py
@@ -0,0 +1,178 @@
+def test_import(server):
+    assert 1 + 2 + 3 + 4 != -1 / 12
+
+    ret = server.get("/")
+    assert ret.status_code == 404
+
+
+def test_root_ca(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": 30
+    })
+
+    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 "status" in d
+    assert d["status"] == 400
+    assert "detail" in d
+    assert d["detail"] == "'usage' is a required property"
+
+
+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 "status" in d
+    assert d["status"] == 400
+    assert "detail" in d
+    assert d["detail"] == "'tak mesic treba plus minus' is not of type 'integer' - 'validityDays'"
+
+
+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 "status" in d
+    assert d["status"] == 400
+    assert "detail" in d
+    assert d["detail"] == "['Bosna', 'Herzegovina'] is not of type 'string' - 'subject.ST'"
+
+
+def test_root_inter_ca(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": 30
+    })
+
+    assert ret.status_code == 201
+
+    d = ret.json
+
+    assert "data" in d
+    assert d["data"] == 2
+    assert "success" in d
+    assert d["success"]
+
+    ret = server.post("/api/certificates", content_type="application/json", json={
+        "subject": {
+            "CA": 2,
+            "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": 30
+    })
+
+    assert ret.status_code == 201
+
+    d = ret.json
+
+    assert "data" in d
+    assert d["data"] == 3
+    assert "success" in d
+    assert d["success"]
\ No newline at end of file
diff --git a/tests/unit_tests/rest_api/conftest.py b/tests/unit_tests/rest_api/conftest.py
new file mode 100644
index 0000000..e7c9227
--- /dev/null
+++ b/tests/unit_tests/rest_api/conftest.py
@@ -0,0 +1,12 @@
+import pytest
+from swagger_server.__main__ import app as flask_app, setup
+from src.db.setup_database import setup_database
+
+
+@pytest.fixture(scope="session")
+def server():
+    setup_database()
+    setup(flask_app)
+    flask_app.app.testing = True
+    with flask_app.app.test_client() as s:
+        yield s
