Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
shivamka1 committed Aug 5, 2024
1 parent 001c40a commit ba92bbb
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 104 deletions.
32 changes: 32 additions & 0 deletions python/tests/test_graphql.py
Original file line number Diff line number Diff line change
Expand Up @@ -2535,3 +2535,35 @@ def test_graph_properties_query():
json_ra["graph"]["nodes"]["list"][0]["properties"]["temporal"]["values"],
key=lambda x: x["key"],
)


def test_load_graph_from_path():
tmp_graph_dir = tempfile.mkdtemp()

g = Graph()
g.add_edge(1, "ben", "hamza")
g.add_edge(2, "haaroon", "hamza")
g.add_edge(3, "ben", "haaroon")
g_file_path = os.path.join(tmp_graph_dir, "g")
g.save_to_file(g_file_path)

tmp_work_dir = tempfile.mkdtemp()
with RaphtoryServer(tmp_work_dir).start() as server:
client = server.get_client()
normalized_path = normalize_path(g_file_path)
query = f"""mutation {{
loadGraphFromPath(
pathOnServer: "{normalized_path}",
overwrite: false
)
}}"""
res = client.query(query)
print(res)

query = """{graph(path: "g") {nodes {list {name}}}}"""
assert client.query(query) == {
"graph": {
"nodes": {"list": [{"name": "ben"}, {"name": "hamza"}, {"name": "haaroon"}]}
}
}

104 changes: 0 additions & 104 deletions raphtory-graphql/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -705,110 +705,6 @@ mod graphql_test {
);
}

#[tokio::test]
async fn test_mutation() {
let test_dir = tempdir().unwrap();
let f0 = &test_dir.path().join("g0");
let f1 = &test_dir.path().join("g1");

let g0 = PersistentGraph::new();
g0.add_constant_properties([("name", "g0")]).unwrap();
g0.save_to_file(f0).unwrap();

let g1 = PersistentGraph::new();
g1.add_node(0, 1, [("name", "1")], None).unwrap();

let g2 = PersistentGraph::new();
g2.add_node(0, 2, [("name", "2")], None).unwrap();

let tmp_dir = tempdir().unwrap();
let data = Data::new(tmp_dir.path(), &AppConfig::default());
let cache = data.graphs.clone();
let schema = App::create_schema().data(data).finish().unwrap();

let list_graphs = r#"{
graphs {
path
}
}"#;

let list_nodes = |path: &str| {
format!(
r#"{{
graph(path: "{}") {{
nodes {{
list {{
id
}}
}}
}}
}}"#,
path
)
};

let load_graph = |path: &Path| {
format!(
r#"mutation {{
loadGraphFromPath(pathOnServer: "{}", overwrite: {})
}}"#,
path.display().to_string(),
true
)
};

let new_g0 = tmp_dir.path().join("g0").display().to_string();
let new_g1 = tmp_dir.path().join("g1").display().to_string();

// only g0 which is empty
let req = Request::new(load_graph(f0));
let res = schema.execute(req).await;
let res_json = res.data.into_json().unwrap();
assert_eq!(res_json, json!({"loadGraphFromPath": new_g0}));

let req = Request::new(list_graphs);
let res = schema.execute(req).await;
let res_json = res.data.into_json().unwrap();
assert_eq!(res_json, json!({"graphs": {"path": ["g0"]}}));

let req = Request::new(list_nodes("g0"));
let res = schema.execute(req).await;
let res_json = res.data.into_json().unwrap();
assert_eq!(res_json, json!({"graph": {"nodes": {"list": []}}}));

// add g1 to graphs dir and replace g0 with g2 and load new graphs
g1.save_to_file(f1).unwrap();
g2.save_to_file(f0).unwrap();
cache.invalidate(Path::new("g0"));

let req = Request::new(load_graph(f0));
let res = schema.execute(req).await;
let res_json = res.data.into_json().unwrap();
assert_eq!(res_json, json!({"loadGraphFromPath": new_g0}));
let req = Request::new(load_graph(f1));
let res = schema.execute(req).await;
let res_json = res.data.into_json().unwrap();
assert_eq!(res_json, json!({"loadGraphFromPath": new_g1}));

// g0 now has node 2
let req = Request::new(list_nodes("g0"));
let res = schema.execute(req).await;
let res_json = res.data.into_json().unwrap();
assert_eq!(
res_json,
json!({"graph": {"nodes": {"list": [{"id": "2"}]}}})
);

// g1 has node 1
let req = Request::new(list_nodes("g1"));
let res = schema.execute(req).await;
let res_json = res.data.into_json().unwrap();
assert_eq!(
res_json,
json!({"graph": {"nodes": {"list": [{"id": "1"}]}}})
);
}

#[tokio::test]
async fn test_graph_injection() {
let g = PersistentGraph::new();
Expand Down

0 comments on commit ba92bbb

Please sign in to comment.