Ejemplo n.º 1
0
async def test_neo4j_http_driver_apoc(httpx_mock: HTTPXMock):
    query = 'call apoc.help("meta")'
    httpx_mock.add_response(url="http://localhost:7474",
                            method="GET",
                            status_code=200)
    httpx_mock.add_response(
        url="http://localhost:7474/db/data/transaction/commit",
        method="POST",
        status_code=200,
        match_content=json.dumps({
            "statements": [{
                "statement": f"{query}"
            }]
        }).encode('utf-8'),
        json={})
    driver = Neo4jHTTPDriver(host='localhost',
                             port='7474',
                             auth=('neo4j', 'somepass'))
    assert driver.check_apoc_support() == True
    httpx_mock.add_response(
        url="http://localhost:7474/db/data/transaction/commit",
        method="POST",
        status_code=500,
        match_content=json.dumps({
            "statements": [{
                "statement": f"{query}"
            }]
        }).encode('utf-8'),
        json={"errors": "apoc not supported"})
    driver = Neo4jHTTPDriver(host='localhost',
                             port='7474',
                             auth=('neo4j', 'somepass'))
    assert driver.check_apoc_support() == False
Ejemplo n.º 2
0
async def test_neo4j_http_driver_run_cypher_fail(httpx_mock: HTTPXMock):
    httpx_mock.add_response(url="http://localhost:7474",
                            method="GET",
                            status_code=200)
    driver = Neo4jHTTPDriver(host='localhost',
                             port='7474',
                             auth=('neo4j', 'somepass'))
    test_response = {"errors": "some_error"}
    query = "some test cypher"

    httpx_mock.add_response(url=driver._full_transaction_path,
                            method='POST',
                            json=test_response,
                            match_content=json.dumps({
                                "statements": [{
                                    "statement": f"{query}"
                                }]
                            }).encode('utf-8'),
                            status_code=500)
    try:
        response = await driver.run(query)
    except:
        assert True
    response = await driver.run(query, return_errors=True)
    assert response == test_response
    # test sync runner
    try:
        response = driver.run_sync(query)
    except:
        assert True
Ejemplo n.º 3
0
def test_neo4j_http_driver_ping_success(httpx_mock: HTTPXMock):
    httpx_mock.add_response(url="http://localhost:7474",
                            method="GET",
                            status_code=200)
    driver = Neo4jHTTPDriver(host='localhost',
                             port='7474',
                             auth=('neo4j', 'somepass'))
Ejemplo n.º 4
0
def test_neo4j_http_driver_ping_fail(httpx_mock: HTTPXMock):
    httpx_mock.add_response(url="http://localhost:7474", method="GET", status_code=500)
    try:
        driver = Neo4jHTTPDriver(host='localhost', port='7474', auth=('neo4j', 'somepass'))
        assert False
    except:
        assert True
Ejemplo n.º 5
0
async def test_driver_convert_to_dict(httpx_mock: HTTPXMock):
    httpx_mock.add_response(url="http://localhost:7474",
                            method="GET",
                            status_code=200)
    driver = Neo4jHTTPDriver(host='localhost',
                             port='7474',
                             auth=('neo4j', 'somepass'))
    sample_resp = {
        "results": [{
            "columns": ["count(n)"],
            "data": [{
                "row": [82513],
                "meta": []
            }]
        }],
        "errors": []
    }
    expected = [{"count(n)": 82513}]
    assert driver.convert_to_dict(sample_resp) == expected