1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
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)
|