Skip to content

Commit 651c856

Browse files
authored
Merge pull request #67 from HTTP-APIs/develop
Sync with develop
2 parents 4bdaa1f + f56128e commit 651c856

File tree

10 files changed

+233
-12
lines changed

10 files changed

+233
-12
lines changed

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ MAINTAINER Sandeep Chauhan <sandeepsajan0@gmail.com>
66
COPY ./requirements.txt /home/requirements.txt
77
RUN pip install -r /home/requirements.txt
88

9-
COPY ./hydra_redis /home/app/hydra_redis
9+
COPY ./hydra_agent /home/app/hydra_agent
1010
ENV PYTHONPATH $PYTHONPATH:/home/app/
1111

12-
ENTRYPOINT ["python", "/home/app/hydra_redis/querying_mechanism.py"]
12+
ENTRYPOINT ["python", "/home/app/hydra_agent/querying_mechanism.py"]
1313

1414

1515

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import re
44
import logging
55
from urllib.error import URLError, HTTPError
6-
from hydra_redis.classes_objects import ClassEndpoints,RequestError
6+
from hydra_agent.classes_objects import ClassEndpoints,RequestError
77

88
logging.basicConfig(level=logging.INFO)
99
logger = logging.getLogger(__name__)
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
from hydrus.hydraspec import doc_maker
66
import hydrus
77
from graphviz import Digraph
8-
from hydra_redis.classes_objects import ClassEndpoints,RequestError
9-
from hydra_redis.collections_endpoint import CollectionEndpoints
10-
from hydra_redis.redis_proxy import RedisProxy
8+
from hydra_agent.classes_objects import ClassEndpoints,RequestError
9+
from hydra_agent.collections_endpoint import CollectionEndpoints
10+
from hydra_agent.redis_proxy import RedisProxy
1111

1212

1313
class InitialGraph:
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import random
22
import string
33
import logging
4-
from hydra_redis.hydra_graph import InitialGraph
4+
from hydra_agent.hydra_graph import InitialGraph
55
import urllib.request
66
import json
77
from hydrus.hydraspec import doc_maker
88
from urllib.error import URLError, HTTPError
9-
from hydra_redis.collections_endpoint import CollectionEndpoints
10-
from hydra_redis.classes_objects import ClassEndpoints,RequestError
11-
from hydra_redis.redis_proxy import RedisProxy
9+
from hydra_agent.collections_endpoint import CollectionEndpoints
10+
from hydra_agent.classes_objects import ClassEndpoints,RequestError
11+
from hydra_agent.redis_proxy import RedisProxy
1212

1313
logging.basicConfig(level=logging.INFO)
1414
logger = logging.getLogger(__name__)

