Ejemplo n.º 1
0
 def setUp(self):
     self.loop = asyncio.new_event_loop()
     asyncio.set_event_loop(None)
     self.graph = GraphDatabase("ws://localhost:8182/",
                                username="******",
                                password="******",
                                loop=self.loop)
Ejemplo n.º 2
0
class AsyncioSessionTest(unittest.TestCase):

    def setUp(self):
        self.loop = asyncio.new_event_loop()
        asyncio.set_event_loop(None)
        self.graph = GraphDatabase("ws://localhost:8182/",
                                   username="******",
                                   password="******",
                                   loop=self.loop)

    def tearDown(self):
        self.loop.close()

    def test_manual_session(self):
        @asyncio.coroutine
        def go():
            session = yield from self.graph.connect(session=str(uuid.uuid4()))
            stream = session.send("v = 1+1", processor="session")
            resp = yield from stream.read()
            stream = session.send("v", processor="session")
            resp2 = yield from stream.read()
            self.assertEqual(resp.data[0], resp2.data[0])
            yield from session.close()

        self.loop.run_until_complete(go())

    def test_no_session(self):
        @asyncio.coroutine
        def go():
            session = yield from self.graph.connect()
            try:
                with self.assertRaises(RuntimeError):
                    stream = session.send("v = 1+1", processor="session")
            finally:
                yield from session.close()

        self.loop.run_until_complete(go())

    def test_session_obj_session(self):
        @asyncio.coroutine
        def go():
            session = yield from self.graph.session()
            stream = session.send("v = 1+1")
            resp = yield from stream.read()
            stream = session.send("v")
            resp2 = yield from stream.read()
            self.assertEqual(resp.data[0], resp2.data[0])
            yield from session.close()
        self.loop.run_until_complete(go())
Ejemplo n.º 3
0
class AsyncioSessionTest(unittest.TestCase):
    def setUp(self):
        self.loop = asyncio.new_event_loop()
        asyncio.set_event_loop(None)
        self.graph = GraphDatabase("ws://localhost:8182/",
                                   username="******",
                                   password="******",
                                   loop=self.loop)

    def tearDown(self):
        self.loop.close()

    def test_manual_session(self):
        @asyncio.coroutine
        def go():
            session = yield from self.graph.connect(session=str(uuid.uuid4()))
            stream = session.send("v = 1+1", processor="session")
            resp = yield from stream.read()
            stream = session.send("v", processor="session")
            resp2 = yield from stream.read()
            self.assertEqual(resp.data[0], resp2.data[0])
            yield from session.close()

        self.loop.run_until_complete(go())

    def test_no_session(self):
        @asyncio.coroutine
        def go():
            session = yield from self.graph.connect()
            try:
                with self.assertRaises(RuntimeError):
                    stream = session.send("v = 1+1", processor="session")
            finally:
                yield from session.close()

        self.loop.run_until_complete(go())

    def test_session_obj_session(self):
        @asyncio.coroutine
        def go():
            session = yield from self.graph.session()
            stream = session.send("v = 1+1")
            resp = yield from stream.read()
            stream = session.send("v")
            resp2 = yield from stream.read()
            self.assertEqual(resp.data[0], resp2.data[0])
            yield from session.close()

        self.loop.run_until_complete(go())
Ejemplo n.º 4
0
 def setUp(self):
     self.loop = asyncio.new_event_loop()
     asyncio.set_event_loop(None)
     self.graph = GraphDatabase("ws://localhost:8182/",
                                username="******",
                                password="******",
                                loop=self.loop)
Ejemplo n.º 5
0
        def execute(script):
            future = asyncio.Future(loop=self.loop)
            graph = GraphDatabase(url="ws://localhost:8182/",
                                  username="******",
                                  password="******",
                                  loop=self.loop)
            future_conn = graph.connect(force_close=True)

            def cb(f):
                conn = f.result()
                stream = conn.send(script)
                future.set_result(stream)

            future_conn.add_done_callback(cb)

            return future
Ejemplo n.º 6
0
        def execute(script):
            future = asyncio.Future(loop=self.loop)
            graph = GraphDatabase(url="ws://localhost:8182/",
                                  username="******",
                                  password="******",
                                  loop=self.loop)
            future_conn = graph.connect(force_close=True)

            def cb(f):
                conn = f.result()
                stream = conn.send(script)
                future.set_result(stream)

            future_conn.add_done_callback(cb)

            return future
