Skip to content

Commit

Permalink
Remove hardcoded nature.
Browse files Browse the repository at this point in the history
  • Loading branch information
priyanshunayan committed Aug 23, 2020
1 parent 42eb18c commit 0a8a4a6
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ before_script:
- docker run -d -p 6379:6379 -it --rm --name redisgraph redislabs/redisgraph:2.0-edge

python:
- "3.5"
- "3.5-dev" # 3.5 development branch
- "3.6"
- "3.6-dev" # 3.6 development branch
- "3.7-dev"
- "3.7"
- "3.7-dev" # 3.7 development branch
install:
- pip install -e git+https://github.com/RedisGraph/redisgraph-py#egg=redisgraph
- pip install -e git+https://github.com/HTTP-APIs/hydra-python-core#egg=hydra_python_core
Expand Down
6 changes: 5 additions & 1 deletion hydra_agent/agent.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging
import sys
import socketio
from urllib.parse import urlparse
from hydra_agent.redis_core.redis_proxy import RedisProxy
from hydra_agent.redis_core.graphutils_operations import GraphOperations
from hydra_agent.redis_core.graph_init import InitialGraph
Expand All @@ -27,6 +28,9 @@ def __init__(self, entrypoint_url: str, namespace: str = '/sync') -> None:
:return: None
"""
self.entrypoint_url = entrypoint_url.strip().rstrip('/')
url_parse = urlparse(entrypoint_url)
self.entrypoint = url_parse.scheme + "://" + url_parse.netloc
self.api_name = url_parse.path.rstrip('/')
self.redis_proxy = RedisProxy()
self.redis_connection = self.redis_proxy.get_connection()
Session.__init__(self)
Expand All @@ -53,7 +57,7 @@ def fetch_apidoc(self) -> HydraDoc:
res = super().get(self.entrypoint_url)
api_doc_url = res.links['http://www.w3.org/ns/hydra/core#apiDocumentation']['url']
jsonld_api_doc = super().get(api_doc_url).json()
self.api_doc = doc_maker.create_doc(jsonld_api_doc, self.entrypoint_url, 'serverapi')
self.api_doc = doc_maker.create_doc(jsonld_api_doc, self.entrypoint, self.api_name )
return self.api_doc
except:
print("Error parsing your API Documentation")
Expand Down
7 changes: 5 additions & 2 deletions hydra_agent/redis_core/graphutils_operations.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import requests
import json
import logging
from urllib.parse import urlparse
from urllib.error import URLError, HTTPError
from hydra_python_core.doc_writer import HydraDoc
from hydra_agent.redis_core.redis_proxy import RedisProxy
Expand All @@ -26,6 +27,9 @@ def __init__(self, entrypoint_url: str, api_doc: HydraDoc,
:return: None
"""
self.entrypoint_url = entrypoint_url
url_parse = urlparse(entrypoint_url)
self.entrypoint = url_parse.scheme + "://" + url_parse.netloc
self.api_name = url_parse.path.rstrip('/')
self.api_doc = api_doc
self.redis_proxy = redis_proxy
self.redis_connection = redis_proxy.get_connection()
Expand Down Expand Up @@ -100,7 +104,6 @@ def get_processing(self, url: str, resource: dict) -> list:
resource['@type'],
where_dest="id : \'" +
resource['@id'] + "\'")

# Checking for embedded resources in the properties of resource
class_doc = self.api_doc.parsed_classes[resource['@type']]['class']
supported_properties = class_doc.supportedProperty
Expand All @@ -110,7 +113,7 @@ def get_processing(self, url: str, resource: dict) -> list:
embedded_url = eval(resource[supported_prop.title])['@id']
embedded_type = eval(resource[supported_prop.title])['@type']
new_resource = {'parent_id': resource['@id'], 'parent_type': resource['@type'],
'embedded_url': "http://localhost:8080{}".format(embedded_url),
'embedded_url': "{}{}".format(self.entrypoint, embedded_url),
'embedded_type': embedded_type}
embedded_resources.append(new_resource)
return embedded_resources
Expand Down
2 changes: 2 additions & 0 deletions hydra_agent/tests/test_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ def setUp(self, get_session_mock, socket_client_mock):
self.agent = Agent("http://localhost:8080/api")
except SyntaxError:
self.setUp(self, get_session_mock, socket_client_mock)
except ConnectionResetError:
self.setUp(self, get_session_mock, socket_client_mock)
self.redis_proxy = RedisProxy()
self.redis_connection = self.redis_proxy.get_connection()
self.redis_graph = Graph("apigraph", self.redis_connection)
Expand Down

0 comments on commit 0a8a4a6

Please sign in to comment.