1313
1414import nx_arangodb as nxadb
1515from nx_arangodb .classes .dict .adj import AdjListOuterDict , EdgeAttrDict , EdgeKeyDict
16+ from nx_arangodb .classes .dict .graph import GRAPH_FIELD
1617from nx_arangodb .classes .dict .node import NodeAttrDict , NodeDict
1718
1819from .conftest import create_grid_graph , create_line_graph , db , run_gpu_tests
@@ -1638,7 +1639,7 @@ def test_multidigraph_edges_crud(load_karate_graph: Any) -> None:
16381639def test_graph_dict_init (load_karate_graph : Any ) -> None :
16391640 G = nxadb .Graph (name = "KarateGraph" , default_node_type = "person" )
16401641 assert db .collection ("_graphs" ).has ("KarateGraph" )
1641- graph_document = db .collection ( "_graphs" ). get ( "KarateGraph " )
1642+ graph_document = db .document ( f "_graphs/ { G . name } " )
16421643 assert graph_document ["_key" ] == "KarateGraph"
16431644 assert graph_document ["edgeDefinitions" ] == [
16441645 {"collection" : "knows" , "from" : ["person" ], "to" : ["person" ]},
@@ -1655,33 +1656,31 @@ def test_graph_dict_init_extended(load_karate_graph: Any) -> None:
16551656 G = nxadb .Graph (name = "KarateGraph" , foo = "bar" , bar = {"baz" : True })
16561657 G .graph ["foo" ] = "!!!"
16571658 G .graph ["bar" ]["baz" ] = False
1658- assert db .document (G .graph .graph_id )["foo" ] == "!!!"
1659- assert db .document (G .graph .graph_id )["bar" ]["baz" ] is False
1660- assert "baz" not in db .document (G .graph .graph_id )
1659+ assert db .document (G .graph .graph_id )[GRAPH_FIELD ][ "foo" ] == "!!!"
1660+ assert db .document (G .graph .graph_id )[GRAPH_FIELD ][ "bar" ]["baz" ] is False
1661+ assert "baz" not in db .document (G .graph .graph_id )[ GRAPH_FIELD ]
16611662
16621663
16631664def test_graph_dict_clear_will_not_remove_remote_data (load_karate_graph : Any ) -> None :
1664- G_adb = nxadb .Graph (
1665+ G = nxadb .Graph (
16651666 name = "KarateGraph" ,
16661667 foo = "bar" ,
16671668 bar = {"a" : 4 },
16681669 )
16691670
1670- G_adb .graph ["ant" ] = {"b" : 5 }
1671- G_adb .graph ["ant" ]["b" ] = 6
1672- G_adb .clear ()
1671+ G .graph ["ant" ] = {"b" : 5 }
1672+ G .graph ["ant" ]["b" ] = 6
1673+ G .clear ()
16731674 try :
1674- G_adb .graph ["ant" ]
1675+ G .graph ["ant" ]
16751676 except KeyError :
16761677 raise AssertionError ("Not allowed to fail." )
16771678
1678- assert db .document (G_adb .graph .graph_id )["ant" ] == {"b" : 6 }
1679+ assert db .document (G .graph .graph_id )[ GRAPH_FIELD ] ["ant" ] == {"b" : 6 }
16791680
16801681
16811682def test_graph_dict_set_item (load_karate_graph : Any ) -> None :
1682- name = "KarateGraph"
1683- db .collection ("nxadb_graphs" ).delete (name , ignore_missing = True )
1684- G = nxadb .Graph (name = name , default_node_type = "person" )
1683+ G = nxadb .Graph (name = "KarateGraph" , default_node_type = "person" )
16851684
16861685 json_values = [
16871686 "aString" ,
@@ -1699,122 +1698,124 @@ def test_graph_dict_set_item(load_karate_graph: Any) -> None:
16991698 G .graph ["json" ] = value
17001699
17011700 if value is None :
1702- assert "json" not in db .document (G .graph .graph_id )
1701+ assert "json" not in db .document (G .graph .graph_id )[ GRAPH_FIELD ]
17031702 else :
17041703 assert G .graph ["json" ] == value
1705- assert db .document (G .graph .graph_id )["json" ] == value
1704+ assert db .document (G .graph .graph_id )[GRAPH_FIELD ][ "json" ] == value
17061705
17071706
17081707def test_graph_dict_update (load_karate_graph : Any ) -> None :
17091708 G = nxadb .Graph (name = "KarateGraph" , default_node_type = "person" )
1710- G .clear ()
17111709
17121710 G .graph ["a" ] = "b"
17131711 to_update = {"c" : "d" }
17141712 G .graph .update (to_update )
17151713
17161714 # local
1717- assert G .graph ["a" ] == "b"
1718- assert G .graph ["c" ] == "d"
1715+ assert G .graph . data [ "a" ] == G . graph ["a" ] == "b"
1716+ assert G .graph . data [ "c" ] == G . graph ["c" ] == "d"
17191717
17201718 # remote
1721- adb_doc = db .collection ( "nxadb_graphs" ). get ( G .name )
1719+ adb_doc = db .document ( f"_graphs/ { G .name } " )[ GRAPH_FIELD ]
17221720 assert adb_doc ["a" ] == "b"
17231721 assert adb_doc ["c" ] == "d"
17241722
17251723
17261724def test_graph_attr_dict_nested_update (load_karate_graph : Any ) -> None :
17271725 G = nxadb .Graph (name = "KarateGraph" , default_node_type = "person" )
1728- G .clear ()
17291726
17301727 G .graph ["a" ] = {"b" : "c" }
17311728 G .graph ["a" ].update ({"d" : "e" })
17321729 assert G .graph ["a" ]["b" ] == "c"
17331730 assert G .graph ["a" ]["d" ] == "e"
1734- assert db .document (G .graph .graph_id )["a" ]["b" ] == "c"
1735- assert db .document (G .graph .graph_id )["a" ]["d" ] == "e"
1731+ assert db .document (G .graph .graph_id )[GRAPH_FIELD ][ "a" ]["b" ] == "c"
1732+ assert db .document (G .graph .graph_id )[GRAPH_FIELD ][ "a" ]["d" ] == "e"
17361733
17371734
17381735def test_graph_dict_nested_1 (load_karate_graph : Any ) -> None :
17391736 G = nxadb .Graph (name = "KarateGraph" , default_node_type = "person" )
1740- G .clear ()
17411737 icon = {"football_icon" : "MJ7" }
17421738
17431739 G .graph ["a" ] = {"b" : icon }
17441740 assert G .graph ["a" ]["b" ] == icon
1745- assert db .document (G .graph .graph_id )["a" ]["b" ] == icon
1741+ assert db .document (G .graph .graph_id )[GRAPH_FIELD ][ "a" ]["b" ] == icon
17461742
17471743
17481744def test_graph_dict_nested_2 (load_karate_graph : Any ) -> None :
17491745 G = nxadb .Graph (name = "KarateGraph" , default_node_type = "person" )
1750- G .clear ()
17511746 icon = {"football_icon" : "MJ7" }
17521747
17531748 G .graph ["x" ] = {"y" : icon }
17541749 G .graph ["x" ]["y" ]["amount_of_goals" ] = 1337
17551750
17561751 assert G .graph ["x" ]["y" ]["amount_of_goals" ] == 1337
1757- assert db .document (G .graph .graph_id )["x" ]["y" ]["amount_of_goals" ] == 1337
1752+ assert (
1753+ db .document (G .graph .graph_id )[GRAPH_FIELD ]["x" ]["y" ]["amount_of_goals" ] == 1337
1754+ )
17581755
17591756
17601757def test_graph_dict_empty_values (load_karate_graph : Any ) -> None :
17611758 G = nxadb .Graph (name = "KarateGraph" , default_node_type = "person" )
1762- G .clear ()
17631759
17641760 G .graph ["empty" ] = {}
17651761 assert G .graph ["empty" ] == {}
1766- assert db .document (G .graph .graph_id )["empty" ] == {}
1762+ assert db .document (G .graph .graph_id )[GRAPH_FIELD ][ "empty" ] == {}
17671763
17681764 G .graph ["none" ] = None
1769- assert "none" not in db .document (G .graph .graph_id )
1765+ assert "none" not in db .document (G .graph .graph_id )[ GRAPH_FIELD ]
17701766 assert "none" not in G .graph
17711767
17721768
17731769def test_graph_dict_nested_overwrite (load_karate_graph : Any ) -> None :
17741770 G = nxadb .Graph (name = "KarateGraph" , default_node_type = "person" )
1775- G .clear ()
17761771 icon1 = {"football_icon" : "MJ7" }
17771772 icon2 = {"basketball_icon" : "MJ23" }
17781773
17791774 G .graph ["a" ] = {"b" : icon1 }
17801775 G .graph ["a" ]["b" ]["football_icon" ] = "ChangedIcon"
17811776 assert G .graph ["a" ]["b" ]["football_icon" ] == "ChangedIcon"
1782- assert db .document (G .graph .graph_id )["a" ]["b" ]["football_icon" ] == "ChangedIcon"
1777+ assert (
1778+ db .document (G .graph .graph_id )[GRAPH_FIELD ]["a" ]["b" ]["football_icon" ]
1779+ == "ChangedIcon"
1780+ )
17831781
17841782 # Overwrite entire nested dictionary
17851783 G .graph ["a" ] = {"b" : icon2 }
17861784 assert G .graph ["a" ]["b" ]["basketball_icon" ] == "MJ23"
1787- assert db .document (G .graph .graph_id )["a" ]["b" ]["basketball_icon" ] == "MJ23"
1785+ assert (
1786+ db .document (G .graph .graph_id )[GRAPH_FIELD ]["a" ]["b" ]["basketball_icon" ]
1787+ == "MJ23"
1788+ )
17881789
17891790
17901791def test_graph_dict_complex_nested (load_karate_graph : Any ) -> None :
17911792 G = nxadb .Graph (name = "KarateGraph" , default_node_type = "person" )
1792- G .clear ()
17931793
17941794 complex_structure = {"level1" : {"level2" : {"level3" : {"key" : "value" }}}}
17951795
17961796 G .graph ["complex" ] = complex_structure
17971797 assert G .graph ["complex" ]["level1" ]["level2" ]["level3" ]["key" ] == "value"
17981798 assert (
1799- db .document (G .graph .graph_id )["complex" ]["level1" ]["level2" ]["level3" ]["key" ]
1799+ db .document (G .graph .graph_id )[GRAPH_FIELD ]["complex" ]["level1" ]["level2" ][
1800+ "level3"
1801+ ]["key" ]
18001802 == "value"
18011803 )
18021804
18031805
18041806def test_graph_dict_nested_deletion (load_karate_graph : Any ) -> None :
18051807 G = nxadb .Graph (name = "KarateGraph" , default_node_type = "person" )
1806- G .clear ()
18071808 icon = {"football_icon" : "MJ7" , "amount_of_goals" : 1337 }
18081809
18091810 G .graph ["x" ] = {"y" : icon }
18101811 del G .graph ["x" ]["y" ]["amount_of_goals" ]
18111812 assert "amount_of_goals" not in G .graph ["x" ]["y" ]
1812- assert "amount_of_goals" not in db .document (G .graph .graph_id )["x" ]["y" ]
1813+ assert "amount_of_goals" not in db .document (G .graph .graph_id )[GRAPH_FIELD ][ "x" ]["y" ]
18131814
18141815 # Delete top-level key
18151816 del G .graph ["x" ]
18161817 assert "x" not in G .graph
1817- assert "x" not in db .document (G .graph .graph_id )
1818+ assert "x" not in db .document (G .graph .graph_id )[ GRAPH_FIELD ]
18181819
18191820
18201821def test_readme (load_karate_graph : Any ) -> None :
0 commit comments