public inbox for [email protected]  
help / color / mirror / Atom feed
From: Akshay Joshi <[email protected]>
To: pgadmin-hackers <[email protected]>
Subject: [pgAdmin4][Patch]: RM 3996 "Error dropping Schedule" message displayed if drop schedule through property section
Date: Fri, 12 Jul 2019 13:58:47 +0530
Message-ID: <CANxoLDeEropafUgTBEyfFC0fC8yuHxFUoeCo6R7MaSJfSUVHBw@mail.gmail.com> (raw)

Hi Hackers,

Attached is the patch to fix RM 3996 "Error dropping Schedule" message
displayed if drop schedule through property section. Added regression test
cases for delete multiple pgAgent Job, multiple schedules and multiple
steps.

-- 
*Thanks & Regards*
*Akshay Joshi*

*Sr. Software Architect*
*EnterpriseDB Software India Private Limited*
*Mobile: +91 976-788-8246*


Attachments:

  [application/octet-stream] RM_3996.patch (11.8K, 3-RM_3996.patch)
  download | inline diff:
diff --git a/web/pgadmin/browser/server_groups/servers/pgagent/schedules/__init__.py b/web/pgadmin/browser/server_groups/servers/pgagent/schedules/__init__.py
index c96db32d..c1903188 100644
--- a/web/pgadmin/browser/server_groups/servers/pgagent/schedules/__init__.py
+++ b/web/pgadmin/browser/server_groups/servers/pgagent/schedules/__init__.py
@@ -140,7 +140,7 @@ class JobScheduleView(PGChildNodeView):
     operations = dict({
         'obj': [
             {'get': 'properties', 'put': 'update', 'delete': 'delete'},
-            {'get': 'list', 'post': 'create'}
+            {'get': 'list', 'post': 'create', 'delete': 'delete'}
         ],
         'nodes': [{'get': 'nodes'}, {'get': 'nodes'}],
         'msql': [{'get': 'msql'}, {'get': 'msql'}],
@@ -474,17 +474,25 @@ class JobScheduleView(PGChildNodeView):
         )
 
     @check_precondition
-    def delete(self, gid, sid, jid, jscid):
+    def delete(self, gid, sid, jid, jscid=None):
         """Delete the Job Schedule."""
 
-        status, res = self.conn.execute_void(
-            render_template(
-                "/".join([self.template_path, 'delete.sql']),
-                jid=jid, jscid=jscid, conn=self.conn
+        if jscid is None:
+            data = request.form if request.form else json.loads(
+                request.data, encoding='utf-8'
             )
-        )
-        if not status:
-            return internal_server_error(errormsg=res)
+        else:
+            data = {'ids': [jscid]}
+
+        for jscid in data['ids']:
+            status, res = self.conn.execute_void(
+                render_template(
+                    "/".join([self.template_path, 'delete.sql']),
+                    jid=jid, jscid=jscid, conn=self.conn
+                )
+            )
+            if not status:
+                return internal_server_error(errormsg=res)
 
         return make_json_response(success=1)
 
diff --git a/web/pgadmin/browser/server_groups/servers/pgagent/schedules/static/js/pga_schedule.js b/web/pgadmin/browser/server_groups/servers/pgagent/schedules/static/js/pga_schedule.js
index 6ab403b9..a5480ac1 100644
--- a/web/pgadmin/browser/server_groups/servers/pgagent/schedules/static/js/pga_schedule.js
+++ b/web/pgadmin/browser/server_groups/servers/pgagent/schedules/static/js/pga_schedule.js
@@ -24,6 +24,7 @@ define('pgadmin.node.pga_schedule', [
         type: 'coll-pga_schedule',
         columns: ['jscid', 'jscname', 'jscenabled'],
         hasStatistics: false,
+        canDropCascade: false,
       });
   }
 
diff --git a/web/pgadmin/browser/server_groups/servers/pgagent/steps/__init__.py b/web/pgadmin/browser/server_groups/servers/pgagent/steps/__init__.py
index a7d84885..1f9a3ab4 100644
--- a/web/pgadmin/browser/server_groups/servers/pgagent/steps/__init__.py
+++ b/web/pgadmin/browser/server_groups/servers/pgagent/steps/__init__.py
@@ -159,7 +159,7 @@ class JobStepView(PGChildNodeView):
     operations = dict({
         'obj': [
             {'get': 'properties', 'put': 'update', 'delete': 'delete'},
-            {'get': 'list', 'post': 'create'}
+            {'get': 'list', 'post': 'create', 'delete': 'delete'}
         ],
         'nodes': [{'get': 'nodes'}, {'get': 'nodes'}],
         'msql': [{'get': 'msql'}, {'get': 'msql'}],
@@ -474,17 +474,25 @@ SELECT EXISTS(
         )
 
     @check_precondition
-    def delete(self, gid, sid, jid, jstid):
+    def delete(self, gid, sid, jid, jstid=None):
         """Delete the Job step."""
 
-        status, res = self.conn.execute_void(
-            render_template(
-                "/".join([self.template_path, 'delete.sql']),
-                jid=jid, jstid=jstid, conn=self.conn
+        if jstid is None:
+            data = request.form if request.form else json.loads(
+                request.data, encoding='utf-8'
             )
-        )
-        if not status:
-            return internal_server_error(errormsg=res)
+        else:
+            data = {'ids': [jstid]}
+
+        for jstid in data['ids']:
+            status, res = self.conn.execute_void(
+                render_template(
+                    "/".join([self.template_path, 'delete.sql']),
+                    jid=jid, jstid=jstid, conn=self.conn
+                )
+            )
+            if not status:
+                return internal_server_error(errormsg=res)
 
         return make_json_response(success=1)
 
diff --git a/web/pgadmin/browser/server_groups/servers/pgagent/steps/static/js/pga_jobstep.js b/web/pgadmin/browser/server_groups/servers/pgagent/steps/static/js/pga_jobstep.js
index cb74f650..e0ead97a 100644
--- a/web/pgadmin/browser/server_groups/servers/pgagent/steps/static/js/pga_jobstep.js
+++ b/web/pgadmin/browser/server_groups/servers/pgagent/steps/static/js/pga_jobstep.js
@@ -24,6 +24,7 @@ define('pgadmin.node.pga_jobstep', [
           'jstonerror',
         ],
         hasStatistics: false,
+        canDropCascade: false,
       });
   }
 
diff --git a/web/pgadmin/browser/server_groups/servers/pgagent/tests/test_pgagent_delete_multiple.py b/web/pgadmin/browser/server_groups/servers/pgagent/tests/test_pgagent_delete_multiple.py
new file mode 100644
index 00000000..e7dee121
--- /dev/null
+++ b/web/pgadmin/browser/server_groups/servers/pgagent/tests/test_pgagent_delete_multiple.py
@@ -0,0 +1,47 @@
+##########################################################################
+#
+# pgAdmin 4 - PostgreSQL Tools
+#
+# Copyright (C) 2013 - 2019, The pgAdmin Development Team
+# This software is released under the PostgreSQL Licence
+#
+##########################################################################
+
+import uuid
+import json
+from pgadmin.utils.route import BaseTestGenerator
+from regression.python_test_utils import test_utils as utils
+from . import utils as pgagent_utils
+
+
+class PgAgentDeleteMultipleTestCase(BaseTestGenerator):
+    """This class will test the delete multiple pgAgent job API"""
+    scenarios = [
+        ('Delete multiple pgAgent job', dict(url='/browser/pga_job/obj/'))
+    ]
+
+    def setUp(self):
+        flag, msg = pgagent_utils.is_valid_server_to_run_pgagent(self)
+        if not flag:
+            self.skipTest(msg)
+        flag, msg = pgagent_utils.is_pgagent_installed_on_server(self)
+        if not flag:
+            self.skipTest(msg)
+        name1 = "test_job1_delete%s" % str(uuid.uuid4())[1:8]
+        self.job_id1 = pgagent_utils.create_pgagent_job(self, name1)
+        name2 = "test_job2_delete%s" % str(uuid.uuid4())[1:8]
+        self.job_id2 = pgagent_utils.create_pgagent_job(self, name2)
+
+    def runTest(self):
+        """This function will deletes pgAgent job"""
+        response = self.tester.delete(
+            '{0}{1}/{2}/'.format(
+                self.url, str(utils.SERVER_GROUP), str(self.server_id)
+            ),
+            data=json.dumps({'ids': [self.job_id1, self.job_id2]}),
+            content_type='html/json'
+        )
+        self.assertEquals(response.status_code, 200)
+
+    def tearDown(self):
+        """Clean up code"""
diff --git a/web/pgadmin/browser/server_groups/servers/pgagent/tests/tests_pgagent_delete_multiple_schedules.py b/web/pgadmin/browser/server_groups/servers/pgagent/tests/tests_pgagent_delete_multiple_schedules.py
new file mode 100644
index 00000000..f9432c17
--- /dev/null
+++ b/web/pgadmin/browser/server_groups/servers/pgagent/tests/tests_pgagent_delete_multiple_schedules.py
@@ -0,0 +1,56 @@
+##########################################################################
+#
+# pgAdmin 4 - PostgreSQL Tools
+#
+# Copyright (C) 2013 - 2019, The pgAdmin Development Team
+# This software is released under the PostgreSQL Licence
+#
+##########################################################################
+
+import uuid
+import json
+from pgadmin.utils.route import BaseTestGenerator
+from regression.python_test_utils import test_utils as utils
+from . import utils as pgagent_utils
+
+
+class PgAgentDeleteMultipleSchedulesTestCase(BaseTestGenerator):
+    """This class will test the delete pgAgent job schedule API"""
+    scenarios = [
+        ('Delete multiple pgAgent schedules',
+         dict(url='/browser/pga_schedule/obj/'))
+    ]
+
+    def setUp(self):
+        flag, msg = pgagent_utils.is_valid_server_to_run_pgagent(self)
+        if not flag:
+            self.skipTest(msg)
+        flag, msg = pgagent_utils.is_pgagent_installed_on_server(self)
+        if not flag:
+            self.skipTest(msg)
+        name = "test_multi_sc_job_delete%s" % str(uuid.uuid4())[1:8]
+        self.job_id = pgagent_utils.create_pgagent_job(self, name)
+        sch1_name = "test_multi_schedule1_delete%s" % str(uuid.uuid4())[1:8]
+        self.schedule_id1 = pgagent_utils.create_pgagent_schedule(
+            self, sch1_name, self.job_id)
+
+        # Create one more schedule
+        sch2_name = "test_multi_schedule2_delete%s" % str(uuid.uuid4())[1:8]
+        self.schedule_id2 = pgagent_utils.create_pgagent_schedule(
+            self, sch2_name, self.job_id)
+
+    def runTest(self):
+        """This function will deletes pgAgent job schedule"""
+        response = self.tester.delete(
+            '{0}{1}/{2}/{3}/'.format(
+                self.url, str(utils.SERVER_GROUP), str(self.server_id),
+                str(self.job_id)
+            ),
+            data=json.dumps({'ids': [self.schedule_id1, self.schedule_id2]}),
+            content_type='html/json'
+        )
+        self.assertEquals(response.status_code, 200)
+
+    def tearDown(self):
+        """Clean up code"""
+        pgagent_utils.delete_pgagent_job(self)
diff --git a/web/pgadmin/browser/server_groups/servers/pgagent/tests/tests_pgagent_delete_multiple_steps.py b/web/pgadmin/browser/server_groups/servers/pgagent/tests/tests_pgagent_delete_multiple_steps.py
new file mode 100644
index 00000000..a9db9e85
--- /dev/null
+++ b/web/pgadmin/browser/server_groups/servers/pgagent/tests/tests_pgagent_delete_multiple_steps.py
@@ -0,0 +1,54 @@
+##########################################################################
+#
+# pgAdmin 4 - PostgreSQL Tools
+#
+# Copyright (C) 2013 - 2019, The pgAdmin Development Team
+# This software is released under the PostgreSQL Licence
+#
+##########################################################################
+
+import uuid
+import json
+from pgadmin.utils.route import BaseTestGenerator
+from regression.python_test_utils import test_utils as utils
+from . import utils as pgagent_utils
+
+
+class PgAgentDeleteMultipleStepsTestCase(BaseTestGenerator):
+    """This class will test the delete pgAgent job steps API"""
+    scenarios = [
+        ('Delete multiple pgAgent steps',
+         dict(url='/browser/pga_jobstep/obj/'))
+    ]
+
+    def setUp(self):
+        flag, msg = pgagent_utils.is_valid_server_to_run_pgagent(self)
+        if not flag:
+            self.skipTest(msg)
+        flag, msg = pgagent_utils.is_pgagent_installed_on_server(self)
+        if not flag:
+            self.skipTest(msg)
+        name = "test_multiple_st_job_delete%s" % str(uuid.uuid4())[1:8]
+        self.job_id = pgagent_utils.create_pgagent_job(self, name)
+        step_name1 = "test_multiple_step1_delete%s" % str(uuid.uuid4())[1:8]
+        self.step_id1 = pgagent_utils.create_pgagent_step(
+            self, step_name1, self.job_id)
+        step_name2 = "test_multiple_step2_delete%s" % str(uuid.uuid4())[1:8]
+        self.step_id2 = pgagent_utils.create_pgagent_step(
+            self, step_name2, self.job_id)
+
+    def runTest(self):
+        """This function will deletes pgAgent job schedule"""
+        response = self.tester.delete(
+            '{0}{1}/{2}/{3}/'.format(
+                self.url, str(utils.SERVER_GROUP), str(self.server_id),
+                str(self.job_id)
+            ),
+            data=json.dumps({'ids': [self.step_id1, self.step_id2]}),
+            content_type='html/json'
+        )
+        self.assertEquals(response.status_code, 200)
+
+    def tearDown(self):
+        """Clean up code"""
+        pgagent_utils.delete_pgagent_job(self)


view thread (2+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected]
  Subject: Re: [pgAdmin4][Patch]: RM 3996 "Error dropping Schedule" message displayed if drop schedule through property section
  In-Reply-To: <CANxoLDeEropafUgTBEyfFC0fC8yuHxFUoeCo6R7MaSJfSUVHBw@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox