|
1 | 1 | import pytest |
2 | 2 |
|
3 | 3 | from arangoasync.exceptions import GraphCreateError, GraphDeleteError, GraphListError |
| 4 | +from tests.helpers import generate_graph_name |
4 | 5 |
|
5 | 6 |
|
6 | 7 | @pytest.mark.asyncio |
7 | 8 | async def test_graph_basic(db, bad_db): |
| 9 | + graph1_name = generate_graph_name() |
8 | 10 | # Test the graph representation |
9 | | - graph = db.graph("test_graph") |
10 | | - assert graph.name == "test_graph" |
11 | | - assert "test_graph" in repr(graph) |
| 11 | + graph = db.graph(graph1_name) |
| 12 | + assert graph.name == graph1_name |
| 13 | + assert graph1_name in repr(graph) |
12 | 14 |
|
13 | 15 | # Cannot find any graph |
| 16 | + graph2_name = generate_graph_name() |
14 | 17 | assert await db.graphs() == [] |
15 | | - assert await db.has_graph("fake_graph") is False |
| 18 | + assert await db.has_graph(graph2_name) is False |
16 | 19 | with pytest.raises(GraphListError): |
17 | | - await bad_db.has_graph("fake_graph") |
| 20 | + await bad_db.has_graph(graph2_name) |
18 | 21 | with pytest.raises(GraphListError): |
19 | 22 | await bad_db.graphs() |
20 | 23 |
|
21 | 24 | # Create a graph |
22 | | - graph = await db.create_graph("test_graph", wait_for_sync=True) |
23 | | - assert graph.name == "test_graph" |
| 25 | + graph = await db.create_graph(graph1_name, wait_for_sync=True) |
| 26 | + assert graph.name == graph1_name |
24 | 27 | with pytest.raises(GraphCreateError): |
25 | | - await bad_db.create_graph("test_graph") |
| 28 | + await bad_db.create_graph(graph1_name) |
26 | 29 |
|
27 | 30 | # Check if the graph exists |
28 | | - assert await db.has_graph("test_graph") is True |
| 31 | + assert await db.has_graph(graph1_name) is True |
29 | 32 | graphs = await db.graphs() |
30 | 33 | assert len(graphs) == 1 |
31 | | - assert graphs[0].name == "test_graph" |
| 34 | + assert graphs[0].name == graph1_name |
32 | 35 |
|
33 | 36 | # Delete the graph |
34 | | - await db.delete_graph("test_graph") |
35 | | - assert await db.has_graph("test_graph") is False |
| 37 | + await db.delete_graph(graph1_name) |
| 38 | + assert await db.has_graph(graph1_name) is False |
36 | 39 | with pytest.raises(GraphDeleteError): |
37 | | - await bad_db.delete_graph("test_graph") |
| 40 | + await bad_db.delete_graph(graph1_name) |
| 41 | + |
| 42 | + |
| 43 | +async def test_graph_properties(db): |
| 44 | + # Create a graph |
| 45 | + name = generate_graph_name() |
| 46 | + graph = await db.create_graph(name) |
| 47 | + |
| 48 | + # Get the properties of the graph |
| 49 | + properties = await graph.properties() |
| 50 | + assert properties.name == name |
0 commit comments