|
1
|
|
|
import pytest |
|
2
|
|
|
|
|
3
|
|
|
import graphinate.builders |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
@pytest.mark.parametrize('execution_number', range(5)) |
|
7
|
|
|
def test_d3_builder__map_graph_model(execution_number, map_graph_model): |
|
8
|
|
|
# arrange |
|
9
|
|
|
country_count, city_count, graph_model = map_graph_model |
|
10
|
|
|
person_count = city_count |
|
11
|
|
|
|
|
12
|
|
|
# act |
|
13
|
|
|
builder = graphinate.builders.D3Builder(graph_model) |
|
14
|
|
|
actual_graph = builder.build() |
|
15
|
|
|
|
|
16
|
|
|
# assert |
|
17
|
|
|
assert actual_graph['directed'] is False |
|
18
|
|
|
assert actual_graph['multigraph'] is False |
|
19
|
|
|
assert actual_graph['graph']['name'] == 'Map' |
|
20
|
|
|
assert actual_graph['graph']['node_types']['country'] == country_count |
|
21
|
|
|
assert actual_graph['graph']['node_types']['city'] == city_count |
|
22
|
|
|
assert len(actual_graph['nodes']) == country_count + city_count + person_count |
|
23
|
|
|
|
|
24
|
|
|
|
|
25
|
|
|
def test_d3_builder__map_graph_model__both_specific_ids(map_graph_model): |
|
26
|
|
|
# arrange |
|
27
|
|
|
_, _, graph_model = map_graph_model |
|
28
|
|
|
|
|
29
|
|
|
# act |
|
30
|
|
|
builder = graphinate.builders.D3Builder(graph_model) |
|
31
|
|
|
actual_graph = builder.build(country_id="1", city_id="1") |
|
32
|
|
|
|
|
33
|
|
|
# assert |
|
34
|
|
|
assert actual_graph['directed'] is False |
|
35
|
|
|
assert actual_graph['multigraph'] is False |
|
36
|
|
|
assert actual_graph['graph']['name'] == 'Map' |
|
37
|
|
|
assert actual_graph['graph']['node_types'].get('city', 0) in (0, 1) |
|
38
|
|
|
assert actual_graph['graph']['node_types']['country'] == 1 |
|
39
|
|
|
assert len(actual_graph['nodes']) in (1, 3) |
|
40
|
|
|
|
|
41
|
|
|
|
|
42
|
|
|
def test_d3_builder_json_format(map_graph_model): |
|
43
|
|
|
# arrange |
|
44
|
|
|
_, _, graph_model = map_graph_model |
|
45
|
|
|
builder = graphinate.builders.D3Builder(graph_model) |
|
46
|
|
|
|
|
47
|
|
|
# act |
|
48
|
|
|
actual_graph = builder.build(values_format='json') |
|
49
|
|
|
|
|
50
|
|
|
# assert |
|
51
|
|
|
|
|
52
|
|
|
assert actual_graph |
|
53
|
|
|
|
|
54
|
|
|
#assert dates where converted to iso |
|
55
|
|
|
|
|
56
|
|
|
# for node in actual_graph['nodes']: |
|
57
|
|
|
# if node.get('value'): |
|
58
|
|
|
# for v in node['value']: |
|
59
|
|
|
# assert isinstance(v, str) |
|
60
|
|
|
# json.loads(v) # Check if it's a valid JSON string |
|
61
|
|
|
|
|
62
|
|
|
|
|
63
|
|
|
def test_d3_builder_invalid_format(map_graph_model): |
|
64
|
|
|
# arrange |
|
65
|
|
|
_, _, graph_model = map_graph_model |
|
66
|
|
|
builder = graphinate.builders.D3Builder(graph_model) |
|
67
|
|
|
|
|
68
|
|
|
# act & assert |
|
69
|
|
|
with pytest.raises(ValueError, match="Invalid values format: invalid_format"): |
|
70
|
|
|
builder.build(values_format='invalid_format') |
|
71
|
|
|
|