Ejemplo n.º 7
0
    def test_bad_host_exception(self):
        graph = GraphDatabase(url="ws://locaost:8182/", loop=self.loop)

        async def go():
            with self.assertRaises(aiohttp.errors.ClientOSError):
                connection = await graph.connect()

        self.loop.run_until_complete(go())
Ejemplo n.º 8
0
    def test_wrong_protocol_exception(self):
        graph = GraphDatabase(url="wss://localhost:8182/", loop=self.loop)

        @asyncio.coroutine
        def go():
            with self.assertRaises(aiohttp.errors.ClientOSError):
                connection = yield from graph.connect()

        self.loop.run_until_complete(go())
Ejemplo n.º 9
0
    def test_bad_port_exception(self):
        graph = GraphDatabase(url="ws://localhost:81/", loop=self.loop)

        @asyncio.coroutine
        def go():
            # Need to fix all these errors
            with self.assertRaises(aiohttp.errors.ClientOSError):
                connection = yield from graph.connect()

        self.loop.run_until_complete(go())
Ejemplo n.º 10
0
class AsyncioFactoryConnectTest(unittest.TestCase):

    def setUp(self):
        self.loop = asyncio.new_event_loop()
        asyncio.set_event_loop(None)
        self.graph = GraphDatabase("ws://localhost:8182/",
                                   username="******",
                                   password="******",
                                   loop=self.loop)

    def tearDown(self):
        self.loop.close()


    def test_connect(self):

        @asyncio.coroutine
        def go():
            connection = yield from self.graph.connect()
            conn = connection.conn
            self.assertFalse(conn.closed)
            self.assertIsInstance(
                conn._conn, aiohttp.websocket_client.ClientWebSocketResponse)
            yield from connection.close()

        self.loop.run_until_complete(go())

    def test_bad_port_exception(self):
        graph = GraphDatabase(url="ws://localhost:81/", loop=self.loop)

        @asyncio.coroutine
        def go():
            # Need to fix all these errors
            with self.assertRaises(aiohttp.errors.ClientOSError):
                connection = yield from graph.connect()


        self.loop.run_until_complete(go())


    def test_wrong_protocol_exception(self):
        graph = GraphDatabase(url="wss://localhost:8182/", loop=self.loop)

        @asyncio.coroutine
        def go():
            with self.assertRaises(aiohttp.errors.ClientOSError):
                connection = yield from graph.connect()

        self.loop.run_until_complete(go())

    def test_bad_host_exception(self):
        graph = GraphDatabase(url="ws://locaost:8182/", loop=self.loop)

        @asyncio.coroutine
        def go():
            with self.assertRaises(aiohttp.errors.ClientOSError):
                connection = yield from graph.connect()

        self.loop.run_until_complete(go())

    def test_send(self):

        @asyncio.coroutine
        def go():
            connection = yield from self.graph.connect()
            resp = connection.send("1 + 1")
            while True:
                msg = yield from resp.read()
                if msg is None:
                    break
                self.assertEqual(msg.status_code, 200)
                self.assertEqual(msg.data[0], 2)
            yield from connection.close()

        self.loop.run_until_complete(go())

    def test_read_one_on_closed(self):

        @asyncio.coroutine
        def go():
            connection = yield from self.graph.connect()
            resp = connection.send("1 + 1")
            yield from connection.close()
            with self.assertRaises(RuntimeError):
                msg = yield from resp.read()
        self.loop.run_until_complete(go())

    def test_null_read_on_closed(self):

        @asyncio.coroutine
        def go():
            connection = yield from self.graph.connect()
            # build connection
            yield from connection.close()
            stream = Stream(connection, None, "processor", None, self.loop,
                            "stephen", "password", False, False,
                            asyncio.Future)
            with self.assertRaises(RuntimeError):
                msg = yield from stream.read()

        self.loop.run_until_complete(go())
