diff --git a/aiogremlin/subprotocol.py b/aiogremlin/subprotocol.py index 252f54059e95b8f7e83ae652ba14f627702ba66e..e75f55e048693df498a68b9605f3ffc6b03d692a 100644 --- a/aiogremlin/subprotocol.py +++ b/aiogremlin/subprotocol.py @@ -69,7 +69,6 @@ class GremlinWriter: if binary: message = self._set_message_header(message, mime_type) self.ws.send(message, binary=binary) - print(message) return self.ws @staticmethod @@ -111,7 +110,7 @@ class GremlinWriter: "op": "authentication", "processor": processor, "args": { - "sasl": base64.b64encode(auth) + "sasl": base64.b64encode(auth).decode() } } if session is None: diff --git a/setup.py b/setup.py index 98d9f93b2335f5fb462cae928153470f779b22b1..3463d36a04b3cdab6f59e6eba0bdfcff831bc912 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ from setuptools import setup setup( name="aiogremlin", - version="0.1.1", + version="0.1.2", url="", license="MIT", author="davebshow", @@ -12,8 +12,8 @@ setup( long_description=open("README.txt").read(), packages=["aiogremlin", "tests"], install_requires=[ - "aiohttp==0.16.5", - "aiowebsocketclient==0.0.3" + "aiohttp==0.18.4", + "aiowebsocketclient==0.0.4" ], test_suite="tests", classifiers=[ diff --git a/tests/test_sasl.py b/tests/test_sasl.py index 62d560f983b0e6c157a8d36c9603b0da1a5e80ae..59e403e615452622b427aaaf9029d928ccaf7b34 100644 --- a/tests/test_sasl.py +++ b/tests/test_sasl.py @@ -8,21 +8,64 @@ import aiohttp from aiogremlin import (submit, GremlinConnector, GremlinClient, GremlinClientSession, GremlinServerError, GremlinClientWebSocketResponse) -from tests import SubmitTest, GremlinClientTest, GremlinClientSessionTest -class SaslSubmitTest(SubmitTest): +class SubmitTest(unittest.TestCase): def setUp(self): - self.uri = 'https://localhost:8182/' self.loop = asyncio.new_event_loop() asyncio.set_event_loop(None) + def tearDown(self): + self.loop.close() -class SaslGremlinClientTest(GremlinClientTest): + def test_submit(self): + + @asyncio.coroutine + def go(): + resp = yield from submit("x + x", url='https://localhost:8182/', + bindings={"x": 4}, loop=self.loop, + username="stephen", password="password") + results = yield from resp.get() + return results + results = self.loop.run_until_complete(go()) + self.assertEqual(results[0].data[0], 8) + + def test_rebinding(self): + + @asyncio.coroutine + def go1(): + result = yield from submit("graph2.addVertex()", + url='https://localhost:8182/', + loop=self.loop, username="stephen", + password="password") + resp = yield from result.get() + + try: + self.loop.run_until_complete(go1()) + error = False + except GremlinServerError: + error = True + self.assertTrue(error) + + @asyncio.coroutine + def go2(): + result = yield from submit( + "graph2.addVertex()", url='https://localhost:8182/', + rebindings={"graph2": "graph"}, loop=self.loop, + username="stephen", password="password") + resp = yield from result.get() + self.assertEqual(len(resp), 1) + + try: + self.loop.run_until_complete(go2()) + except GremlinServerError: + print("RELEASE DOES NOT SUPPORT REBINDINGS") + + +class GremlinClientTest(unittest.TestCase): def setUp(self): - self.uri = 'https://localhost:8182/' self.loop = asyncio.new_event_loop() asyncio.set_event_loop(None) connector = aiohttp.TCPConnector(force_close=False, loop=self.loop, @@ -32,15 +75,92 @@ class SaslGremlinClientTest(GremlinClientTest): connector=connector, loop=self.loop, ws_response_class=GremlinClientWebSocketResponse) - self.gc = GremlinClient(url=self.uri, loop=self.loop, + self.gc = GremlinClient(url="https://localhost:8182/", loop=self.loop, username="stephen", password="password", client_session=client_session) + def tearDown(self): + self.loop.run_until_complete(self.gc.close()) + self.loop.close() + + def test_connection(self): + + @asyncio.coroutine + def go(): + ws = yield from self.gc._connector.ws_connect(self.gc.url) + self.assertFalse(ws.closed) + yield from ws.close() + + self.loop.run_until_complete(go()) + + def test_execute(self): + + @asyncio.coroutine + def go(): + resp = yield from self.gc.execute("x + x", bindings={"x": 4}) + return resp + + results = self.loop.run_until_complete(go()) + self.assertEqual(results[0].data[0], 8) + + def test_sub_waitfor(self): + sub1 = self.gc.execute("x + x", bindings={"x": 1}) + sub2 = self.gc.execute("x + x", bindings={"x": 2}) + sub3 = self.gc.execute("x + x", bindings={"x": 4}) + coro = asyncio.gather(*[asyncio.async(sub1, loop=self.loop), + asyncio.async(sub2, loop=self.loop), + asyncio.async(sub3, loop=self.loop)], + loop=self.loop) + # Here I am looking for resource warnings. + results = self.loop.run_until_complete(coro) + self.assertIsNotNone(results) + + def test_resp_stream(self): + @asyncio.coroutine + def stream_coro(): + results = [] + resp = yield from self.gc.submit("x + x", bindings={"x": 4}) + while True: + f = yield from resp.stream.read() + if f is None: + break + results.append(f) + self.assertEqual(results[0].data[0], 8) + self.loop.run_until_complete(stream_coro()) + + def test_execute_error(self): + execute = self.gc.execute("x + x g.asdfas", bindings={"x": 4}) + try: + self.loop.run_until_complete(execute) + error = False + except: + error = True + self.assertTrue(error) -class SaslGremlinClientSessionTest(GremlinClientSessionTest): + def test_rebinding(self): + execute = self.gc.execute("graph2.addVertex()") + try: + self.loop.run_until_complete(execute) + error = False + except GremlinServerError: + error = True + self.assertTrue(error) + + @asyncio.coroutine + def go(): + result = yield from self.gc.execute( + "graph2.addVertex()", rebindings={"graph2": "graph"}) + self.assertEqual(len(result), 1) + + try: + self.loop.run_until_complete(go()) + except GremlinServerError: + print("RELEASE DOES NOT SUPPORT REBINDINGS") + + +class GremlinClientSessionTest(unittest.TestCase): def setUp(self): - self.uri = 'https://localhost:8182/' self.loop = asyncio.new_event_loop() asyncio.set_event_loop(None) connector = aiohttp.TCPConnector(force_close=False, loop=self.loop, @@ -50,7 +170,7 @@ class SaslGremlinClientSessionTest(GremlinClientSessionTest): connector=connector, loop=self.loop, ws_response_class=GremlinClientWebSocketResponse) - self.gc = GremlinClientSession(url=self.uri, + self.gc = GremlinClientSession(url="https://localhost:8182/", loop=self.loop, username="stephen", password="password", client_session=client_session) @@ -59,6 +179,86 @@ class SaslGremlinClientSessionTest(GremlinClientSessionTest): self.script2 = "v.property('name')" + def tearDown(self): + self.loop.run_until_complete(self.gc.close()) + self.loop.close() + + def test_session(self): + + @asyncio.coroutine + def go(): + yield from self.gc.execute(self.script1) + results = yield from self.gc.execute(self.script2) + return results + + results = self.loop.run_until_complete(go()) + self.assertEqual(results[0].data[0]['value'], 'Dave') + + def test_session_reset(self): + + @asyncio.coroutine + def go(): + yield from self.gc.execute(self.script1) + self.gc.reset_session() + results = yield from self.gc.execute(self.script2) + return results + try: + results = self.loop.run_until_complete(go()) + error = False + except GremlinServerError: + error = True + self.assertTrue(error) + + def test_session_manual_reset(self): + + @asyncio.coroutine + def go(): + yield from self.gc.execute(self.script1) + new_sess = str(uuid.uuid4()) + sess = self.gc.reset_session(session=new_sess) + self.assertEqual(sess, new_sess) + self.assertEqual(self.gc.session, new_sess) + results = yield from self.gc.execute(self.script2) + return results + try: + results = self.loop.run_until_complete(go()) + error = False + except GremlinServerError: + error = True + self.assertTrue(error) + + def test_session_set(self): + + @asyncio.coroutine + def go(): + yield from self.gc.execute(self.script1) + new_sess = str(uuid.uuid4()) + self.gc.session = new_sess + self.assertEqual(self.gc.session, new_sess) + results = yield from self.gc.execute(self.script2) + return results + try: + results = self.loop.run_until_complete(go()) + error = False + except GremlinServerError: + error = True + self.assertTrue(error) + + def test_resp_session(self): + + @asyncio.coroutine + def go(): + session = str(uuid.uuid4()) + self.gc.session = session + resp = yield from self.gc.submit("x + x", bindings={"x": 4}) + while True: + f = yield from resp.stream.read() + if f is None: + break + self.assertEqual(resp.session, session) + + self.loop.run_until_complete(go()) + if __name__ == "__main__": unittest.main() diff --git a/tests/tests.py b/tests/tests.py index a062e9eb22ce264067a9fb27ab2a7d387646d453..b823e7dbd0e13d31187c0579461909a70b677bd7 100644 --- a/tests/tests.py +++ b/tests/tests.py @@ -13,7 +13,6 @@ from aiogremlin import (submit, GremlinConnector, GremlinClient, class SubmitTest(unittest.TestCase): def setUp(self): - self.uri = 'http://localhost:8182/' self.loop = asyncio.new_event_loop() asyncio.set_event_loop(None) @@ -24,7 +23,7 @@ class SubmitTest(unittest.TestCase): @asyncio.coroutine def go(): - resp = yield from submit("x + x", url=self.uri, + resp = yield from submit("x + x", url='http://localhost:8182/', bindings={"x": 4}, loop=self.loop, username="stephen", password="password") results = yield from resp.get() @@ -37,7 +36,7 @@ class SubmitTest(unittest.TestCase): @asyncio.coroutine def go1(): result = yield from submit("graph2.addVertex()", - url='https://localhost:8182/', + url='http://localhost:8182/', loop=self.loop, username="stephen", password="password") resp = yield from result.get() @@ -52,7 +51,7 @@ class SubmitTest(unittest.TestCase): @asyncio.coroutine def go2(): result = yield from submit( - "graph2.addVertex()", url=self.uri, + "graph2.addVertex()", url='http://localhost:8182/', rebindings={"graph2": "graph"}, loop=self.loop, username="stephen", password="password") resp = yield from result.get() @@ -67,19 +66,10 @@ class SubmitTest(unittest.TestCase): class GremlinClientTest(unittest.TestCase): def setUp(self): - self.uri = 'http://localhost:8182/' self.loop = asyncio.new_event_loop() asyncio.set_event_loop(None) - connector = aiohttp.TCPConnector(force_close=False, loop=self.loop, - verify_ssl=False) - client_session = aiohttp.ClientSession( - connector=connector, loop=self.loop, - ws_response_class=GremlinClientWebSocketResponse) - - self.gc = GremlinClient(url=self.uri, loop=self.loop, - username="stephen", password="password", - client_session=client_session) + self.gc = GremlinClient(url="http://localhost:8182/", loop=self.loop) def tearDown(self): self.loop.run_until_complete(self.gc.close()) @@ -163,20 +153,10 @@ class GremlinClientTest(unittest.TestCase): class GremlinClientSessionTest(unittest.TestCase): def setUp(self): - self.uri = 'http://localhost:8182/' self.loop = asyncio.new_event_loop() asyncio.set_event_loop(None) - connector = aiohttp.TCPConnector(force_close=False, loop=self.loop, - verify_ssl=False) - - client_session = aiohttp.ClientSession( - connector=connector, loop=self.loop, - ws_response_class=GremlinClientWebSocketResponse) - - self.gc = GremlinClientSession(url=self.uri, - loop=self.loop, - username="stephen", password="password", - client_session=client_session) + self.gc = GremlinClientSession(url="http://localhost:8182/", + loop=self.loop) self.script1 = """v=graph.addVertex('name', 'Dave')"""