|
1 | 1 | import pytest |
2 | 2 | from snowflake.snowpark import Session |
3 | | -from snowflake.snowpark.types import LongType, StructField, StructType |
| 3 | +from snowflake.snowpark.types import LongType, StringType, StructField, StructType |
4 | 4 |
|
| 5 | +from neo4j_viz import Relationship |
5 | 6 | from neo4j_viz.node import Node |
6 | 7 | from neo4j_viz.snowflake import from_snowflake |
7 | 8 |
|
@@ -60,13 +61,82 @@ def test_from_snowflake(session_with_minimal_graph: Session) -> None: |
60 | 61 | ) |
61 | 62 |
|
62 | 63 | assert VG.nodes == [ |
63 | | - Node(id=0, caption="NODES", color="#ffdf81", properties={"SNOWFLAKEID": 6, "table": "NODES"}), |
64 | | - Node(id=1, caption="NODES", color="#ffdf81", properties={"SNOWFLAKEID": 7, "table": "NODES"}), |
| 64 | + Node(id=0, caption="NODES", color="#ffdf81", properties={"SNOWFLAKEID": 6}), |
| 65 | + Node(id=1, caption="NODES", color="#ffdf81", properties={"SNOWFLAKEID": 7}), |
65 | 66 | ] |
66 | 67 |
|
67 | 68 | assert len(VG.relationships) == 1 |
68 | 69 |
|
69 | 70 | assert VG.relationships[0].source == 0 |
70 | 71 | assert VG.relationships[0].target == 1 |
71 | 72 | assert VG.relationships[0].caption == "RELS" |
72 | | - assert VG.relationships[0].properties == {"table": "RELS"} |
| 73 | + assert VG.relationships[0].properties == {} |
| 74 | + |
| 75 | + |
| 76 | +@pytest.fixture |
| 77 | +def session_with_custom_caption_graph(session: Session) -> Session: |
| 78 | + """ |
| 79 | + Create a minimal graph with two nodes and one relationship. |
| 80 | + """ |
| 81 | + node_df = session.create_dataframe( |
| 82 | + data=[ |
| 83 | + [6, "Alice"], |
| 84 | + [7, "Bob"], |
| 85 | + [8, "Charlie"], |
| 86 | + ], |
| 87 | + schema=StructType( |
| 88 | + [ |
| 89 | + StructField("NODEID", LongType()), |
| 90 | + StructField("CAPTION", StringType()), |
| 91 | + ] |
| 92 | + ), |
| 93 | + ) |
| 94 | + node_df.write.save_as_table("NODES") |
| 95 | + |
| 96 | + rel_df = session.create_dataframe( |
| 97 | + data=[ |
| 98 | + [6, 7, "KNOWS"], |
| 99 | + [6, 8, "LIKES"], |
| 100 | + ], |
| 101 | + schema=StructType( |
| 102 | + [ |
| 103 | + StructField("SOURCENODEID", LongType()), |
| 104 | + StructField("TARGETNODEID", LongType()), |
| 105 | + StructField("CAPTION", StringType()), |
| 106 | + ] |
| 107 | + ), |
| 108 | + ) |
| 109 | + rel_df.write.save_as_table("RELS") |
| 110 | + |
| 111 | + return session |
| 112 | + |
| 113 | + |
| 114 | +def test_from_snowflake_with_caption(session_with_custom_caption_graph: Session) -> None: |
| 115 | + VG = from_snowflake( |
| 116 | + session_with_custom_caption_graph, |
| 117 | + { |
| 118 | + "nodeTables": ["NODES"], |
| 119 | + "relationshipTables": { |
| 120 | + "RELS": { |
| 121 | + "sourceTable": "NODES", |
| 122 | + "targetTable": "NODES", |
| 123 | + }, |
| 124 | + }, |
| 125 | + }, |
| 126 | + ) |
| 127 | + |
| 128 | + assert VG.nodes == [ |
| 129 | + Node(id=0, caption="Alice", color="#ffdf81", properties={"CAPTION": "Alice", "SNOWFLAKEID": 6}), |
| 130 | + Node(id=1, caption="Bob", color="#c990c0", properties={"CAPTION": "Bob", "SNOWFLAKEID": 7}), |
| 131 | + Node(id=2, caption="Charlie", color="#f79767", properties={"CAPTION": "Charlie", "SNOWFLAKEID": 8}), |
| 132 | + ] |
| 133 | + |
| 134 | + assert len(VG.relationships) == 2 |
| 135 | + # ignore uuid in comparison |
| 136 | + VG.relationships[0].id = 0 |
| 137 | + VG.relationships[1].id = 1 |
| 138 | + |
| 139 | + assert VG.relationships == [ |
| 140 | + Relationship(id=0, source=0, target=1, caption="KNOWS", properties={"CAPTION": "KNOWS"}), |
| 141 | + Relationship(id=1, source=0, target=2, caption="LIKES", properties={"CAPTION": "LIKES"}), |
| 142 | + ] |
0 commit comments