Пример #1
0
class TornadoSessionTest(AsyncTestCase):
    def setUp(self):
        super(TornadoSessionTest, self).setUp()
        self.graph = GraphDatabase("ws://localhost:8182/",
                                   username="******",
                                   password="******")

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

    @gen_test
    def test_no_session(self):
        session = yield self.graph.connect()
        with self.assertRaises(RuntimeError):
            stream = session.send("v = 1+1", processor="session")

    @gen_test
    def test_session_obj_session(self):
        session = yield self.graph.session()
        stream = session.send("v = 1+1")
        resp = yield stream.read()
        stream = session.send("v")
        resp2 = yield stream.read()
        self.assertEqual(resp.data[0], resp2.data[0])
Пример #2
0
class TornadoSessionTest(AsyncTestCase):

    def setUp(self):
        super(TornadoSessionTest, self).setUp()
        self.graph = GraphDatabase("ws://localhost:8182/",
                                   username="******",
                                   password="******")

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

    @gen_test
    def test_no_session(self):
        session = yield self.graph.connect()
        with self.assertRaises(RuntimeError):
            stream = session.send("v = 1+1", processor="session")

    @gen_test
    def test_session_obj_session(self):
        session = yield self.graph.session()
        stream = session.send("v = 1+1")
        resp = yield stream.read()
        stream = session.send("v")
        resp2 = yield stream.read()
        self.assertEqual(resp.data[0], resp2.data[0])
Пример #3
0
 def setUp(self):
     self.loop = trollius.get_event_loop()
     self.graph = GraphDatabase("ws://localhost:8182/",
                                username="******",
                                password="******",
                                loop=self.loop,
                                future_class=Future)
Пример #4
0
        def execute(script):
            future = Future()
            graph = GraphDatabase("ws://localhost:8182/",
                                  username="******",
                                  password="******")
            future_conn = graph.connect()

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

            future_conn.add_done_callback(cb)

            return future
Пример #5
0
        def execute(script):
            future = Future()
            graph = GraphDatabase(
                url="ws://localhost:8182/", username="******", password="******", loop=self.loop, future_class=Future
            )
            future_conn = graph.connect()

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

            future_conn.add_done_callback(cb)

            return future
Пример #6
0
 def setUp(self):
     self.loop = trollius.get_event_loop()
     self.graph = GraphDatabase("ws://localhost:8182/",
                                username="******",
                                password="******",
                                loop=self.loop,
                                future_class=Future)
Пример #7
0
 def setUp(self):
     super(TornadoSessionTest, self).setUp()
     self.loop = self.get_new_ioloop()
     self.loop.make_current()
     self.graph = GraphDatabase("ws://localhost:8182/",
                                username="******",
                                password="******",
                                future_class=Future)
Пример #8
0
    def test_wrong_protocol_exception(self):
        graph = GraphDatabase(url="wss://localhost:8182/", loop=self.loop,
                              future_class=Future)
        @asyncio.coroutine
        def go():
            with self.assertRaises(RuntimeError):
                connection = yield from graph.connect()

        self.loop.run_until_complete(go())
Пример #9
0
    def test_wrong_protocol_exception(self):
        graph = GraphDatabase("wss://localhost:8182/",
                              loop=self.loop,
                              future_class=Future)

        async def go():
            with self.assertRaises(RuntimeError):
                connection = await graph.connect()

        self.loop.run_sync(go)
Пример #10
0
    def test_bad_port_exception(self):
        graph = GraphDatabase(url="ws://localhost:81/",
                              loop=self.loop,
                              future_class=Future)

        async def go():
            with self.assertRaises(RuntimeError):
                connection = await graph.connect()

        self.loop.run_until_complete(go())
Пример #11
0
class TrolliusSessionTest(unittest.TestCase):

    def setUp(self):
        self.loop = trollius.get_event_loop()
        self.graph = GraphDatabase("ws://localhost:8182/",
                                   username="******",
                                   password="******",
                                   future_class=Future)

    def test_manual_session(self):
        @trollius.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])
            session.close()

        self.loop.run_until_complete(go())

    def test_no_session(self):
        @trollius.coroutine
        def go():
            session = yield From(self.graph.connect())
            with self.assertRaises(RuntimeError):
                stream = session.send("v = 1+1", processor="session")

        self.loop.run_until_complete(go())

    def test_session_obj_session(self):
        @trollius.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])

        self.loop.run_until_complete(go())
