-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtests.py
65 lines (56 loc) · 2.38 KB
/
tests.py
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
import unittest
import json
import requests
class TestServer(unittest.TestCase):
def setUp(self):
self.url = 'http://localhost:8080'
self.headers = {
"Authorization":"123456"
}
def test_save_node(self):
# Test saving a new node to the database
data = {
'parentId': "",
'text': 'Test node',
'author': 'Test author',
'timestamp': '2022-01-01 00:00:00'
}
response = requests.post(f'{self.url}/nodes', json=data, headers=self.headers)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.json(), {'success': True})
def test_update_node(self):
# Test updating an existing node in the database
data = {
'text': 'Updated node',
'author': 'Updated author',
'timestamp': '2022-01-01 00:00:00'
}
response = requests.put(f'{self.url}/nodes/1', json=data, headers=self.headers)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.json(), {'success': True})
def test_get_nodes(self):
# Test getting all nodes from the database after a given timestamp
response = requests.get(f'{self.url}/nodes/get/2021-01-01 00:00:00', headers=self.headers)
print(response.json())
self.assertEqual(response.status_code, 200)
self.assertEqual(response.json()['success'], True)
def test_get_node_ids(self):
# Test getting all node ids from the database
response = requests.get(f'{self.url}/nodes/ids', headers=self.headers)
print(response.json())
self.assertEqual(response.status_code, 200)
self.assertEqual(response.json()['success'], True)
def test_node_exists(self):
# Test checking if a node exists in the database
response = requests.get(f'{self.url}/nodes/exists/1', headers=self.headers)
print(response.json())
self.assertEqual(response.status_code, 200)
self.assertEqual(response.json()['success'], True)
def test_get_history(self):
# Test getting the history from the database
response = requests.get(f'{self.url}/history', headers=self.headers)
print(response.json())
self.assertEqual(response.status_code, 200)
self.assertEqual(response.json()['success'], True)
if __name__ == '__main__':
unittest.main()