-
Notifications
You must be signed in to change notification settings - Fork 483
Python driver: Add skip_load parameter to skip LOAD 'age' statement
#2366
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
12ac331
8be3cbb
56256f9
3ce6bfe
56d3df3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,7 @@ | |
|
|
||
| from age.models import Vertex | ||
| import unittest | ||
| import unittest.mock | ||
| import decimal | ||
| import age | ||
| import argparse | ||
|
|
@@ -28,6 +29,76 @@ | |
| TEST_GRAPH_NAME = "test_graph" | ||
|
|
||
|
|
||
| class TestSetUpAge(unittest.TestCase): | ||
| """Unit tests for setUpAge() skip_load parameter — no DB required.""" | ||
|
|
||
| def _make_mock_conn(self): | ||
| mock_conn = unittest.mock.MagicMock() | ||
| mock_cursor = unittest.mock.MagicMock() | ||
| mock_conn.cursor.return_value.__enter__ = unittest.mock.Mock(return_value=mock_cursor) | ||
| mock_conn.cursor.return_value.__exit__ = unittest.mock.Mock(return_value=False) | ||
| mock_conn.adapters = unittest.mock.MagicMock() | ||
|
Comment on lines
+32
to
+40
|
||
| mock_type_info = unittest.mock.MagicMock() | ||
| mock_type_info.oid = 1 | ||
| mock_type_info.array_oid = 2 | ||
| return mock_conn, mock_cursor, mock_type_info | ||
|
|
||
| def test_skip_load_true_does_not_execute_load(self): | ||
| """When skip_load=True, LOAD 'age' must not be executed.""" | ||
| mock_conn, mock_cursor, mock_type_info = self._make_mock_conn() | ||
| with unittest.mock.patch("age.age.TypeInfo.fetch", return_value=mock_type_info), \ | ||
| unittest.mock.patch("age.age.checkGraphCreated"): | ||
| age.age.setUpAge(mock_conn, "test_graph", skip_load=True) | ||
| mock_cursor.execute.assert_called_once_with( | ||
| 'SET search_path = ag_catalog, "$user", public;' | ||
| ) | ||
|
Comment on lines
+46
to
+54
|
||
|
|
||
| def test_skip_load_false_executes_load(self): | ||
| """When skip_load=False (default), LOAD 'age' must be executed.""" | ||
| mock_conn, mock_cursor, mock_type_info = self._make_mock_conn() | ||
| with unittest.mock.patch("age.age.TypeInfo.fetch", return_value=mock_type_info), \ | ||
| unittest.mock.patch("age.age.checkGraphCreated"): | ||
| age.age.setUpAge(mock_conn, "test_graph", skip_load=False) | ||
| mock_cursor.execute.assert_any_call("LOAD 'age';") | ||
|
|
||
| def test_skip_load_with_load_from_plugins(self): | ||
| """When skip_load=False and load_from_plugins=True, LOAD from plugins path.""" | ||
| mock_conn, mock_cursor, mock_type_info = self._make_mock_conn() | ||
| with unittest.mock.patch("age.age.TypeInfo.fetch", return_value=mock_type_info), \ | ||
| unittest.mock.patch("age.age.checkGraphCreated"): | ||
| age.age.setUpAge(mock_conn, "test_graph", load_from_plugins=True, skip_load=False) | ||
| mock_cursor.execute.assert_any_call("LOAD '$libdir/plugins/age';") | ||
|
|
||
| def test_skip_load_true_still_sets_search_path(self): | ||
| """When skip_load=True, search_path must still be set.""" | ||
| mock_conn, mock_cursor, mock_type_info = self._make_mock_conn() | ||
| with unittest.mock.patch("age.age.TypeInfo.fetch", return_value=mock_type_info), \ | ||
| unittest.mock.patch("age.age.checkGraphCreated"): | ||
| age.age.setUpAge(mock_conn, "test_graph", skip_load=True) | ||
| mock_cursor.execute.assert_any_call( | ||
| 'SET search_path = ag_catalog, "$user", public;' | ||
| ) | ||
|
|
||
| def test_contradictory_skip_load_and_load_from_plugins_raises(self): | ||
| """skip_load=True + load_from_plugins=True must raise ValueError.""" | ||
| mock_conn, _, _ = self._make_mock_conn() | ||
| with self.assertRaises(ValueError): | ||
| age.age.setUpAge(mock_conn, "test_graph", load_from_plugins=True, skip_load=True) | ||
|
|
||
| def test_connect_forwards_skip_load_to_setup(self): | ||
| """age.connect(skip_load=True) must forward skip_load through the full call chain.""" | ||
| with unittest.mock.patch("age.age.psycopg.connect") as mock_psycopg, \ | ||
| unittest.mock.patch("age.age.setUpAge") as mock_setup: | ||
| mock_psycopg.return_value = unittest.mock.MagicMock() | ||
| age.connect(dsn="host=localhost", graph="test_graph", skip_load=True) | ||
| mock_setup.assert_called_once() | ||
| _, kwargs = mock_setup.call_args | ||
| self.assertTrue( | ||
| kwargs.get("skip_load", False), | ||
| "skip_load must be forwarded from age.connect() to setUpAge()" | ||
| ) | ||
|
|
||
|
|
||
| class TestAgeBasic(unittest.TestCase): | ||
| ag = None | ||
| args: argparse.Namespace = argparse.Namespace( | ||
|
|
@@ -485,6 +556,8 @@ def testSerialization(self): | |
|
|
||
| args = parser.parse_args() | ||
| suite = unittest.TestSuite() | ||
| loader = unittest.TestLoader() | ||
| suite.addTests(loader.loadTestsFromTestCase(TestSetUpAge)) | ||
| suite.addTest(TestAgeBasic("testExec")) | ||
| suite.addTest(TestAgeBasic("testQuery")) | ||
| suite.addTest(TestAgeBasic("testChangeData")) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.