summaryrefslogtreecommitdiff
path: root/tests/test_get.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_get.py')
-rw-r--r--tests/test_get.py82
1 files changed, 82 insertions, 0 deletions
diff --git a/tests/test_get.py b/tests/test_get.py
new file mode 100644
index 0000000..377f35a
--- /dev/null
+++ b/tests/test_get.py
@@ -0,0 +1,82 @@
+"""
+Test our get
+"""
+import unittest
+import json
+
+import requests
+
+from src.soc_collector.auth import load_api_keys
+from src.soc_collector.soc_collector_cli import json_load_data
+
+
+BASE_URL = "https://localhost:8000"
+
+
+class TestAddress(unittest.TestCase):
+ """
+ Test our get
+ """
+
+ def test_get(self) -> None:
+ """
+ Test get
+ """
+
+ api_keys = load_api_keys("data/api_keys.txt")
+ insert_data = json_load_data("./tests/data/example_data_1.json")
+
+ request_headers = {"API-KEY": api_keys[-1]}
+ req = requests.post(
+ f"{BASE_URL}/sc/v0",
+ json=insert_data,
+ headers=request_headers,
+ timeout=4,
+ verify="./data/collector_root_ca.crt",
+ )
+ self.assertTrue(req.status_code == 200)
+ key = json.loads(req.text)["_id"]
+
+ req = requests.get(
+ f"{BASE_URL}/sc/v0/dummy",
+ headers=request_headers,
+ timeout=4,
+ verify="./data/collector_root_ca.crt",
+ )
+ self.assertTrue(req.status_code == 400)
+
+ req = requests.get(
+ f"{BASE_URL}/sc/v0/63765238890b48a0c3118f4f",
+ headers=request_headers,
+ timeout=4,
+ verify="./data/collector_root_ca.crt",
+ )
+ self.assertTrue(req.status_code == 404)
+
+ req = requests.get(
+ f"{BASE_URL}/sc/v0/{key}",
+ headers=request_headers,
+ timeout=4,
+ verify="./data/collector_root_ca.crt",
+ )
+ self.assertTrue(req.status_code == 200)
+ data1 = json.loads(req.text)
+
+ req = requests.get(
+ f"{BASE_URL}/sc/v0/{key}",
+ headers=request_headers,
+ timeout=4,
+ verify="./data/collector_root_ca.crt",
+ )
+ self.assertTrue(req.status_code == 200)
+ data2 = json.loads(req.text)
+ self.assertTrue(data1 == data2)
+
+ # Delete test data
+ req = requests.delete(
+ f"{BASE_URL}/sc/v0/{key}",
+ headers=request_headers,
+ timeout=4,
+ verify="./data/collector_root_ca.crt",
+ )
+ self.assertTrue(req.status_code == 200)