hydra_agent/tests/querying_test.py

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
import unittest
2+
import urllib.request
3+
import json
4+
import redis
5+
from hydrus.hydraspec import doc_maker
6+
from os import sys, path
7+
from hydra_agent import querying_mechanism
8+
9+
class TestQueryingMechanism(unittest.TestCase):
10+
11+
def setUp(self):
12+
url = "https://storage.googleapis.com/api4/api"
13+
vocab_url = url + "/" + "vocab"
14+
response = urllib.request.urlopen(vocab_url)
15+
apidoc = json.loads(response.read().decode('utf-8'))
16+
api_doc = doc_maker.create_doc(apidoc)
17+
self.query_facades = querying_mechanism.QueryFacades(api_doc, url, True)
18+
self.query_facades.initialize(True)
19+
self.test_database = redis.StrictRedis(host='localhost', port=6379, db=5)
20+
21+
def test_1_classendpoint(self):
22+
"""Test for class endpoint"""
23+
check_data = [['p.properties', 'p.id', 'p.type'],
24+
["['Location']",'vocab:EntryPoint/Location','Location']]
25+
query = "show classEndpoints"
26+
data = self.query_facades.user_query(query)
27+
for check in check_data:
28+
flag = False
29+
if check[0] in str(data) and check[1] in str(data) and check[2] in str(data):
30+
flag = True
31+
if flag:
32+
self.assertTrue(True)
33+
else:
34+
self.assertTrue(False)
35+
36+
def test_2_collectionendpoint(self):
37+
"""Test for collection endpoint"""
38+
check_data = ["ControllerLogCollection",
39+
"DroneLogCollection",
40+
"AnomalyCollection",
41+
"DroneCollection",
42+
"CommandCollection",
43+
"HttpApiLogCollection",
44+
"DatastreamCollection",
45+
"MessageCollection"]
46+
query = "show collectionEndpoints"
47+
data = self.query_facades.user_query(query)
48+
for check in check_data:
49+
if check not in str(data):
50+
self.assertTrue(False)
51+
self.assertTrue(True)
52+
53+
def test_3_CommandCollectionmember(self):
54+
"""
55+
Test for all Commands in CommandCollection.
56+
Data is already stored in check_data from the static data url.
57+
Check_data is used for compare the data retrieve by querying process.
58+
"""
59+
check_data = ['[]']
60+
query = "show CommandCollection members"
61+
data = self.query_facades.user_query(query)
62+
self.assertEqual(data[1],check_data)
63+
64+
def test_4_ControllerLogCollectionmember(self):
65+
"""
66+
Test for all controller logs for ControllerLogCollection.
67+
Whole object of ControllerLogCollection is stored in check data.
68+
Check_data is used for compare the data retrieve by querying process.
69+
"""
70+
check_data = [{'@id': '/api/ControllerLogCollection/65',
71+
'@type': 'ControllerLog'},
72+
{'@id': '/api/ControllerLogCollection/183',
73+
'@type': 'ControllerLog'},
74+
{'@id': '/api/ControllerLogCollection/374',
75+
'@type': 'ControllerLog'}]
76+
query = "show ControllerLogCollection members"
77+
data = self.query_facades.user_query(query)
78+
# Make data searchable and comaprable.
79+
data1 = str(data[1]).replace('"', '')
80+
# data retrive from the memory can be distributed:
81+
# like type can be at first position and id can be at second.
82+
# So, check_data split in 3 parts.
83+
# And check all parts are in data retrieve.
84+
if str(
85+
check_data[0]) in data1 and str(
86+
check_data[1]) in data1 and str(
87+
check_data[2]) in data1:
88+
self.assertTrue(True)
89+
else:
90+
self.assertTrue(False)
91+
92+
93+
def test_5_DatastreamCollectionmember(self):
94+
"""Test for all datastream with Drone ID 2"""
95+
check_data = ['/api/DatastreamCollection/19']
96+
query = "show DatastreamCollection members"
97+
data = self.query_facades.user_query(query)
98+
# Here are find the datastream only for those which have DroneID 2.
99+
query = "show DroneID 2 and type Datastream"
100+
data = self.query_facades.user_query(query)
101+
self.assertEqual(data,check_data)
102+
103+
def tearDown(self):
104+
self.test_database.flushdb()
105+
106+
if __name__ == "__main__":
107+
unittest.main()

hydra_agent/tests/redis_test.py

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
import unittest
2+
import redis
3+
4+
5+
class Tests:
6+
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):
29+
return True
30+
else:
31+
return False
32+
33+
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):
56+
return True
57+
else:
58+
return False
59+
60+
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):
84+
return True
85+
else:
86+
return False
87+
88+
89+
class TestRedisStructure(unittest.TestCase):
90+
test_redis = Tests()
91+
92+
@classmethod
93+
def setUpClass(cls):
94+
cls.test_database=redis.StrictRedis(host='localhost', port=6379, db=5)
95+
cls.test_database.set("foo","bar")
96+
cls.test_database.set("hydra","redis")
97+
print("setUpClass db=5 keys:",cls.test_database.keys())
98+
99+
def test_entrypoint(self):
100+
self.assertTrue(self.test_redis.entry_point())
101+
102+
def test_collectionEndpoints(self):
103+
self.assertTrue(self.test_redis.collection_endpoints())
104+
105+
def test_classEndpoints(self):
106+
self.assertTrue(self.test_redis.class_endpoints())
107+
108+
@classmethod
109+
def tearDownClass(cls):
110+
cls.test_database.flushdb()
111+
print("tearDownClass db=5 keys:",cls.test_database.get("foo"))
112+
113+
if __name__ == '__main__':
114+
unittest.main()

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@
2525
install_requires=dependencies,
2626
packages=find_packages(
2727
exclude=['hydra','examples','test*','python_whihydra_agent.egg-info']),
28-
package_dir={'hydra_redis':
29-
'hydra_redis'},
28+
package_dir={'hydra_agent':
29+
'hydra_agent'},
3030
)

0 commit comments

Comments
 (0)