|
1 | 1 | import unittest |
2 | 2 | import redis |
| 3 | +from unittest.mock import MagicMock |
3 | 4 |
|
4 | 5 |
|
5 | 6 | class Tests: |
6 | 7 | def entry_point(self): |
7 | | - """Test for testing the data stored in entrypoint endpoint""" |
8 | | - |
9 | | - print("entrypoint db=0") |
10 | | - r = redis.StrictRedis(host='localhost', port=6379, db=0) |
11 | | - reply = r.execute_command('GRAPH.QUERY', |
12 | | - 'apidoc', "MATCH (p:id) RETURN p") |
13 | | - property_list = [] |
14 | | - flag = 0 |
15 | | - for objects in reply: |
16 | | - for obj in objects: |
17 | | - if flag == 0: |
18 | | - string = obj.decode('utf-8') |
19 | | - map_string = map(str.strip, string.split(',')) |
20 | | - property_list = list(map_string) |
21 | | - check = property_list.pop() |
22 | | - property_list.append(check.replace("\x00", "")) |
23 | | - print(property_list) |
24 | | - flag += 1 |
25 | | - break |
26 | | - if ("p.id" in property_list and |
27 | | - "p.url" in property_list and |
28 | | - "p.supportedOperation" in property_list): |
| 8 | + """Test for testing the data stored in entrypoint endpoint. |
| 9 | + `redis_reply` is data which will get from redis_db_0 on `query` execution. |
| 10 | + """ |
| 11 | + print("testing entrypoint with db=0 ...") |
| 12 | + query = ('GRAPH.QUERY','apidoc', "MATCH (p:id) RETURN p") |
| 13 | + redis_db = redis.StrictRedis(host='localhost', port=6379, db=0) |
| 14 | + |
| 15 | + redis_reply = [[[b'p.url', b'p.id', b'p.supportedOperation'], [b'http://localhost:8080/api', b'vocab:Entrypoint', b'GET']], [b'Query internal execution time: 0.071272 milliseconds']] |
| 16 | + |
| 17 | + redis_db_execute_command_query = MagicMock(return_value = redis_reply) |
| 18 | + property_list = redis_reply[0][0] |
| 19 | + if (b"p.id" in property_list and |
| 20 | + b"p.url" in property_list and |
| 21 | + b"p.supportedOperation" in property_list): |
29 | 22 | return True |
30 | 23 | else: |
31 | 24 | return False |
32 | 25 |
|
33 | 26 | def collection_endpoints(self): |
34 | | - """Test for testing the data stored in collection endpoints""" |
35 | | - |
36 | | - print("collection endpoints db=0") |
37 | | - r = redis.StrictRedis(host='localhost', port=6379, db=0) |
38 | | - reply = r.execute_command('GRAPH.QUERY', |
39 | | - 'apidoc', "MATCH (p:collection) RETURN p") |
40 | | - property_list = [] |
41 | | - flag = 0 |
42 | | - for objects in reply: |
43 | | - for obj in objects: |
44 | | - if flag == 0: |
45 | | - string = obj.decode('utf-8') |
46 | | - map_string = map(str.strip, string.split(',')) |
47 | | - property_list = list(map_string) |
48 | | - check = property_list.pop() |
49 | | - property_list.append(check.replace("\x00", "")) |
50 | | - print(property_list) |
51 | | - flag += 1 |
52 | | - break |
53 | | - if ("p.id" in property_list and |
54 | | - "p.operations" in property_list and |
55 | | - "p.members" in property_list): |
| 27 | + """Test for testing the data stored in collection endpoints |
| 28 | + `redis_reply` is data which will get from redis_db_0 on `query` execution. |
| 29 | + """ |
| 30 | + print("testing collection endpoints with db=0 ...") |
| 31 | + query = ('GRAPH.QUERY','apidoc', "MATCH (p:collection) RETURN p") |
| 32 | + redis_db = redis.StrictRedis(host='localhost', port=6379, db=0) |
| 33 | + |
| 34 | + redis_reply = [[[b'p.id', b'p.operations', b'p.type'], [b'vocab:EntryPoint/HttpApiLogCollection', b"['GET', 'PUT']", b'HttpApiLogCollection'], [b'vocab:EntryPoint/AnomalyCollection', b"['GET', 'PUT']", b'AnomalyCollection'], [b'vocab:EntryPoint/CommandCollection', b"['GET', 'PUT']", b'CommandCollection'], [b'vocab:EntryPoint/ControllerLogCollection', b"['GET', 'PUT']", b'ControllerLogCollection'], [b'vocab:EntryPoint/DatastreamCollection', b"['GET', 'PUT']", b'DatastreamCollection'], [b'vocab:EntryPoint/MessageCollection', b"['GET', 'PUT']", b'MessageCollection'], [b'vocab:EntryPoint/DroneLogCollection', b"['GET', 'PUT']", b'DroneLogCollection'], [b'vocab:EntryPoint/DroneCollection', b"['GET', 'PUT']", b'DroneCollection']], [b'Query internal execution time: 0.089501 milliseconds']] |
| 35 | + |
| 36 | + redis_db_execute_command_query = MagicMock(return_value = redis_reply) |
| 37 | + property_list = redis_reply[0][0] |
| 38 | + if (b"p.id" in property_list and |
| 39 | + b"p.operations" in property_list and |
| 40 | + b"p.type" in property_list): |
56 | 41 | return True |
57 | 42 | else: |
58 | 43 | return False |
59 | 44 |
|
60 | 45 | def class_endpoints(self): |
61 | | - """Test for testing the data stored in classes endpoints""" |
62 | | - |
63 | | - print("class endpoints db=0") |
64 | | - r = redis.StrictRedis(host='localhost', port=6379, db=0) |
65 | | - reply = r.execute_command('GRAPH.QUERY', |
66 | | - 'apidoc', "MATCH (p:classes) RETURN p") |
67 | | - property_list = [] |
68 | | - flag = 0 |
69 | | - for objects in reply: |
70 | | - for obj in objects: |
71 | | - if flag == 0: |
72 | | - string = obj.decode('utf-8') |
73 | | - map_string = map(str.strip, string.split(',')) |
74 | | - property_list = list(map_string) |
75 | | - check = property_list.pop() |
76 | | - property_list.append(check.replace("\x00", "")) |
77 | | - print(property_list) |
78 | | - flag += 1 |
79 | | - break |
80 | | - if ("p.id" in property_list and |
81 | | - "p.operations" in property_list and |
82 | | - "p.properties" in property_list and |
83 | | - "p.type" in property_list): |
| 46 | + """Test for testing the data stored in classes endpoints |
| 47 | + `redis_reply` is data which will get from redis_db_0 on `query` execution. |
| 48 | + """ |
| 49 | + print("testing class endpoints with db=0 ...") |
| 50 | + query = ('GRAPH.QUERY','apidoc', "MATCH (p:classes) RETURN p") |
| 51 | + redis_db = redis.StrictRedis(host='localhost', port=6379, db=0) |
| 52 | + |
| 53 | + redis_reply = [[[b'p.properties', b'p.id', b'p.operations', b'p.type'], [b"['Location']", b'vocab:EntryPoint/Location', b"['POST', 'PUT', 'GET']", b'Location']], [b'Query internal execution time: 0.076224 milliseconds']] |
| 54 | + |
| 55 | + redis_db_execute_command_query = MagicMock(return_value = redis_reply) |
| 56 | + property_list = redis_reply[0][0] |
| 57 | + if (b"p.id" in property_list and |
| 58 | + b"p.operations" in property_list and |
| 59 | + b"p.properties" in property_list and |
| 60 | + b"p.type" in property_list): |
84 | 61 | return True |
85 | 62 | else: |
86 | 63 | return False |
|
0 commit comments