|
| 1 | +from typing import Generator |
| 2 | + |
| 3 | +import pytest |
| 4 | + |
| 5 | +from graphdatascience.graph.graph_object import Graph |
| 6 | +from graphdatascience.graph_data_science import GraphDataScience |
| 7 | +from graphdatascience.server_version.server_version import ServerVersion |
| 8 | +from graphdatascience.session.aura_graph_data_science import AuraGraphDataScience |
| 9 | + |
| 10 | + |
| 11 | +@pytest.fixture(autouse=True) |
| 12 | +def G(gds_with_cloud_setup: GraphDataScience) -> Generator[Graph, None, None]: |
| 13 | + gds_with_cloud_setup.run_cypher( |
| 14 | + """ |
| 15 | + CREATE |
| 16 | + (a:Location {name: 'A', population: 1337}), |
| 17 | + (b:Location {name: 'B'}), |
| 18 | + (c:Location {name: 'C'}), |
| 19 | + (d:Location {name: 'D'}), |
| 20 | + (e:Location {name: 'G'}), |
| 21 | + (f:Location {name: 2}), |
| 22 | + (a)-[:ROAD {cost: 50}]->(b), |
| 23 | + (a)-[:ROAD {cost: 50}]->(c), |
| 24 | + (a)-[:ROAD {cost: 100}]->(d), |
| 25 | + (b)-[:ROAD {cost: 40}]->(d), |
| 26 | + (c)-[:ROAD {cost: 40}]->(d), |
| 27 | + (c)-[:ROAD {cost: 80}]->(e), |
| 28 | + (d)-[:ROAD {cost: 30}]->(e), |
| 29 | + (d)-[:ROAD {cost: 80}]->(f), |
| 30 | + (e)-[:ROAD {cost: 40}]->(f) |
| 31 | + """ |
| 32 | + ) |
| 33 | + G, _ = gds_with_cloud_setup.graph.project( |
| 34 | + "g", |
| 35 | + {"Location": {"properties": "population"}}, |
| 36 | + {"ROAD": {"properties": "cost"}}, |
| 37 | + ) |
| 38 | + |
| 39 | + yield G |
| 40 | + |
| 41 | + G.drop() |
| 42 | + gds_with_cloud_setup.run_cypher("MATCH (n) DETACH DELETE n") |
| 43 | + |
| 44 | + |
| 45 | +@pytest.mark.cloud_architecture |
| 46 | +@pytest.mark.compatible_with(min_inclusive=ServerVersion(2, 7, 0)) |
| 47 | +def test_remote_util_as_node(gds_with_cloud_setup: AuraGraphDataScience) -> None: |
| 48 | + id = gds_with_cloud_setup.find_node_id(["Location"], {"name": "A"}) |
| 49 | + result = gds_with_cloud_setup.util.asNode(id) |
| 50 | + assert result["name"] == "A" |
| 51 | + |
| 52 | + |
| 53 | +@pytest.mark.cloud_architecture |
| 54 | +@pytest.mark.compatible_with(min_inclusive=ServerVersion(2, 7, 0)) |
| 55 | +def test_remote_util_as_nodes(gds_with_cloud_setup: AuraGraphDataScience) -> None: |
| 56 | + ids = [ |
| 57 | + gds_with_cloud_setup.find_node_id(["Location"], {"name": "A"}), |
| 58 | + gds_with_cloud_setup.find_node_id(["Location"], {"name": 2}), |
| 59 | + ] |
| 60 | + result = gds_with_cloud_setup.util.asNodes(ids) |
| 61 | + assert len(result) == 2 |
| 62 | + |
| 63 | + |
| 64 | +@pytest.mark.cloud_architecture |
| 65 | +@pytest.mark.compatible_with(min_inclusive=ServerVersion(2, 7, 0)) |
| 66 | +def test_util_nodeProperty(gds_with_cloud_setup: GraphDataScience, G: Graph) -> None: |
| 67 | + id = gds_with_cloud_setup.find_node_id(["Location"], {"name": "A"}) |
| 68 | + result = gds_with_cloud_setup.util.nodeProperty(G, id, "population") |
| 69 | + assert result == 1337 |
0 commit comments