#     #
#     # def test_creditials_error(self):
#     #
#     #     @asyncio.coroutine
#     #     def go():
#     #         graph = GraphDatabase("ws://localhost:8182/",
#     #                               username="******",
#     #                               password="******",
#     #                               loop=self.loop,
#     #                               future_class=Future)
#     #         connection = yield from graph.connect()
#     #         resp = connection.send("1 + 1")
#     #         with self.assertRaises(RuntimeError):
#     #             msg = yield from resp.read()
#     #         connection.conn.close()
#     #
#     #     self.loop.run_until_complete(go())
# #
    def test_force_close(self):

        @asyncio.coroutine
        def go():
            connection = yield from self.graph.connect(force_close=True)
            resp = connection.send("1 + 1")
            while True:
                msg = yield from resp.read()
                if msg is None:
                    break
                self.assertEqual(msg.status_code, 200)
                self.assertEqual(msg.data[0], 2)
            self.assertTrue(connection.conn.closed)

        self.loop.run_until_complete(go())
Ejemplo n.º 11
0
class AsyncioFactoryConnectTest(unittest.TestCase):
    def setUp(self):
        self.loop = asyncio.new_event_loop()
        asyncio.set_event_loop(None)
        self.graph = GraphDatabase("ws://localhost:8182/",
                                   username="******",
                                   password="******",
                                   loop=self.loop)

    def tearDown(self):
        self.loop.close()

    def test_connect(self):
        @asyncio.coroutine
        def go():
            connection = yield from self.graph.connect()
            conn = connection.conn
            self.assertFalse(conn.closed)
            self.assertIsInstance(
                conn._conn, aiohttp.websocket_client.ClientWebSocketResponse)
            yield from connection.close()

        self.loop.run_until_complete(go())

    def test_bad_port_exception(self):
        graph = GraphDatabase(url="ws://localhost:81/", loop=self.loop)

        @asyncio.coroutine
        def go():
            # Need to fix all these errors
            with self.assertRaises(aiohttp.errors.ClientOSError):
                connection = yield from graph.connect()

        self.loop.run_until_complete(go())

    def test_wrong_protocol_exception(self):
        graph = GraphDatabase(url="wss://localhost:8182/", loop=self.loop)

        @asyncio.coroutine
        def go():
            with self.assertRaises(aiohttp.errors.ClientOSError):
                connection = yield from graph.connect()

        self.loop.run_until_complete(go())

    def test_bad_host_exception(self):
        graph = GraphDatabase(url="ws://locaost:8182/", loop=self.loop)

        @asyncio.coroutine
        def go():
            with self.assertRaises(aiohttp.errors.ClientOSError):
                connection = yield from graph.connect()

        self.loop.run_until_complete(go())

    def test_send(self):
        @asyncio.coroutine
        def go():
            connection = yield from self.graph.connect()
            resp = connection.send("1 + 1")
            while True:
                msg = yield from resp.read()
                if msg is None:
                    break
                self.assertEqual(msg.status_code, 200)
                self.assertEqual(msg.data[0], 2)
            yield from connection.close()

        self.loop.run_until_complete(go())

    def test_read_one_on_closed(self):
        @asyncio.coroutine
        def go():
            connection = yield from self.graph.connect()
            resp = connection.send("1 + 1")
            yield from connection.close()
            with self.assertRaises(RuntimeError):
                msg = yield from resp.read()

        self.loop.run_until_complete(go())

    def test_null_read_on_closed(self):
        @asyncio.coroutine
        def go():
            connection = yield from self.graph.connect()
            # build connection
            yield from connection.close()
            stream = Stream(connection, None, "processor", None, self.loop,
                            "stephen", "password", False, False,
                            asyncio.Future)
            with self.assertRaises(RuntimeError):
                msg = yield from stream.read()

        self.loop.run_until_complete(go())
#     #
#     # def test_creditials_error(self):
#     #
#     #     @asyncio.coroutine
#     #     def go():
#     #         graph = GraphDatabase("ws://localhost:8182/",
#     #                               username="******",
#     #                               password="******",
#     #                               loop=self.loop,
#     #                               future_class=Future)
#     #         connection = yield from graph.connect()
#     #         resp = connection.send("1 + 1")
#     #         with self.assertRaises(RuntimeError):
#     #             msg = yield from resp.read()
#     #         connection.conn.close()
#     #
#     #     self.loop.run_until_complete(go())
# #

    def test_force_close(self):
        @asyncio.coroutine
        def go():
            connection = yield from self.graph.connect(force_close=True)
            resp = connection.send("1 + 1")
            while True:
                msg = yield from resp.read()
                if msg is None:
                    break
                self.assertEqual(msg.status_code, 200)
                self.assertEqual(msg.data[0], 2)
            self.assertTrue(connection.conn.closed)

        self.loop.run_until_complete(go())