Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Token support in gripql python client #190

Merged
merged 16 commits into from
Mar 11, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
dont strip path from url
  • Loading branch information
adamstruck committed Mar 4, 2019
commit 3ffa0639791e0e03ff896118f59a6d3be5132c6a
4 changes: 2 additions & 2 deletions gripql/python/gripql/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
class Connection(BaseConnection):
def __init__(self, url, user=None, password=None, token=None):
super(Connection, self).__init__(url, user, password, token)
self.url = self.url + "/v1/graph"
self.url = self.base_url + "/v1/graph"

def listGraphs(self):
"""
Expand Down Expand Up @@ -60,4 +60,4 @@ def graph(self, name):
"""
Get a graph handle.
"""
return Graph(self.url, name, self.user, self.password, self.token)
return Graph(self.base_url, name, self.user, self.password, self.token)
8 changes: 4 additions & 4 deletions gripql/python/gripql/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class Graph(BaseConnection):
def __init__(self, url, graph, user=None, password=None, token=None):
super(Graph, self).__init__(url, user, password, token)
self.url = self.url + "/v1/graph/" + graph
self.url = self.base_url + "/v1/graph/" + graph
self.graph = graph

def addSchema(self, vertices=[], edges=[]):
Expand Down Expand Up @@ -116,7 +116,7 @@ def getEdge(self, gid):
return response.json()

def bulkAdd(self):
return BulkAdd(self.url, self.graph, self.user, self.password, self.token)
return BulkAdd(self.base_url, self.graph, self.user, self.password, self.token)

def addIndex(self, label, field):
url = self.url + "/index/" + label
Expand Down Expand Up @@ -165,13 +165,13 @@ def query(self):
"""
Create a query handle.
"""
return Query(self.url, self.graph, self.user, self.password, self.token)
return Query(self.base_url, self.graph, self.user, self.password, self.token)


class BulkAdd(BaseConnection):
def __init__(self, url, graph, user=None, password=None, token=None):
super(BulkAdd, self).__init__(url, user, password, token)
self.url = self.url + "/v1/graph"
self.url = self.base_url + "/v1/graph"
self.graph = graph
self.elements = []

Expand Down
4 changes: 2 additions & 2 deletions gripql/python/gripql/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ def _wrap_dict_value(value):
class Query(BaseConnection):
def __init__(self, url, graph, user=None, password=None, token=None):
super(Query, self).__init__(url, user, password, token)
self.url = self.url + "/v1/graph/" + graph + "/query"
self.url = self.base_url + "/v1/graph/" + graph + "/query"
self.graph = graph
self.query = []

def __append(self, part):
q = self.__class__(self.url, self.graph, self.user, self.password, self.token)
q = self.__class__(self.base_url, self.graph, self.user, self.password, self.token)
q.query = self.query[:]
q.query.append(part)
return q
Expand Down
3 changes: 1 addition & 2 deletions gripql/python/gripql/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class BaseConnection(object):
def __init__(self, url, user=None, password=None, token=None):
url = process_url(url)
self.url = url
self.base_url = url
if user is None:
user = os.getenv("GRIP_USER", None)
self.user = user
Expand Down Expand Up @@ -197,7 +197,6 @@ def process_url(url):
if netloc == "" and path != "":
netloc = path.split("/")[0]
path = ""
path = ""
return urlunparse((scheme, netloc, path, params, query, frag))


Expand Down
29 changes: 0 additions & 29 deletions gripql/python/tests/BaseConnection_test.py

This file was deleted.

26 changes: 26 additions & 0 deletions gripql/python/tests/url_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import unittest

from gripql.connection import Connection
from gripql.graph import Graph, BulkAdd
from gripql.query import Query
from gripql.util import BaseConnection


class TestUrlBuilding(unittest.TestCase):
mock_url = "http://fakehost:8000"

def test_url_building(self):
b = BaseConnection(self.mock_url)
self.assertEqual(b.base_url, self.mock_url)

c = Connection(self.mock_url)
self.assertEqual(c.base_url, self.mock_url)
self.assertEqual(c.url, self.mock_url + "/v1/graph")

g = c.graph("test")
self.assertEqual(g.base_url, self.mock_url)
self.assertEqual(g.url, self.mock_url + "/v1/graph/test")

q = g.query()
self.assertEqual(q.base_url, self.mock_url)
self.assertEqual(q.url, self.mock_url + "/v1/graph/test/query")