Пример #12
0
class AsyncioSessionTest(unittest.TestCase):

    def setUp(self):
        self.loop = asyncio.get_event_loop()
        self.graph = GraphDatabase("ws://localhost:8182/",
                                   username="******",
                                   password="******",
                                   future_class=Future)

    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])
            session.close()

        self.loop.run_until_complete(go())

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

        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])

        self.loop.run_until_complete(go())
Пример #13
0
    def test_bad_port_exception(self):
        graph = GraphDatabase(url="ws://localhost:81/",
                              loop=self.loop,
                              future_class=Future)

        @trollius.coroutine
        def go():
            with self.assertRaises(RuntimeError):
                connection = yield From(graph.connect())

        self.loop.run_until_complete(go())
Пример #14
0
 def test_bad_port_exception(self):
     graph = GraphDatabase("ws://localhost:81/")
     with self.assertRaises(RuntimeError):
         connection = yield graph.connect()
Пример #15
0
class TrolliusFactoryConnectTest(unittest.TestCase):
    def setUp(self):
        self.loop = trollius.get_event_loop()
        self.graph = GraphDatabase("ws://localhost:8182/",
                                   username="******",
                                   password="******",
                                   loop=self.loop,
                                   future_class=Future)

    def test_connect(self):
        @trollius.coroutine
        def go():
            connection = yield From(self.graph.connect())
            conn = connection.conn._conn
            self.assertIsNotNone(conn.protocol)
            self.assertIsInstance(conn, WebSocketClientConnection)
            conn.close()

        self.loop.run_until_complete(go())

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

        @trollius.coroutine
        def go():
            with self.assertRaises(RuntimeError):
                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,
                              future_class=Future)

        @trollius.coroutine
        def go():
            with self.assertRaises(RuntimeError):
                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,
    #                           future_class=Future)
    #
    #     @trollius.coroutine
    #     def go():
    #         with self.assertRaises(RuntimeError):
    #             connection = yield From(graph.connect())
    #
    #     self.loop.run_until_complete(go())

    def test_send(self):
        @trollius.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)
            connection.conn.close()

        self.loop.run_until_complete(go())

    def test_handler(self):
        @trollius.coroutine
        def go():
            connection = yield From(self.graph.connect())
            resp = connection.send("1 + 1", handler=lambda x: x[0] * 2)
            while True:
                msg = yield From(resp.read())
                if msg is None:
                    break
                self.assertEqual(msg, 4)
            connection.conn.close()

        self.loop.run_until_complete(go())

    def test_add_handler(self):
        @trollius.coroutine
        def go():
            connection = yield From(self.graph.connect())
            resp = connection.send("1 + 1", handler=lambda x: x[0] * 2)
            resp.add_handler(lambda x: x**2)
            while True:
                msg = yield From(resp.read())
                if msg is None:
                    break
                self.assertEqual(msg, 16)
            connection.conn.close()

        self.loop.run_until_complete(go())

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

        self.loop.run_until_complete(go())

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

        self.loop.run_until_complete(go())

    # def test_creditials_error(self):
    #
    #     @trollius.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):
        @trollius.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())
