Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/code-style.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
branches: [ "main" ]
pull_request:
paths:
- "python-wrapper/src/neo4j_viz/**" # python code + its resources
- "python-wrapper/**" # python code + its resources
branches: [ "main" ]

# Allows you to run this workflow manually from the Actions tab
Expand Down
44 changes: 44 additions & 0 deletions .github/workflows/gds-integration-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Run GDS integration tests

# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the "main" branch
push:
branches: [ "main" ]
# Skip on this check PR to reduce number of AuraDS instances created

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
tests:
# The type of runner that the job will run on
runs-on: ${{ matrix.os}}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
defaults:
run:
working-directory: python-wrapper

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: 'pip'
cache-dependency-path: pyproject.toml
- run: pip install ".[dev]"
- run: pip install ".[pandas]"
- run: pip install ".[gds]"

- name: Run tests
env:
AURA_API_CLIENT_ID: 4V1HYCYEeoU4dSxThKnBeLvE2U4hSphx
AURA_API_CLIENT_SECRET: ${{ secrets.AURA_API_CLIENT_SECRET }}
AURA_API_TENANT_ID: eee7ec28-6b1a-5286-8e3a-3362cc1c4c78
run: pytest tests/ --include-neo4j-and-gds -Werror
2 changes: 1 addition & 1 deletion .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
branches: [ "main" ]
pull_request:
paths:
- "python-wrapper/src/neo4j_viz/**" # python code + its resources
- "python-wrapper/**" # python code + its resources
- "python-wrapper/pyproject.toml" # dependencies
branches: [ "main" ]

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Environments
.env
*.env
.venv
env/
venv/
Expand Down
27 changes: 26 additions & 1 deletion python-wrapper/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Any
import os
from typing import Any, Generator

import pytest

Expand All @@ -17,3 +18,27 @@ def pytest_collection_modifyitems(config: Any, items: Any) -> None:
for item in items:
if "requires_neo4j_and_gds" in item.keywords:
item.add_marker(skip)


@pytest.fixture(scope="package")
def gds() -> Generator[Any, None, None]:
from gds_helper import aura_api, connect_to_plugin_gds, create_aurads_instance
from graphdatascience import GraphDataScience

NEO4J_URI = os.environ.get("NEO4J_URI")

if NEO4J_URI:
gds = connect_to_plugin_gds(NEO4J_URI)
yield gds
gds.close()
else:
api = aura_api()
id, dbms_connection_info = create_aurads_instance(api)
yield GraphDataScience(
endpoint=dbms_connection_info.uri,
auth=(dbms_connection_info.username, dbms_connection_info.password),
aura_ds=True,
database="neo4j",
)

api.delete_instance(id)
44 changes: 44 additions & 0 deletions python-wrapper/tests/gds_helper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import os

from graphdatascience import GraphDataScience
from graphdatascience.session import DbmsConnectionInfo, SessionMemory
from graphdatascience.session.aura_api import AuraApi
from graphdatascience.session.aura_api_responses import InstanceCreateDetails


def connect_to_plugin_gds(uri: str) -> GraphDataScience:
NEO4J_AUTH = ("neo4j", "password")
if os.environ.get("NEO4J_USER"):
NEO4J_AUTH = (os.environ.get("NEO4J_USER", "DUMMY"), os.environ.get("NEO4J_PASSWORD", "neo4j"))

return GraphDataScience(endpoint=uri, auth=NEO4J_AUTH, database="neo4j")


def aura_api() -> AuraApi:
return AuraApi(
client_id=os.environ["AURA_API_CLIENT_ID"],
client_secret=os.environ["AURA_API_CLIENT_SECRET"],
tenant_id=os.environ.get("AURA_API_TENANT_ID"),
)


def create_aurads_instance(api: AuraApi) -> tuple[str, DbmsConnectionInfo]:
# Switch to Sessions once they can be created without a DB
instance_details: InstanceCreateDetails = api.create_instance(
name="ci-neo4j-viz-session",
memory=SessionMemory.m_8GB.value,
cloud_provider="gcp",
region="europe-west1",
)

wait_result = api.wait_for_instance_running(instance_id=instance_details.id)
if wait_result.error:
raise Exception(f"Error while waiting for instance to be running: {wait_result.error}")

wait_result.connection_url

return instance_details.id, DbmsConnectionInfo(
uri=wait_result.connection_url,
username="neo4j",
password=instance_details.password,
)
23 changes: 6 additions & 17 deletions python-wrapper/tests/test_gds.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,22 @@
import os
import sys
from typing import Any

import pandas as pd
import pytest
from pytest_mock import MockerFixture

from neo4j_viz import Node

NEO4J_URI = os.environ.get("NEO4J_URI", "bolt://localhost:7687")

NEO4J_AUTH = ("neo4j", "password")
if os.environ.get("NEO4J_USER"):
NEO4J_AUTH = (
os.environ.get("NEO4J_USER", "DUMMY"),
os.environ.get("NEO4J_PASSWORD", "neo4j"),
)


@pytest.mark.skipif(sys.version_info >= (3, 13), reason="requires python 3.12 or lower")
@pytest.mark.requires_neo4j_and_gds
def test_from_gds_integration() -> None:
from graphdatascience import GraphDataScience

def test_from_gds_integration(gds: Any) -> None:
from neo4j_viz.gds import from_gds

nodes = pd.DataFrame(
{
"nodeId": [0, 1, 2],
"labels": ["A", "C", ["A", "B"]],
"labels": [["A"], ["C"], ["A", "B"]],
"score": [1337, 42, 3.14],
"component": [1, 4, 2],
}
Expand All @@ -40,10 +29,10 @@ def test_from_gds_integration() -> None:
}
)

gds = GraphDataScience(NEO4J_URI, auth=NEO4J_AUTH)

with gds.graph.construct("flo", nodes, rels) as G:
VG = from_gds(gds, G, size_property="score", additional_node_properties=["component"])
VG = from_gds(
gds, G, size_property="score", additional_node_properties=["component"], node_radius_min_max=(3.14, 1337)
)

assert len(VG.nodes) == 3
assert sorted(VG.nodes, key=lambda x: x.id) == [
Expand Down