mirror of
https://github.com/reconurge/flowsint.git
synced 2026-05-03 09:59:45 -05:00
feat: toolbar actions
This commit is contained in:
0
flowsint-api/tests/api/__init__.py
Normal file
0
flowsint-api/tests/api/__init__.py
Normal file
27
flowsint-api/tests/api/edges.py
Normal file
27
flowsint-api/tests/api/edges.py
Normal file
@@ -0,0 +1,27 @@
|
||||
from fastapi.testclient import TestClient
|
||||
from unittest.mock import patch, MagicMock
|
||||
from app.main import app
|
||||
|
||||
client = TestClient(app)
|
||||
|
||||
def test_add_edge_success():
|
||||
sketch_id = "sketch-123"
|
||||
edge_input = {
|
||||
"from_node": {"uuid": "node-1"},
|
||||
"to_node": {"uuid": "node-2"},
|
||||
"type": "HAS_SUBDOMAIN"
|
||||
}
|
||||
|
||||
mock_result = [{"r": {"type": "HAS_SUBDOMAIN", "sketch_id": sketch_id}}]
|
||||
|
||||
with patch("main.neo4j_connection.query", return_value=mock_result) as mock_query:
|
||||
response = client.post(f"/sketch/{sketch_id}/edges/add", json=edge_input)
|
||||
|
||||
assert response.status_code == 200
|
||||
assert response.json()["status"] == "edge added"
|
||||
assert response.json()["edge"]["sketch_id"] == sketch_id
|
||||
|
||||
expected_query_part = "MERGE (a)-[r:`HAS_SUBDOMAIN`"
|
||||
args, kwargs = mock_query.call_args
|
||||
assert expected_query_part in args[0]
|
||||
assert kwargs is None or kwargs.get("sketch_id") == sketch_id
|
||||
44
flowsint-api/tests/api/nodes.py
Normal file
44
flowsint-api/tests/api/nodes.py
Normal file
@@ -0,0 +1,44 @@
|
||||
from fastapi.testclient import TestClient
|
||||
from unittest.mock import patch
|
||||
from app.main import app
|
||||
|
||||
client = TestClient(app)
|
||||
|
||||
def test_add_node_success():
|
||||
sketch_id = "sketch-abc"
|
||||
node_payload = {
|
||||
"type": "Domain",
|
||||
"data": {
|
||||
"label": "example.com",
|
||||
"color": "#ff0000",
|
||||
"ip": "1.2.3.4"
|
||||
}
|
||||
}
|
||||
|
||||
# Mock de la réponse Neo4j attendue
|
||||
mock_result = [{
|
||||
"node": {
|
||||
"uuid": "node-uuid-123",
|
||||
"type": "Domain",
|
||||
"label": "example.com",
|
||||
"color": "#ff0000",
|
||||
"ip": "1.2.3.4",
|
||||
"caption": "example.com",
|
||||
"size": 40,
|
||||
"sketch_id": sketch_id,
|
||||
}
|
||||
}]
|
||||
|
||||
with patch("main.neo4j_connection.query", return_value=mock_result) as mock_query:
|
||||
response = client.post(f"/sketch/{sketch_id}/nodes/add", json=node_payload)
|
||||
|
||||
assert response.status_code == 200
|
||||
json_data = response.json()
|
||||
assert json_data["status"] == "node added"
|
||||
assert json_data["node"]["label"] == "example.com"
|
||||
assert json_data["node"]["data"] == node_payload["data"]
|
||||
|
||||
# Vérifie qu'on a bien appelé Neo4j avec une requête contenant MERGE et le bon type
|
||||
args, kwargs = mock_query.call_args
|
||||
assert f"MERGE (d:`{node_payload['type']}`" in args[0]
|
||||
assert kwargs is None or kwargs.get("sketch_id") == sketch_id
|
||||
Reference in New Issue
Block a user