|
| 1 | +import pytest |
| 2 | + |
| 3 | +from mcp import ClientSession |
| 4 | +from mcp.client.stdio import stdio_client |
| 5 | +from tigergraphx import Graph |
| 6 | + |
| 7 | +from tests.integration.base_graph_fixture import BaseGraphFixture |
| 8 | +from tigergraph_mcp import TigerGraphToolNames |
| 9 | + |
| 10 | + |
| 11 | +@pytest.mark.skip( |
| 12 | + reason=""" |
| 13 | +Skipped by default. To enable this test, you must manually place the following files in the TigerGraph server: |
| 14 | +
|
| 15 | +1. /home/tigergraph/data/person_data.csv |
| 16 | +Contents: |
| 17 | +name,age |
| 18 | +John,11 |
| 19 | +
|
| 20 | +2. /home/tigergraph/data/friendship_data.csv |
| 21 | +Contents: |
| 22 | +source,target,closeness |
| 23 | +John,John,11 |
| 24 | +""" |
| 25 | +) |
| 26 | +class TestDataTools(BaseGraphFixture): |
| 27 | + def setup_graph(self): |
| 28 | + """Set up the graph shared across all tests.""" |
| 29 | + self.graph_name = "SocialGraph" |
| 30 | + self.graph_schema = { |
| 31 | + "graph_name": self.graph_name, |
| 32 | + "nodes": { |
| 33 | + "Person": { |
| 34 | + "primary_key": "name", |
| 35 | + "attributes": { |
| 36 | + "name": "STRING", |
| 37 | + "age": "INT", |
| 38 | + }, |
| 39 | + }, |
| 40 | + }, |
| 41 | + "edges": { |
| 42 | + "Friendship": { |
| 43 | + "is_directed_edge": False, |
| 44 | + "from_node_type": "Person", |
| 45 | + "to_node_type": "Person", |
| 46 | + "attributes": { |
| 47 | + "closeness": "DOUBLE", |
| 48 | + }, |
| 49 | + }, |
| 50 | + }, |
| 51 | + } |
| 52 | + self.G = Graph( |
| 53 | + graph_schema=self.graph_schema, |
| 54 | + tigergraph_connection_config=self.tigergraph_connection_config, |
| 55 | + ) |
| 56 | + |
| 57 | + @pytest.fixture(autouse=True) |
| 58 | + def setup_files_and_graph(self): |
| 59 | + # Initialize the graph |
| 60 | + self.setup_graph() |
| 61 | + |
| 62 | + yield # The test case runs here |
| 63 | + |
| 64 | + self.G.clear() |
| 65 | + |
| 66 | + @pytest.fixture(scope="class", autouse=True) |
| 67 | + def drop_graph(self): |
| 68 | + """Drop the graph after all tests are done in the session.""" |
| 69 | + yield |
| 70 | + self.setup_graph() |
| 71 | + self.G.drop_graph() |
| 72 | + |
| 73 | + @pytest.mark.asyncio |
| 74 | + async def test_load_data(self): |
| 75 | + loading_job_config = { |
| 76 | + "loading_job_name": "loading_job_Social", |
| 77 | + "files": [ |
| 78 | + { |
| 79 | + "file_alias": "f_person", |
| 80 | + "file_path": "/home/tigergraph/data/person_data.csv", |
| 81 | + "csv_parsing_options": { |
| 82 | + "separator": ",", |
| 83 | + "header": True, |
| 84 | + "EOL": "\\n", |
| 85 | + "quote": "DOUBLE", |
| 86 | + }, |
| 87 | + "node_mappings": [ |
| 88 | + { |
| 89 | + "target_name": "Person", |
| 90 | + "attribute_column_mappings": { |
| 91 | + "name": "name", |
| 92 | + "age": "age", |
| 93 | + }, |
| 94 | + } |
| 95 | + ], |
| 96 | + }, |
| 97 | + { |
| 98 | + "file_alias": "f_friendship", |
| 99 | + "file_path": "/home/tigergraph/data/friendship_data.csv", |
| 100 | + "csv_parsing_options": { |
| 101 | + "separator": ",", |
| 102 | + "header": True, |
| 103 | + "EOL": "\\n", |
| 104 | + "quote": "DOUBLE", |
| 105 | + }, |
| 106 | + "edge_mappings": [ |
| 107 | + { |
| 108 | + "target_name": "Friendship", |
| 109 | + "source_node_column": "source", |
| 110 | + "target_node_column": "target", |
| 111 | + "attribute_column_mappings": { |
| 112 | + "closeness": "closeness", |
| 113 | + }, |
| 114 | + } |
| 115 | + ], |
| 116 | + }, |
| 117 | + ], |
| 118 | + } |
| 119 | + |
| 120 | + async with stdio_client(self.server_params) as (read, write): |
| 121 | + async with ClientSession(read, write) as session: |
| 122 | + await session.initialize() |
| 123 | + result = await session.call_tool( |
| 124 | + TigerGraphToolNames.LOAD_DATA, |
| 125 | + arguments={ |
| 126 | + "graph_name": self.graph_name, |
| 127 | + "loading_job_config": loading_job_config, |
| 128 | + "tigergraph_connection_config": self.tigergraph_connection_config, |
| 129 | + }, |
| 130 | + ) |
| 131 | + assert "Data loaded successfully into graph" in str(result) |
| 132 | + assert self.G.number_of_nodes() == 1 |
| 133 | + assert self.G.number_of_edges() == 1 |
0 commit comments