From c28509ac2880f7db5407395bde53beca33126601 Mon Sep 17 00:00:00 2001 From: Khushboo Vashi Date: Mon, 5 Oct 2020 14:40:21 +0530 Subject: [PATCH] Fixed an issue where the user is unable to change the macro name. Fixes #5885 --- docs/en_US/release_notes_4_27.rst | 3 +- .../tools/sqleditor/tests/test_macros.py | 32 +++++++++++++++++-- web/pgadmin/tools/sqleditor/utils/macros.py | 4 +-- 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/docs/en_US/release_notes_4_27.rst b/docs/en_US/release_notes_4_27.rst index 8bcbf7d76..295ba5cb0 100644 --- a/docs/en_US/release_notes_4_27.rst +++ b/docs/en_US/release_notes_4_27.rst @@ -36,4 +36,5 @@ Bug fixes | `Issue #5843 `_ - Fixed an issue where the 'PARALLEL UNSAFE' option is missing from reverse engineering SQL of function/procedure. | `Issue #5845 `_ - Fixed an issue where the query tool is not fetching more than 1000 rows for the table does not have any primary key. | `Issue #5861 `_ - Ensure that the 'Remove Server' option should be visible in the context menu. -| `Issue #5867 `_ - Fixed an issue where some properties are not being updated correctly for the shared server. \ No newline at end of file +| `Issue #5867 `_ - Fixed an issue where some properties are not being updated correctly for the shared server. +| `Issue #5885 `_ - Fixed an issue where the user is unable to change the macro name. \ No newline at end of file diff --git a/web/pgadmin/tools/sqleditor/tests/test_macros.py b/web/pgadmin/tools/sqleditor/tests/test_macros.py index cbc43edec..80d5c8bf4 100644 --- a/web/pgadmin/tools/sqleditor/tests/test_macros.py +++ b/web/pgadmin/tools/sqleditor/tests/test_macros.py @@ -29,7 +29,7 @@ class TestMacros(BaseTestGenerator): dict( url='set_macros', method='put', - operation='update', + operation='set', data={ 'changed': [ {'id': 1, @@ -47,6 +47,26 @@ class TestMacros(BaseTestGenerator): ] } )), + ('Update Macros', + dict( + url='set_macros', + method='put', + operation='update', + data={ + 'changed': [ + {'id': 1, + 'name': 'Test Macro 1 updated', + }, + {'id': 2, + 'sql': 'SELECT 22;' + }, + {'id': 3, + 'name': 'Test Macro 3 updated', + 'sql': 'SELECT 33;' + }, + ] + } + )), ('Clear Macros', dict( url='set_macros', @@ -113,12 +133,20 @@ class TestMacros(BaseTestGenerator): if self.operation == 'clear': self.assertEqual(response.status_code, 410) - else: + elif self.operation == 'set': self.assertEqual(response.status_code, 200) response_data = json.loads(response.data.decode('utf-8')) self.assertEqual(response_data['name'], m['name']) self.assertEqual(response_data['sql'], m['sql']) + elif self.operation == 'update': + self.assertEqual(response.status_code, 200) + + response_data = json.loads(response.data.decode('utf-8')) + if 'name' in m: + self.assertEqual(response_data['name'], m['name']) + if 'sql' in m: + self.assertEqual(response_data['sql'], m['sql']) def tearDown(self): # Disconnect the database diff --git a/web/pgadmin/tools/sqleditor/utils/macros.py b/web/pgadmin/tools/sqleditor/utils/macros.py index 10ad95811..2b33502d1 100644 --- a/web/pgadmin/tools/sqleditor/utils/macros.py +++ b/web/pgadmin/tools/sqleditor/utils/macros.py @@ -165,10 +165,10 @@ def update_macro(data, macro): name = data.get('name', None) sql = data.get('sql', None) - if name or sql and macro.sql and 'name' in data and name is None: + if (name or sql) and macro.sql and 'name' in data and name is None: return False, gettext( "Could not find the required parameter (name).") - elif name or sql and macro.name and 'sql' in data and sql is None: + elif (name or sql) and macro.name and 'sql' in data and sql is None: return False, gettext( "Could not find the required parameter (sql).")