Пример #16
0
class TornadoFactoryConnectTest(AsyncTestCase):

    def setUp(self):
        super(TornadoFactoryConnectTest, self).setUp()
        self.graph = GraphDatabase("ws://localhost:8182/",
                                   username="******",
                                   password="******")

    @gen_test
    def test_connect(self):
        connection = yield self.graph.connect()
        conn = connection.conn._conn
        self.assertIsNotNone(conn.protocol)
        self.assertIsInstance(conn, WebSocketClientConnection)
        conn.close()

    @gen_test
    def test_bad_port_exception(self):
        graph = GraphDatabase("ws://localhost:81/")
        with self.assertRaises(RuntimeError):
            connection = yield graph.connect()

    @gen_test
    def test_wrong_protocol_exception(self):
        graph = GraphDatabase("wss://localhost:8182/")
        with self.assertRaises(RuntimeError):
            connection = yield graph.connect()

    # Check this out
    # @gen_test
    # def test_bad_host_exception(self):
    #     graph = GraphDatabase("ws://locaost:8182/")
    #     with self.assertRaises(RuntimeError):
    #         connection = yield graph.connect()

    @gen_test
    def test_send(self):
        connection = yield self.graph.connect()
        resp = connection.send("1 + 1")
        while True:
            msg = yield resp.read()
            print(msg)
            if msg is None:
                break
            self.assertEqual(msg.status_code, 200)
            self.assertEqual(msg.data[0], 2)
        resp2 = connection.send("2 + 2")
        while True:
            msg = yield resp2.read()
            print(msg)
            if msg is None:
                break
            self.assertEqual(msg.status_code, 200)
            self.assertEqual(msg.data[0], 4)

        connection.conn.close()

    @gen_test
    def test_handler(self):
        connection = yield self.graph.connect()
        resp = connection.send("1 + 1", handler=lambda x: x[0] * 2)
        while True:
            msg = yield resp.read()
            if msg is None:
                break
            self.assertEqual(msg, 4)
        connection.conn.close()

    @gen_test
    def test_add_handler(self):
        connection = yield self.graph.connect()
        resp = connection.send("1 + 1", handler=lambda x: x[0] * 2)
        resp.add_handler(lambda x: x ** 2)
        while True:
            msg = yield resp.read()
            if msg is None:
                break
            self.assertEqual(msg, 16)
        connection.conn.close()

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

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

    # @gen_test
    # def test_creditials_error(self):
    #     graph = GraphDatabase("ws://localhost:8182/",
    #                             username="******",
    #                             password="******")
    #     connection = yield graph.connect()
    #     resp = connection.send("1 + 1")
    #     with self.assertRaises(RuntimeError):
    #         msg = yield resp.read()
    #     connection.conn.close()

    @gen_test
    def test_force_close(self):
        connection = yield self.graph.connect(force_close=True)
        resp = connection.send("1 + 1")
        while True:
            msg = yield resp.read()
            if msg is None:
                break
            self.assertEqual(msg.status_code, 200)
            self.assertEqual(msg.data[0], 2)
        self.assertTrue(connection.conn.closed)
Пример #17
0
 def test_bad_port_exception(self):
     graph = GraphDatabase("ws://localhost:81/")
     with self.assertRaises(RuntimeError):
         connection = yield graph.connect()
Пример #18
0
 def setUp(self):
     super(TornadoSessionTest, self).setUp()
     self.graph = GraphDatabase("ws://localhost:8182/",
                                username="******",
                                password="******")
Пример #19
0
class TrolliusFactoryConnectTest(unittest.TestCase):

    def setUp(self):
        self.loop = trollius.get_event_loop()
        self.graph = GraphDatabase("ws://localhost:8182/",
                                   username="******",
                                   password="******",
                                   loop=self.loop,
                                   future_class=Future)


    def test_connect(self):

        @trollius.coroutine
        def go():
            connection = yield From(self.graph.connect())
            conn = connection.conn._conn
            self.assertIsNotNone(conn.protocol)
            self.assertIsInstance(conn, WebSocketClientConnection)
            conn.close()

        self.loop.run_until_complete(go())


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

        @trollius.coroutine
        def go():
            with self.assertRaises(RuntimeError):
                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,
                              future_class=Future)
        @trollius.coroutine
        def go():
            with self.assertRaises(RuntimeError):
                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,
    #                           future_class=Future)
    #
    #     @trollius.coroutine
    #     def go():
    #         with self.assertRaises(RuntimeError):
    #             connection = yield From(graph.connect())
    #
    #     self.loop.run_until_complete(go())

    def test_send(self):

        @trollius.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)
            connection.conn.close()

        self.loop.run_until_complete(go())

    def test_handler(self):

        @trollius.coroutine
        def go():
            connection = yield From(self.graph.connect())
            resp = connection.send("1 + 1", handler=lambda x: x[0] * 2)
            while True:
                msg = yield From(resp.read())
                if msg is None:
                    break
                self.assertEqual(msg, 4)
            connection.conn.close()
        self.loop.run_until_complete(go())

    def test_add_handler(self):

        @trollius.coroutine
        def go():
            connection = yield From(self.graph.connect())
            resp = connection.send("1 + 1", handler=lambda x: x[0] * 2)
            resp.add_handler(lambda x: x ** 2)
            while True:
                msg = yield From(resp.read())
                if msg is None:
                    break
                self.assertEqual(msg, 16)
            connection.conn.close()

        self.loop.run_until_complete(go())

    def test_read_one_on_closed(self):

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

        self.loop.run_until_complete(go())

    def test_null_read_on_closed(self):

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

        self.loop.run_until_complete(go())

    # def test_creditials_error(self):
    #
    #     @trollius.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):

        @trollius.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())
