async def test_good_connectivity(script):
    async with BoltStubService.load(script("v3", "empty.script")) as stub:
        bolt = await Bolt.open(stub.addresses[0], auth=stub.auth)
        assert bolt.remote_address.host in ("localhost", "127.0.0.1", "::1")
        assert bolt.remote_address.port_number == stub.addresses[0].port_number
        assert bolt.local_address.host in ("localhost", "127.0.0.1", "::1")
        await bolt.close()
Exemplo n.º 2
0
async def test_explicit_protocol_version(script):
    async with BoltStubService.load(script("v3", "empty.script")) as stub:
        bolt = await Bolt.open(stub.addresses[0],
                               auth=stub.auth,
                               protocol_version=(3, 0))
        assert bolt.protocol_version == (3, 0)
        await bolt.close()
async def test_return_1(script):
    async with BoltStubService.load(script("v3", "return_1.script")) as stub:
        bolt = await Bolt.open(stub.addresses[0], auth=stub.auth)
        values = []
        async for record in await bolt.run("RETURN $x", {"x": 1}):
            values.append(record[0])
        await bolt.close()
        assert values == [1]
Exemplo n.º 4
0
 async def a():
     scripts = map(BoltScript.load, script)
     service = BoltStubService(*scripts, listen_addr=listen_addr, timeout=timeout)
     try:
         service.start()
         await service.wait_started()
     finally:
         try:
             await service.wait_stopped()
         except ScriptMismatch as error:
             extra = ""
             if error.script.filename:
                 extra += " in {!r}".format(error.script.filename)
             if error.line_no:
                 extra += " at line {}".format(error.line_no)
             print("Script mismatch{}:\n{}".format(extra, error))
             exit(1)
         except TimeoutError as error:
             print(error)
             exit(2)
Exemplo n.º 5
0
async def test_v3_mismatch():

    async with BoltStubService.load(script("v3", "return_1_as_x.bolt")) as service:

        # Given
        with Connection.open(*service.addresses, auth=service.auth) as cx:

            # When
            records = []
            cx.run("RETURN $x", {"x": 2})
            cx.send_all()
            with raises(ScriptMismatch):
                cx.fetch_all()
Exemplo n.º 6
0
async def test_v3():

    async with BoltStubService.load(script("v3", "return_1_as_x.bolt")) as service:

        # Given
        with Connection.open(*service.addresses, auth=service.auth) as cx:

            # When
            records = []
            cx.run("RETURN $x", {"x": 1})
            cx.pull(-1, -1, records)
            cx.send_all()
            cx.fetch_all()

            # Then
            assert records == [[1]]
            assert cx.bolt_version == 3
Exemplo n.º 7
0
async def test_unsupported_old_protocol_version(script):
    # TODO: fix task pending in boltkit that arises from this test
    async with BoltStubService.load(script("v3",
                                           "old_protocol.script")) as stub:
        with raises(BoltHandshakeError) as e:
            await Bolt.open(stub.addresses[0],
                            auth=stub.auth,
                            protocol_version=(3, 0))
        error = e.value
        assert isinstance(error, BoltHandshakeError)
        port = stub.primary_address.port_number
        assert error.address in {("localhost", port), ("127.0.0.1", port),
                                 ("::1", port)}
        assert error.request_data == (b"\x60\x60\xb0\x17"
                                      b"\x00\x00\x00\x03"
                                      b"\x00\x00\x00\x00"
                                      b"\x00\x00\x00\x00"
                                      b"\x00\x00\x00\x00")
        assert error.response_data == b"\x00\x00\x01\x00"
async def test_incomplete_read_on_handshake(script):
    async with BoltStubService.load(script("v3", "incomplete_read_on_handshake.script")) as stub:
        with raises(BoltConnectionBroken) as e:
            await Bolt.open(stub.addresses[0], auth=stub.auth)
        assert isinstance(e.value.__cause__, IncompleteReadError)
async def test_unusable_value_on_handshake(script):
    async with BoltStubService.load(script("v3", "unusable_value_on_handshake.script")) as stub:
        with raises(BoltHandshakeError) as e:
            await Bolt.open(stub.addresses[0], auth=stub.auth)
        assert isinstance(e.value.__cause__, ValueError)
async def test_illegal_protocol_version_type(script):
    async with BoltStubService.load(script("v3", "empty.script")) as stub:
        with raises(TypeError):
            _ = await Bolt.open(stub.addresses[0], auth=stub.auth, protocol_version=object())
async def test_bad_timeout_value(script):
    async with BoltStubService.load(script("v3", "empty.script")) as stub:
        bolt = await Bolt.open(stub.addresses[0], auth=stub.auth)
        with raises(TypeError):
            await bolt.run("RETURN 1", timeout=object())
        await bolt.close()
async def test_good_timeout_value(script):
    async with BoltStubService.load(script("v3", "good_timeout.script")) as stub:
        bolt = await Bolt.open(stub.addresses[0], auth=stub.auth)
        await bolt.run("RETURN 1", timeout=15)
        await bolt.close()
async def test_good_metadata_value(script):
    async with BoltStubService.load(script("v3", "good_metadata.script")) as stub:
        bolt = await Bolt.open(stub.addresses[0], auth=stub.auth)
        await bolt.run("RETURN 1", metadata={"foo": "bar"})
        await bolt.close()
async def test_good_bookmarks_value(script):
    async with BoltStubService.load(script("v3", "good_bookmarks.script")) as stub:
        bolt = await Bolt.open(stub.addresses[0], auth=stub.auth)
        await bolt.run("RETURN 1", bookmarks=["bookmark1"])
        await bolt.close()
async def test_readonly_false(script):
    async with BoltStubService.load(script("v3", "readonly_false.script")) as stub:
        bolt = await Bolt.open(stub.addresses[0], auth=stub.auth)
        await bolt.run("RETURN 1", readonly=False)
        await bolt.close()
Exemplo n.º 16
0
async def test_explicit_unsupported_protocol_version(script):
    async with BoltStubService.load(script("v3", "empty.script")) as stub:
        with raises(ValueError):
            _ = await Bolt.open(stub.addresses[0],
                                auth=stub.auth,
                                protocol_version=(0, 1))