-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_graph_validation.py
More file actions
59 lines (50 loc) · 1.63 KB
/
test_graph_validation.py
File metadata and controls
59 lines (50 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import pytest
from src.models.graph_models import GraphInput, GraphOutput
from src.visualiser_graph_generator import slugify
def test_graph_input_validation():
data = {
"entities": [
{
"id": "e1",
"canonical_key": "test_entity",
"label": "Test Entity",
"aliases": [{"name": "alias1"}, {"name": "alias2"}],
"properties": {"sourceUrls": "s3://bucket/key"},
}
]
}
validated = GraphInput.model_validate(data)
assert len(validated.entities) == 1
assert validated.entities[0].id == "e1"
def test_graph_input_invalid():
data = {
"entities": [
{
"id": "e1",
# missing canonical_key
"label": "Test Entity",
}
]
}
with pytest.raises(Exception):
GraphInput.model_validate(data)
def test_slugify():
assert slugify("Hello World!") == "hello_world"
assert slugify("Test-123") == "test_123"
def test_graph_output_validation():
data = {
"nodes": [{"data": {"id": "e1", "label": "Entity 1", "type": "entity"}}],
"edges": [{"data": {"source": "e1", "target": "a1", "label": "Alias"}}],
"outliers": [
{
"entity_id": "e1",
"entity_label": "Entity 1",
"alias_imbalance": [
{"alias_id": "a1", "alias_label": "Alias", "occurrence_count": 1}
],
}
],
}
validated = GraphOutput.model_validate(data)
assert len(validated.nodes) == 1
assert validated.nodes[0].data.id == "e1"