Пример #20
0
 def test_wrong_protocol_exception(self):
     graph = GraphDatabase("wss://localhost:8182/")
     with self.assertRaises(RuntimeError):
         connection = yield graph.connect()
Пример #21
0
class TornadoFactoryConnectTest(AsyncTestCase):
    def setUp(self):
        super(TornadoFactoryConnectTest, self).setUp()
        self.graph = GraphDatabase("ws://localhost:8182/",
                                   username="******",
                                   password="******")

    @gen_test
    def test_connect(self):
        connection = yield self.graph.connect()
        conn = connection.conn._conn
        self.assertIsNotNone(conn.protocol)
        self.assertIsInstance(conn, WebSocketClientConnection)
        conn.close()

    @gen_test
    def test_bad_port_exception(self):
        graph = GraphDatabase("ws://localhost:81/")
        with self.assertRaises(RuntimeError):
            connection = yield graph.connect()

    @gen_test
    def test_wrong_protocol_exception(self):
        graph = GraphDatabase("wss://localhost:8182/")
        with self.assertRaises(RuntimeError):
            connection = yield graph.connect()

    # Check this out
    # @gen_test
    # def test_bad_host_exception(self):
    #     graph = GraphDatabase("ws://locaost:8182/")
    #     with self.assertRaises(RuntimeError):
    #         connection = yield graph.connect()

    @gen_test
    def test_send(self):
        connection = yield self.graph.connect()
        resp = connection.send("1 + 1")
        while True:
            msg = yield resp.read()
            print(msg)
            if msg is None:
                break
            self.assertEqual(msg.status_code, 200)
            self.assertEqual(msg.data[0], 2)
        resp2 = connection.send("2 + 2")
        while True:
            msg = yield resp2.read()
            print(msg)
            if msg is None:
                break
            self.assertEqual(msg.status_code, 200)
            self.assertEqual(msg.data[0], 4)

        connection.conn.close()

    @gen_test
    def test_handler(self):
        connection = yield self.graph.connect()
        resp = connection.send("1 + 1", handler=lambda x: x[0] * 2)
        while True:
            msg = yield resp.read()
            if msg is None:
                break
            self.assertEqual(msg, 4)
        connection.conn.close()

    @gen_test
    def test_add_handler(self):
        connection = yield self.graph.connect()
        resp = connection.send("1 + 1", handler=lambda x: x[0] * 2)
        resp.add_handler(lambda x: x**2)
        while True:
            msg = yield resp.read()
            if msg is None:
                break
            self.assertEqual(msg, 16)
        connection.conn.close()

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

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

    # @gen_test
    # def test_creditials_error(self):
    #     graph = GraphDatabase("ws://localhost:8182/",
    #                             username="******",
    #                             password="******")
    #     connection = yield graph.connect()
    #     resp = connection.send("1 + 1")
    #     with self.assertRaises(RuntimeError):
    #         msg = yield resp.read()
    #     connection.conn.close()

    @gen_test
    def test_force_close(self):
        connection = yield self.graph.connect(force_close=True)
        resp = connection.send("1 + 1")
        while True:
            msg = yield resp.read()
            if msg is None:
                break
            self.assertEqual(msg.status_code, 200)
            self.assertEqual(msg.data[0], 2)
        self.assertTrue(connection.conn.closed)
Пример #22
0
 def setUp(self):
     super(TornadoSessionTest, self).setUp()
     self.graph = GraphDatabase("ws://localhost:8182/",
                                username="******",
                                password="******")
Пример #23
0
 def test_wrong_protocol_exception(self):
     graph = GraphDatabase("wss://localhost:8182/")
     with self.assertRaises(RuntimeError):
         connection = yield graph.connect()