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
37 changes: 37 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Tests

on:
pull_request:
push:
branches:
- main

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
test:
name: Python tests
runs-on: ubuntu-latest
permissions:
contents: read

steps:
- name: Checkout repository
uses: actions/checkout@v6

- name: Install uv
uses: astral-sh/setup-uv@v7
with:
enable-cache: true

# Same entrypoint as local development — keeps CI and `make test` in sync.
- name: Run tests
run: make test
env:
# flowsint_core hard-requires these at import time (provided by .env
# locally). Dummy values — no service is reached during tests:
# connections (redis.from_url, create_engine) are lazy.
AUTH_SECRET: ci-only-dummy-secret
REDIS_URL: redis://127.0.0.1:6379/0
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ test:
cd flowsint-types && uv run pytest
cd flowsint-core && uv run pytest
cd flowsint-enrichers && uv run pytest
cd flowsint-api && uv run pytest

install:
$(MAKE) infra-dev
Expand Down
1 change: 1 addition & 0 deletions flowsint-core/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ dependencies = [
"redis>=5.0,<6.0",
"celery>=5.3,<6.0",
"python-dotenv>=1.0,<2.0",
"pyyaml>=6.0,<7.0",
"requests>=2.31,<3.0",
"httpx>=0.28,<0.29",
"networkx>=2.6.3,<3.0.0",
Expand Down
6 changes: 6 additions & 0 deletions flowsint-core/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ def setup_test_environment(monkeypatch):
# Set a test master key for vault tests
test_key = "base64:qnHTmwYb+uoygIw9MsRMY22vS5YPchY+QOi/E79GAvM="
monkeypatch.setenv("MASTER_VAULT_KEY_V1", test_key)
# Dummy Neo4j credentials: the Neo4jConnection singleton requires them
# at construction, but driver creation is lazy — nothing connects.
# Without these, tests silently depend on the developer's local .env.
monkeypatch.setenv("NEO4J_URI_BOLT", "bolt://127.0.0.1:7687")
monkeypatch.setenv("NEO4J_USERNAME", "neo4j")
monkeypatch.setenv("NEO4J_PASSWORD", "test-password")


@pytest.fixture(autouse=True)
Expand Down
65 changes: 29 additions & 36 deletions flowsint-core/tests/core/graph/test_graph_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@
from flowsint_core.core.graph import Neo4jGraphRepository


def repo_without_connection() -> Neo4jGraphRepository:
"""Repository with no underlying connection.

Constructed with a mock to avoid the constructor's singleton fallback,
which requires NEO4J_* credentials from the environment.
"""
repo = Neo4jGraphRepository(neo4j_connection=MagicMock())
repo._connection = None
return repo


class TestNeo4jGraphRepositoryInit:
def test_init_with_connection(self):
mock_connection = MagicMock()
Expand Down Expand Up @@ -43,8 +54,7 @@ def test_create_node_success(self):
mock_connection.query.assert_called_once()

def test_create_node_no_connection(self):
repo = Neo4jGraphRepository(neo4j_connection=None)
repo._connection = None
repo = repo_without_connection()

result = repo.create_node({"nodeLabel": "test", "nodeType": "domain"}, "sketch-1")

Expand Down Expand Up @@ -80,8 +90,7 @@ def test_create_relationship_success(self):
mock_connection.execute_write.assert_called_once()

def test_create_relationship_no_connection(self):
repo = Neo4jGraphRepository(neo4j_connection=None)
repo._connection = None
repo = repo_without_connection()

rel_obj = {
"from_type": "domain",
Expand Down Expand Up @@ -231,8 +240,7 @@ def test_flush_batch_empty(self):
mock_connection.execute_batch.assert_not_called()

def test_flush_batch_no_connection(self):
repo = Neo4jGraphRepository(neo4j_connection=None)
repo._connection = None
repo = repo_without_connection()
repo._batch_operations = [("query", {})]

repo.flush_batch()
Expand Down Expand Up @@ -285,8 +293,7 @@ def test_batch_create_nodes_success(self):
assert result["errors"] == []

def test_batch_create_nodes_no_connection(self):
repo = Neo4jGraphRepository(neo4j_connection=None)
repo._connection = None
repo = repo_without_connection()

result = repo.batch_create_nodes(
[{"nodeLabel": "test", "nodeType": "domain"}], sketch_id="sketch-1"
Expand Down Expand Up @@ -338,8 +345,7 @@ def test_batch_create_edges_success(self):
assert result["errors"] == []

def test_batch_create_edges_no_connection(self):
repo = Neo4jGraphRepository(neo4j_connection=None)
repo._connection = None
repo = repo_without_connection()

result = repo.batch_create_edges([{}], sketch_id="sketch-1")

Expand Down Expand Up @@ -385,8 +391,7 @@ def test_batch_create_edges_by_element_id_missing_fields(self):
assert any("Missing required fields" in e for e in result["errors"])

def test_batch_create_edges_by_element_id_no_connection(self):
repo = Neo4jGraphRepository(neo4j_connection=None)
repo._connection = None
repo = repo_without_connection()

result = repo.batch_create_edges_by_element_id([{}], sketch_id="sketch-1")

Expand All @@ -409,8 +414,7 @@ def test_update_node_success(self):
assert result == "elem-1"

def test_update_node_no_connection(self):
repo = Neo4jGraphRepository(neo4j_connection=None)
repo._connection = None
repo = repo_without_connection()

result = repo.update_node("elem-1", {"nodeLabel": "x"}, "sketch-1")

Expand All @@ -428,8 +432,7 @@ def test_delete_nodes_success(self):
assert result == 3

def test_delete_nodes_no_connection(self):
repo = Neo4jGraphRepository(neo4j_connection=None)
repo._connection = None
repo = repo_without_connection()

result = repo.delete_nodes(["id-1"], sketch_id="sketch-1")

Expand All @@ -456,8 +459,7 @@ def test_delete_relationships_success(self):
assert result == 2

def test_delete_relationships_no_connection(self):
repo = Neo4jGraphRepository(neo4j_connection=None)
repo._connection = None
repo = repo_without_connection()

result = repo.delete_relationships(["rel-1"], sketch_id="sketch-1")

Expand All @@ -483,8 +485,7 @@ def test_delete_all_sketch_nodes_success(self):
assert result == 10

def test_delete_all_sketch_nodes_no_connection(self):
repo = Neo4jGraphRepository(neo4j_connection=None)
repo._connection = None
repo = repo_without_connection()

result = repo.delete_all_sketch_nodes(sketch_id="sketch-1")

Expand Down Expand Up @@ -519,8 +520,7 @@ def test_get_sketch_graph_success(self):
assert len(result["edges"]) == 1

def test_get_sketch_graph_no_connection(self):
repo = Neo4jGraphRepository(neo4j_connection=None)
repo._connection = None
repo = repo_without_connection()

result = repo.get_sketch_graph(sketch_id="sketch-1")

Expand Down Expand Up @@ -553,8 +553,7 @@ def test_update_relationship_success(self):
assert result["id"] == "rel-1"

def test_update_relationship_no_connection(self):
repo = Neo4jGraphRepository(neo4j_connection=None)
repo._connection = None
repo = repo_without_connection()

result = repo.update_relationship("rel-1", {}, "sketch-1")

Expand All @@ -577,8 +576,7 @@ def test_create_relationship_by_element_id_success(self):
assert result["sketch_id"] == "sketch-1"

def test_create_relationship_by_element_id_no_connection(self):
repo = Neo4jGraphRepository(neo4j_connection=None)
repo._connection = None
repo = repo_without_connection()

result = repo.create_relationship_by_element_id(
"elem-1", "elem-2", "CONNECTS", "sketch-1"
Expand All @@ -598,8 +596,7 @@ def test_query_success(self):
assert result == [{"count": 5}]

def test_query_no_connection(self):
repo = Neo4jGraphRepository(neo4j_connection=None)
repo._connection = None
repo = repo_without_connection()

result = repo.query("MATCH (n) RETURN n", {})

Expand All @@ -622,8 +619,7 @@ def test_update_nodes_positions_success(self):
assert result == 2

def test_update_nodes_positions_no_connection(self):
repo = Neo4jGraphRepository(neo4j_connection=None)
repo._connection = None
repo = repo_without_connection()

result = repo.update_nodes_positions([{"nodeId": "x", "x": 0, "y": 0}], "s")

Expand Down Expand Up @@ -652,8 +648,7 @@ def test_get_nodes_by_ids_success(self):
assert len(result) == 2

def test_get_nodes_by_ids_no_connection(self):
repo = Neo4jGraphRepository(neo4j_connection=None)
repo._connection = None
repo = repo_without_connection()

result = repo.get_nodes_by_ids(["id-1"], sketch_id="sketch-1")

Expand Down Expand Up @@ -706,8 +701,7 @@ def test_merge_nodes_reuse_existing_node(self):
assert result == "old-1"

def test_merge_nodes_no_connection(self):
repo = Neo4jGraphRepository(neo4j_connection=None)
repo._connection = None
repo = repo_without_connection()

result = repo.merge_nodes(["old-1"], {}, None, "sketch-1")

Expand Down Expand Up @@ -764,8 +758,7 @@ def test_get_neighbors_no_relationships(self):
assert len(result["edges"]) == 0

def test_get_neighbors_no_connection(self):
repo = Neo4jGraphRepository(neo4j_connection=None)
repo._connection = None
repo = repo_without_connection()

result = repo.get_neighbors("node-1", "sketch-1")

Expand Down
13 changes: 13 additions & 0 deletions flowsint-enrichers/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@
from tests.logger import TestLogger


@pytest.fixture(autouse=True)
def setup_test_environment(monkeypatch):
"""Set up test environment variables.

Dummy Neo4j credentials: the Neo4jConnection singleton requires them
at construction, but driver creation is lazy — nothing connects.
Without these, tests silently depend on the developer's local .env.
"""
monkeypatch.setenv("NEO4J_URI_BOLT", "bolt://127.0.0.1:7687")
monkeypatch.setenv("NEO4J_USERNAME", "neo4j")
monkeypatch.setenv("NEO4J_PASSWORD", "test-password")


@pytest.fixture(autouse=True)
def mock_logger(monkeypatch):
"""Automatically replace the production Logger with TestLogger for all tests."""
Expand Down
2 changes: 2 additions & 0 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.