public inbox for [email protected]  
help / color / mirror / Atom feed
From: Khushboo Vashi <[email protected]>
To: pgadmin-hackers <[email protected]>
Subject: [pgAdmin4][Patch] - RE-SQL and modified SQL tests for Check Constraint node
Date: Tue, 16 Jul 2019 11:52:31 +0530
Message-ID: <CAFOhELePnGgBQnfowrkabLHauGBiXO9xNGM_hmCZ766PUPmtFQ@mail.gmail.com> (raw)

Hi,

Please find the attached patch for the RE-SQL and modified SQL tests for
check constraint node.

For the table child nodes, *create table endpoint *with proper data is
required in the JSON file.
I have introduced one new parameter named *store_table_id* in the table
create endpoint, so the created table ID will be stored for the rest of the
scenarios.

Thanks,
Khushboo


Attachments:

  [application/octet-stream] resql_check_constraint.patch (6.1K, 3-resql_check_constraint.patch)
  download | inline diff:
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/check_constraint/tests/Default/alter_check_constraint.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/check_constraint/tests/Default/alter_check_constraint.sql
new file mode 100644
index 00000000..e9985430
--- /dev/null
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/check_constraint/tests/Default/alter_check_constraint.sql
@@ -0,0 +1,9 @@
+-- Constraint: Chk_$%{}[]()&*^!@"'`\/#a
+
+-- ALTER TABLE testschema.tableforcon DROP CONSTRAINT "Chk_$%{}[]()&*^!@""'`\/#a";
+
+ALTER TABLE testschema.tableforcon
+    ADD CONSTRAINT "Chk_$%{}[]()&*^!@""'`\/#a" CHECK (col1 > 1);
+
+COMMENT ON CONSTRAINT "Chk_$%{}[]()&*^!@""'`\/#a" ON testschema.tableforcon
+    IS 'Comment for alter';
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/check_constraint/tests/Default/create_check_constraint.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/check_constraint/tests/Default/create_check_constraint.sql
new file mode 100644
index 00000000..9afc729b
--- /dev/null
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/check_constraint/tests/Default/create_check_constraint.sql
@@ -0,0 +1,10 @@
+-- Constraint: Chk_$%{}[]()&*^!@"'`\/#
+
+-- ALTER TABLE testschema.tableforcon DROP CONSTRAINT "Chk_$%{}[]()&*^!@""'`\/#";
+
+ALTER TABLE testschema.tableforcon
+    ADD CONSTRAINT "Chk_$%{}[]()&*^!@""'`\/#" CHECK (col1 > 1)
+    NOT VALID;
+
+COMMENT ON CONSTRAINT "Chk_$%{}[]()&*^!@""'`\/#" ON testschema.tableforcon
+    IS 'Comment for create';
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/check_constraint/tests/Default/msql_check_constraint.sql b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/check_constraint/tests/Default/msql_check_constraint.sql
new file mode 100644
index 00000000..6f1fd8d3
--- /dev/null
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/check_constraint/tests/Default/msql_check_constraint.sql
@@ -0,0 +1,6 @@
+ALTER TABLE testschema.tableforcon
+    RENAME CONSTRAINT "Chk_$%{}[]()&*^!@""'`\/#" TO "Chk_$%{}[]()&*^!@""'`\/#a";
+ALTER TABLE testschema.tableforcon
+    VALIDATE CONSTRAINT "Chk_$%{}[]()&*^!@""'`\/#a";
+COMMENT ON CONSTRAINT "Chk_$%{}[]()&*^!@""'`\/#a" ON testschema.tableforcon
+    IS 'Comment for alter';
diff --git a/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/check_constraint/tests/Default/test.json b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/check_constraint/tests/Default/test.json
new file mode 100644
index 00000000..a5fb3671
--- /dev/null
+++ b/web/pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/check_constraint/tests/Default/test.json
@@ -0,0 +1,56 @@
+{
+  "scenarios": [
+    {
+      "type": "create",
+      "name": "Create Table",
+      "endpoint": "NODE-table.obj",
+      "sql_endpoint": "NODE-table.sql_id",
+      "data": {
+        "name": "tableforcon",
+        "columns": [{
+          "name": "col1",
+          "cltype": "integer",
+          "is_primary_key": true
+        }],
+        "is_partitioned": false,
+        "schema": "testschema",
+        "spcname": "pg_default"
+      },
+      "store_table_id": true
+    },
+    {
+      "type": "create",
+      "name": "Create Check Constraint",
+      "endpoint": "NODE-check_constraint.obj",
+      "sql_endpoint": "NODE-check_constraint.sql_id",
+      "data": {
+        "name": "Chk_$%{}[]()&*^!@\"'`\\/#",
+        "comment": "Comment for create",
+        "consrc": "col1 > 1",
+        "connoinherit": false,
+        "convalidated": true
+      },
+      "expected_sql_file": "create_check_constraint.sql"
+    }, {
+      "type": "alter",
+      "name": "Alter Check Constraint",
+      "endpoint": "NODE-check_constraint.obj_id",
+      "sql_endpoint": "NODE-check_constraint.sql_id",
+      "msql_endpoint": "NODE-check_constraint.msql_id",
+      "data": {
+        "name": "Chk_$%{}[]()&*^!@\"'`\\/#a",
+        "convalidated": false,
+        "comment": "Comment for alter"
+      },
+      "expected_sql_file": "alter_check_constraint.sql",
+      "expected_msql_file": "msql_check_constraint.sql"
+    }, {
+      "type": "delete",
+      "name": "Drop Check Constraint",
+      "endpoint": "NODE-check_constraint.delete_id",
+      "data": {
+        "name": "Chk_$%{}[]()&*^!@\"'`\\/#a"
+      }
+    }
+  ]
+}
diff --git a/web/regression/re_sql/tests/test_resql.py b/web/regression/re_sql/tests/test_resql.py
index 6b87f030..6bb54d9e 100644
--- a/web/regression/re_sql/tests/test_resql.py
+++ b/web/regression/re_sql/tests/test_resql.py
@@ -151,6 +151,8 @@ class ReverseEngineeredSQLTestCases(BaseTestGenerator):
                     options['did'] = int(self.server_information['db_id'])
                 elif arg == 'scid':
                     options['scid'] = int(self.schema_id)
+                elif arg == 'tid':
+                    options['tid'] = int(self.table_id)
                 else:
                     if object_id is not None:
                         options[arg] = int(object_id)
@@ -212,6 +214,10 @@ class ReverseEngineeredSQLTestCases(BaseTestGenerator):
                 resp_data = json.loads(response.data.decode('utf8'))
                 object_id = resp_data['node']['_id']
 
+                # Table child nodes require table id
+                if 'store_table_id' in scenario:
+                    self.table_id = object_id
+
                 # Compare the reverse engineering SQL
                 if not self.check_re_sql(scenario, object_id):
                     print_msg = scenario['name']
@@ -320,6 +326,7 @@ class ReverseEngineeredSQLTestCases(BaseTestGenerator):
                                 object_id)
 
         params = urllib.parse.urlencode(scenario['data'])
+        params = params.replace('False', 'false').replace('True', 'true')
         url = msql_url + "?%s" % params
         response = self.tester.get(url,
                                    follow_redirects=True)


view thread (4+ 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] - RE-SQL and modified SQL tests for Check Constraint node
  In-Reply-To: <CAFOhELePnGgBQnfowrkabLHauGBiXO9xNGM_hmCZ766PUPmtFQ@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