def runTest(self):
     """ This function will update event trigger under test database. """
     db_con = database_utils.connect_database(self, utils.SERVER_GROUP,
                                              self.server_id, self.db_id)
     if not db_con['data']["connected"]:
         raise Exception("Could not connect to database.")
     schema_response = schema_utils.verify_schemas(self.server,
                                                   self.db_name,
                                                   self.schema_name)
     if not schema_response:
         raise Exception("Could not find the schema.")
     func_name = self.function_info[1]
     func_response = trigger_funcs_utils.verify_trigger_function(
         self.server,
         self.db_name,
         func_name)
     if not func_response:
         raise Exception("Could not find the trigger function.")
     trigger_response = event_trigger_utils.verify_event_trigger(
         self.server, self.db_name, self.trigger_name)
     if not trigger_response:
         raise Exception("Could not find event trigger.")
     data = {
         "comment": "This is event trigger update comment",
         "id": self.event_trigger_id
     }
     put_response = self.tester.put(
         self.url + str(utils.SERVER_GROUP) + '/' +
         str(self.server_id) + '/' + str(self.db_id) +
         '/' + str(self.event_trigger_id),
         data=json.dumps(data),
         follow_redirects=True)
     self.assertEquals(put_response.status_code, 200)
Example #2
0
 def setUp(self):
     self.db_name = parent_node_dict["database"][-1]["db_name"]
     schema_info = parent_node_dict["schema"][-1]
     self.server_id = schema_info["server_id"]
     self.db_id = schema_info["db_id"]
     db_con = database_utils.connect_database(self, utils.SERVER_GROUP,
                                              self.server_id, self.db_id)
     if not db_con['data']["connected"]:
         raise Exception("Could not connect to database to delete rule.")
     self.schema_id = schema_info["schema_id"]
     self.schema_name = schema_info["schema_name"]
     schema_response = schema_utils.verify_schemas(self.server,
                                                   self.db_name,
                                                   self.schema_name)
     if not schema_response:
         raise Exception("Could not find the schema to delete rule.")
     self.table_name = "table_column_%s" % (str(uuid.uuid4())[1:8])
     self.table_id = tables_utils.create_table(self.server, self.db_name,
                                               self.schema_name,
                                               self.table_name)
     self.rule_name = "test_rule_delete_%s" % (str(uuid.uuid4())[1:8])
     self.rule_id = rules_utils.create_rule(self.server, self.db_name,
                                            self.schema_name,
                                            self.table_name,
                                            self.rule_name)
 def setUp(self):
     self.db_name = parent_node_dict["database"][-1]["db_name"]
     schema_info = parent_node_dict["schema"][-1]
     self.server_id = schema_info["server_id"]
     self.db_id = schema_info["db_id"]
     db_con = database_utils.connect_database(self, utils.SERVER_GROUP,
                                              self.server_id, self.db_id)
     if not db_con['data']["connected"]:
         raise Exception(
             "Could not connect to database to delete a foreign "
             "key constraint.")
     self.schema_id = schema_info["schema_id"]
     self.schema_name = schema_info["schema_name"]
     schema_response = schema_utils.verify_schemas(self.server,
                                                   self.db_name,
                                                   self.schema_name)
     if not schema_response:
         raise Exception("Could not find the schema to delete a foreign "
                         "key constraint.")
     self.local_table_name = "local_table_foreignkey_delete_%s" % \
                             (str(uuid.uuid4())[1:8])
     self.local_table_id = tables_utils.create_table(
         self.server, self.db_name, self.schema_name, self.local_table_name)
     self.foreign_table_name = "foreign_table_foreignkey_delete_%s" % \
                               (str(uuid.uuid4())[1:8])
     self.foreign_table_id = tables_utils.create_table(
         self.server, self.db_name, self.schema_name,
         self.foreign_table_name)
     self.foreign_key_name = "test_foreignkey_delete_%s" % \
                             (str(uuid.uuid4())[1:8])
     self.foreign_key_id = fk_utils.create_foreignkey(
         self.server, self.db_name, self.schema_name, self.local_table_name,
         self.foreign_table_name)
    def runTest(self):
        """ This function will add new FTS configuration under test schema. """

        db_con = database_utils.connect_database(self,
                                                 utils.SERVER_GROUP,
                                                 self.server_id,
                                                 self.db_id)

        if not db_con["info"] == "Database connected.":
            raise Exception("Could not connect to database.")

        schema_response = schema_utils.verify_schemas(self.server,
                                                      self.db_name,
                                                      self.schema_name)
        if not schema_response:
            raise Exception("Could not find the schema.")

        self.fts_conf_name = "fts_conf_%s" % str(uuid.uuid4())[1:8]
        data = \
            {
                "name": self.fts_conf_name,
                "owner": self.server["username"],
                "prsname": "%s.%s" % (self.schema_name, self.fts_parser_name),
                "schema": self.schema_id,
                "tokens": []
            }

        response = self.tester.post(
            self.url + str(utils.SERVER_GROUP) + '/' +
            str(self.server_id) + '/' + str(self.db_id) +
            '/' + str(self.schema_id) + '/',
            data=json.dumps(data),
            content_type='html/json')

        self.assertEquals(response.status_code, 200)
 def runTest(self):
     """ This function will fetch added event trigger under test database.
     """
     db_con = database_utils.connect_database(self, utils.SERVER_GROUP,
                                              self.server_id, self.db_id)
     if not db_con['data']["connected"]:
         raise Exception("Could not connect to database.")
     schema_response = schema_utils.verify_schemas(self.server,
                                                   self.db_name,
                                                   self.schema_name)
     if not schema_response:
         raise Exception("Could not find the schema.")
     func_name = self.function_info[1]
     func_response = trigger_funcs_utils.verify_trigger_function(
         self.server,
         self.db_name,
         func_name)
     if not func_response:
         raise Exception("Could not find the trigger function.")
     response = self.tester.get(
         self.url +
         str(utils.SERVER_GROUP) + '/' + str(self.server_id) + '/' +
         str(self.db_id) + '/' + str(self.event_trigger_id),
         content_type='html/json'
     )
     self.assertEquals(response.status_code, 200)
Example #6
0
 def runTest(self):
     """ This function will update domain under schema node. """
     db_id = self.database_info["db_id"]
     server_id = self.database_info["server_id"]
     db_con = database_utils.connect_database(self, utils.SERVER_GROUP,
                                              server_id, db_id)
     if not db_con['data']["connected"]:
         raise Exception("Could not connect to database to get the domain.")
     db_name = self.database_info["db_name"]
     schema_response = schema_utils.verify_schemas(self.server,
                                                   db_name,
                                                   self.schema_name)
     if not schema_response:
         raise Exception("Could not find the schema to get the domain.")
     domain_response = domain_utils.verify_domain(self.server,
                                                  db_name,
                                                  self.schema_id,
                                                  self.domain_name)
     if not domain_response:
         raise Exception("Could not find the domain to update.")
     domain_id = self.domain_info[0]
     data = {"description": "This is domain update comment",
             "id": domain_id,
             }
     response = self.tester.put(
         self.url + str(utils.SERVER_GROUP) + '/' +
         str(server_id) + '/' +
         str(db_id) + '/' +
         str(self.schema_id) + '/' +
         str(domain_id),
         data=json.dumps(data),
         follow_redirects=True)
     self.assertEquals(response.status_code, 200)
     # Disconnect the database
     database_utils.disconnect_database(self, server_id, db_id)
    def runTest(self):
        """ This function will delete collation under schema node. """
        server_id = self.schema_info["server_id"]
        db_id = self.schema_info["db_id"]
        db_con = database_utils.connect_database(self,
                                                 utils.SERVER_GROUP,
                                                 server_id,
                                                 db_id)
        if not db_con['data']["connected"]:
            raise Exception("Could not connect to database.")

        schema_response = schema_utils.verify_schemas(self.server,
                                                      self.db_name,
                                                      self.schema_name)
        if not schema_response:
            raise Exception("Could not find the schema.")
        collation_id = self.collation[0]
        schema_id = self.schema_info["schema_id"]
        get_response = self.tester.delete(
            self.url + str(utils.SERVER_GROUP) + '/' + str(
                server_id) + '/' +
            str(db_id) + '/' + str(schema_id) + '/' + str(collation_id),
            content_type='html/json')
        self.assertEquals(get_response.status_code, 200)
        # Disconnect database to delete it
        database_utils.disconnect_database(self, server_id, db_id)
Example #8
0
    def runTest(self):
        """ This function will add collation under schema node. """
        schema_info = parent_node_dict["schema"][-1]
        server_id = schema_info["server_id"]
        db_id = schema_info["db_id"]
        db_con = database_utils.connect_database(self, utils.SERVER_GROUP,
                                                 server_id, db_id)
        if not db_con['data']["connected"]:
            raise Exception("Could not connect to database to add collation.")
        schema_id = self.schema_details[0]
        schema_name = self.schema_details[1]
        schema_response = schema_utils.verify_schemas(self.server,
                                                      self.db_name,
                                                      schema_name)
        if not schema_response:
            raise Exception("Could not find the schema to add the collation.")

        data = {
            "copy_collation": "pg_catalog.\"C\"",
            "name": "collation_add_%s" % str(uuid.uuid4())[1:8],
            "owner": self.server["username"],
            "schema": schema_name
        }
        response = self.tester.post(self.url + str(utils.SERVER_GROUP) + '/' +
                                    str(server_id) + '/' + str(db_id) + '/' +
                                    str(schema_id) + '/',
                                    data=json.dumps(data),
                                    content_type='html/json')
        self.assertEquals(response.status_code, 200)
        # Disconnect the database
        database_utils.disconnect_database(self, server_id, db_id)
    def runTest(self):

        db_con = database_utils.connect_database(self,
                                                 test_utils.SERVER_GROUP,
                                                 self.encode_sid,
                                                 self.encode_did)
        if not db_con["info"] == "Database connected.":
            raise Exception("Could not connect to the database.")

        # Initialize query tool
        url = '/datagrid/initialize/query_tool/{0}/{1}/{2}'.format(
            test_utils.SERVER_GROUP, self.encode_sid, self.encode_did)
        response = self.tester.post(url)
        self.assertEquals(response.status_code, 200)

        response_data = json.loads(response.data.decode('utf-8'))
        self.trans_id = response_data['data']['gridTransId']

        # Check character
        url = "/sqleditor/query_tool/start/{0}".format(self.trans_id)
        sql = "select E'{0}';".format(self.test_str)
        response = self.tester.post(url, data=json.dumps({"sql": sql}),
                                    content_type='html/json')
        self.assertEquals(response.status_code, 200)
        url = '/sqleditor/poll/{0}'.format(self.trans_id)
        response = self.tester.get(url)
        self.assertEquals(response.status_code, 200)
        response_data = json.loads(response.data.decode('utf-8'))
        self.assertEquals(response_data['data']['rows_fetched_to'], 1)

        database_utils.disconnect_database(self, self.encode_sid,
                                           self.encode_did)
Example #10
0
 def setUp(self):
     super(SynonymAddTestCase, self).setUp()
     self.db_name = parent_node_dict["database"][-1]["db_name"]
     schema_info = parent_node_dict["schema"][-1]
     self.server_id = schema_info["server_id"]
     self.db_id = schema_info["db_id"]
     server_con = server_utils.connect_server(self, self.server_id)
     if server_con:
         if "type" in server_con["data"]:
             if server_con["data"]["type"] == "pg":
                 message = "Synonyms are not supported by PG."
                 self.skipTest(message)
     db_con = database_utils.connect_database(self, utils.SERVER_GROUP,
                                              self.server_id, self.db_id)
     if not db_con['data']["connected"]:
         raise Exception("Could not connect to database to add synonym.")
     self.schema_id = schema_info["schema_id"]
     self.schema_name = schema_info["schema_name"]
     schema_response = schema_utils.verify_schemas(self.server,
                                                   self.db_name,
                                                   self.schema_name)
     if not schema_response:
         raise Exception("Could not find the schema to add the synonym.")
     self.sequence_name = "test_sequence_synonym_%s" % \
                          str(uuid.uuid4())[1:8]
     self.sequence_id = sequence_utils.create_sequences(
         self.server, self.db_name, self.schema_name, self.sequence_name)
    def runTest(self):
        """ This function will delete FTS template present under
            test schema. """

        db_con = database_utils.connect_database(self,
                                                 utils.SERVER_GROUP,
                                                 self.server_id,
                                                 self.db_id)

        if not db_con["info"] == "Database connected.":
            raise Exception("Could not connect to database.")

        schema_response = schema_utils.verify_schemas(self.server,
                                                      self.db_name,
                                                      self.schema_name)
        if not schema_response:
            raise Exception("Could not find the schema.")

        fts_response = fts_temp_utils.verify_fts_template(self.server,
                                                          self.db_name,
                                                          self.fts_temp_name)

        if not fts_response:
            raise Exception("Could not find the FTS template.")

        delete_response = self.tester.delete(
            self.url + str(utils.SERVER_GROUP) + '/' +
            str(self.server_id) + '/' +
            str(self.db_id) + '/' +
            str(self.schema_id) + '/' +
            str(self.fts_temp_id),
            follow_redirects=True)

        self.assertEquals(delete_response.status_code, 200)
 def runTest(self):
     """This function will update foreign server present under test
     database."""
     db_con = database_utils.connect_database(self,
                                              utils.SERVER_GROUP,
                                              self.server_id,
                                              self.db_id)
     if not db_con["info"] == "Database connected.":
         raise Exception("Could not connect to database.")
     fdw_response = fdw_utils.verify_fdw(self.server, self.db_name,
                                         self.fdw_name)
     if not fdw_response:
         raise Exception("Could not find FDW.")
     fsrv_response = fsrv_utils.verify_fsrv(self.server, self.db_name,
                                            self.fsrv_name)
     if not fsrv_response:
         raise Exception("Could not find FSRV.")
     data = {"description": "This is foreign server update comment",
             "id": self.fsrv_id}
     put_response = self.tester.put(
         self.url + str(utils.SERVER_GROUP) + '/' +
         str(self.server_id) + '/' + str(self.db_id) +
         '/' + str(self.fdw_id) + '/' +
         str(self.fsrv_id), data=json.dumps(data),
         follow_redirects=True)
     self.assertEquals(put_response.status_code, 200)
    def runTest(self):
        """This function will fetch foreign table under test database."""

        db_con = database_utils.connect_database(self,
                                                 utils.SERVER_GROUP,
                                                 self.server_id,
                                                 self.db_id)

        if not db_con["info"] == "Database connected.":
            raise Exception("Could not connect to database.")

        fsrv_response = fsrv_utils.verify_fsrv(self.server, self.db_name,
                                               self.fsrv_name)

        if not fsrv_response:
            raise Exception("Could not find Foreign Server.")

        response = self.tester.get(self.url + str(utils.SERVER_GROUP) + '/' +
                                   str(self.server_id) + '/' +
                                   str(self.db_id) + '/' +
                                   str(self.schema_id) + '/' +
                                   str(self.ft_id),
                                   content_type='html/json')

        self.assertEquals(response.status_code, 200)
Example #14
0
    def setUp(self):
        self.db_name = parent_node_dict["database"][-1]["db_name"]
        schema_info = parent_node_dict["schema"][-1]
        self.server_id = schema_info["server_id"]
        self.db_id = schema_info["db_id"]
        server_response = server_utils.connect_server(self, self.server_id)

        if server_response["data"]["version"] < 90300 and "mview" in self.url:
            message = "Materialized Views are not supported by PG9.2 " \
                      "and PPAS9.2 and below."
            self.skipTest(message)

        db_con = database_utils.connect_database(self, utils.SERVER_GROUP,
                                                 self.server_id, self.db_id)
        if not db_con['data']["connected"]:
            raise Exception("Could not connect to database to update a view.")
        self.schema_id = schema_info["schema_id"]
        self.schema_name = schema_info["schema_name"]
        schema_response = schema_utils.verify_schemas(self.server,
                                                      self.db_name,
                                                      self.schema_name)
        if not schema_response:
            raise Exception("Could not find the schema to update a view.")
        self.view_id = views_utils.create_view(self.server,
                                               self.db_name,
                                               self.schema_name,
                                               self.sql_query,
                                               self.view_name)
Example #15
0
 def runTest(self):
     """ This function will update added cast."""
     self.server_id = self.database_info["server_id"]
     self.db_id = self.database_info['db_id']
     db_con = database_utils.connect_database(self,
                                              utils.SERVER_GROUP,
                                              self.server_id,
                                              self.db_id)
     if not db_con["info"] == "Database connected.":
         raise Exception("Could not connect to database.")
     connection = utils.get_db_connection(self.server['db'],
                                          self.server['username'],
                                          self.server['db_password'],
                                          self.server['host'],
                                          self.server['port'])
     response = cast_utils.verify_cast(connection, self.source_type,
                                       self.target_type)
     if len(response) == 0:
         raise Exception("Could not find cast.")
     data = {
         "description": "This is cast update comment",
         "id": self.cast_id
     }
     put_response = self.tester.put(
         self.url + str(utils.SERVER_GROUP) + '/' +
         str(self.server_id) + '/' + str(
             self.db_id) +
         '/' + str(self.cast_id),
         data=json.dumps(data),
         follow_redirects=True)
     self.assertEquals(put_response.status_code, 200)
Example #16
0
def set_up(obj):
    """Common set up function"""
    from regression import parent_node_dict

    obj.db_name = parent_node_dict["database"][-1]["db_name"]
    schema_info = parent_node_dict["schema"][-1]
    obj.server_id = schema_info["server_id"]
    obj.db_id = schema_info["db_id"]
    obj.prorettypename = "event_trigger/trigger"
    server_con = server_utils.connect_server(obj, obj.server_id)

    if not server_con["info"] == "Server connected.":
        raise Exception("Could not connect to server.")
    if "version" in server_con["data"]:
        obj.server_version = server_con["data"]["version"]
        if server_con["data"]["version"] < 90300:
            obj.prorettypename = "trigger"
    if "type" in server_con["data"]:
        obj.server_type = server_con["data"]["type"]

    db_con = database_utils.connect_database(obj, utils.SERVER_GROUP,
                                             obj.server_id,
                                             obj.db_id)
    if not db_con['data']["connected"]:
        raise Exception("Could not connect to database.")
    obj.schema_id = schema_info["schema_id"]
    obj.schema_name = schema_info["schema_name"]
    schema_response = schema_utils.verify_schemas(obj.server,
                                                  obj.db_name,
                                                  obj.schema_name)
    if not schema_response:
        raise Exception("Could not find the schema.")

    return obj
    def runTest(self):
        """This function will delete foreign table under test database."""

        db_con = database_utils.connect_database(self,
                                                 utils.SERVER_GROUP,
                                                 self.server_id,
                                                 self.db_id)

        if not db_con["info"] == "Database connected.":
            raise Exception("Could not connect to database.")

        fsrv_response = fsrv_utils.verify_fsrv(self.server, self.db_name,
                                               self.fsrv_name)

        if not fsrv_response:
            raise Exception("Could not find Foreign Server.")

        ft_response = ft_utils.verify_foreign_table(self.server, self.db_name,
                                                    self.fsrv_name)
        if not ft_response:
            raise Exception("Could not find Foreign Table.")

        delete_response = self.tester.delete(
            self.url + str(utils.SERVER_GROUP) + '/' +
            str(self.server_id) + '/' +
            str(self.db_id) + '/' +
            str(self.schema_id) + '/' +
            str(self.ft_id),
            follow_redirects=True)

        self.assertEquals(delete_response.status_code, 200)
Example #18
0
    def setUp(self):
        self.db_name = parent_node_dict["database"][-1]["db_name"]
        schema_info = parent_node_dict["schema"][-1]
        self.server_id = schema_info["server_id"]
        self.db_id = schema_info["db_id"]
        db_con = database_utils.connect_database(self, utils.SERVER_GROUP,
                                                 self.server_id, self.db_id)
        if not db_con['data']["connected"]:
            raise Exception("Could not connect to database to add a table.")
        self.schema_id = schema_info["schema_id"]
        self.schema_name = schema_info["schema_name"]
        schema_response = schema_utils.verify_schemas(self.server,
                                                      self.db_name,
                                                      self.schema_name)
        if not schema_response:
            raise Exception("Could not find the schema to add a table.")

        self.is_partition = False
        if hasattr(self, 'server_min_version'):
            server_con = server_utils.connect_server(self, self.server_id)
            if not server_con["info"] == "Server connected.":
                raise Exception("Could not connect to server to add "
                                "partitioned table.")
            if server_con["data"]["version"] < self.server_min_version:
                message = "Partitioned table are not supported by " \
                          "PPAS/PG 10.0 and below."
                self.skipTest(message)
            else:
                self.is_partition = True
Example #19
0
 def runTest(self):
     """ This function will add domain under schema node. """
     db_id = self.database_info["db_id"]
     server_id = self.database_info["server_id"]
     db_con = database_utils.connect_database(self, utils.SERVER_GROUP,
                                              server_id, db_id)
     if not db_con['data']["connected"]:
         raise Exception("Could not connect to database to get the domain.")
     db_name = self.database_info["db_name"]
     schema_response = schema_utils.verify_schemas(self.server,
                                                   db_name,
                                                   self.schema_name)
     if not schema_response:
         raise Exception("Could not find the schema to get the domain.")
     domain_id = self.domain_info[0]
     # Call GET API to verify the domain
     get_response = self.tester.delete(
         self.url + str(utils.SERVER_GROUP) + '/' +
         str(server_id) + '/' +
         str(db_id) + '/' +
         str(self.schema_id) + '/' +
         str(domain_id),
         content_type='html/json')
     self.assertEquals(get_response.status_code, 200)
     # Disconnect the database
     database_utils.disconnect_database(self, server_id, db_id)
    def runTest(self):
        """ This function will fetch FTS template present under
            test schema. """

        db_con = database_utils.connect_database(self,
                                                 utils.SERVER_GROUP,
                                                 self.server_id,
                                                 self.db_id)

        if not db_con["info"] == "Database connected.":
            raise Exception("Could not connect to database.")

        schema_response = schema_utils.verify_schemas(self.server,
                                                      self.db_name,
                                                      self.schema_name)
        if not schema_response:
            raise Exception("Could not find the schema.")

        response = self.tester.get(self.url + str(utils.SERVER_GROUP) + '/' +
                                   str(self.server_id) + '/' +
                                   str(self.db_id) + '/' +
                                   str(self.schema_id) + '/' +
                                   str(self.fts_temp_id),
                                   content_type='html/json')

        self.assertEquals(response.status_code, 200)
Example #21
0
 def setUp(self):
     super(TriggersDeleteTestCase, self).setUp()
     self.db_name = parent_node_dict["database"][-1]["db_name"]
     schema_info = parent_node_dict["schema"][-1]
     self.server_id = schema_info["server_id"]
     self.db_id = schema_info["db_id"]
     db_con = database_utils.connect_database(self, utils.SERVER_GROUP,
                                              self.server_id, self.db_id)
     if not db_con['data']["connected"]:
         raise Exception("Could not connect to database to delete trigger.")
     self.schema_id = schema_info["schema_id"]
     self.schema_name = schema_info["schema_name"]
     schema_response = schema_utils.verify_schemas(self.server,
                                                   self.db_name,
                                                   self.schema_name)
     if not schema_response:
         raise Exception("Could not find the schema to delete trigger.")
     self.table_name = "table_trigger_%s" % (str(uuid.uuid4())[1:8])
     self.table_id = tables_utils.create_table(self.server, self.db_name,
                                               self.schema_name,
                                               self.table_name)
     self.func_name = "trigger_func_delete_%s" % str(uuid.uuid4())[1:8]
     self.function_info = \
         trigger_funcs_utils.create_trigger_function_with_trigger(
             self.server, self.db_name, self.schema_name, self.func_name)
     self.trigger_name = "test_trigger_delete_%s" % (str(uuid.uuid4())[1:8])
     self.trigger_id = triggers_utils.create_trigger(self.server,
                                                     self.db_name,
                                                     self.schema_name,
                                                     self.table_name,
                                                     self.trigger_name,
                                                     self.func_name)
 def setUp(self):
     super(CheckConstraintAddTestCase, self).setUp()
     self.db_name = parent_node_dict["database"][-1]["db_name"]
     schema_info = parent_node_dict["schema"][-1]
     self.server_id = schema_info["server_id"]
     self.db_id = schema_info["db_id"]
     db_con = database_utils.connect_database(self, utils.SERVER_GROUP,
                                              self.server_id, self.db_id)
     if not db_con['data']["connected"]:
         raise Exception("Could not connect to database to add a check "
                         "constraint.")
     self.schema_id = schema_info["schema_id"]
     self.schema_name = schema_info["schema_name"]
     schema_response = schema_utils.verify_schemas(self.server,
                                                   self.db_name,
                                                   self.schema_name)
     if not schema_response:
         raise Exception("Could not find the schema to add a check "
                         "constraint.")
     self.table_name = "table_checkconstraint_add_%s" % \
                       (str(uuid.uuid4())[1:8])
     self.table_id = tables_utils.create_table(self.server,
                                               self.db_name,
                                               self.schema_name,
                                               self.table_name)
Example #23
0
    def runTest(self):
        """This function will add sequence(s) under schema node."""
        db_name = parent_node_dict["database"][-1]["db_name"]
        schema_info = parent_node_dict["schema"][-1]
        self.server_id = schema_info["server_id"]
        self.db_id = schema_info["db_id"]
        db_con = database_utils.connect_database(self, utils.SERVER_GROUP,
                                                 self.server_id, self.db_id)
        if not db_con['data']["connected"]:
            raise Exception("Could not connect to database to add sequence.")
        schema_id = schema_info["schema_id"]
        schema_name = schema_info["schema_name"]
        schema_response = schema_utils.verify_schemas(self.server,
                                                      db_name,
                                                      schema_name)
        if not schema_response:
            raise Exception("Could not find the schema to add sequence.")
        db_user = self.server["username"]

        common_data = {
            "relacl": [
                {
                    "grantee": db_user,
                    "grantor": db_user,
                    "privileges":
                        [
                            {
                                "privilege_type": "r",
                                "privilege": True,
                                "with_grant": True
                            },
                            {
                                "privilege_type": "w",
                                "privilege": True,
                                "with_grant": False
                            },
                            {
                                "privilege_type": "U",
                                "privilege": True,
                                "with_grant": False
                            }
                        ]
                }
            ],
            "schema": schema_name,
            "seqowner": db_user,
        }

        self.data.update(common_data)

        response = self.tester.post(
            self.url + str(utils.SERVER_GROUP) + '/' +
            str(self.server_id) + '/' + str(self.db_id) +
            '/' + str(schema_id) + '/',
            data=json.dumps(self.data),
            content_type='html/json')
        self.assertEquals(response.status_code, 200)
Example #24
0
 def setUp(self):
     super(LanguagesAddTestCase, self).setUp()
     self.server_data = parent_node_dict["database"][-1]
     self.server_id = self.server_data["server_id"]
     self.db_id = self.server_data['db_id']
     self.db_name = self.server_data["db_name"]
     db_con = database_utils.connect_database(self,
                                              utils.SERVER_GROUP,
                                              self.server_id,
                                              self.db_id)
     if not db_con["info"] == "Database connected.":
         raise Exception("Could not connect to database.")
 def runTest(self):
     """This function will fetch foreign data wrapper present under test
      database."""
     db_con = database_utils.connect_database(self,
                                              utils.SERVER_GROUP,
                                              self.server_id,
                                              self.db_id)
     if not db_con["info"] == "Database connected.":
         raise Exception("Could not connect to database.")
     fdw_response = fdw_utils.verify_fdw(self.server, self.db_name,
                                         self.fdw_name)
     if not fdw_response:
         raise Exception("Could not find FDW.")
     db_user = self.server["username"]
     data = {
         "fsrvacl": [
             {
                 "grantee": db_user,
                 "grantor": db_user,
                 "privileges":
                     [
                         {
                             "privilege_type": "U",
                             "privilege": "true",
                             "with_grant": "false"
                         }
                     ]
             }
         ],
         "fsrvoptions": [
             {
                 "fsrvoption": "host",
                 "fsrvvalue": self.server['host']
             },
             {
                 "fsrvoption": "port",
                 "fsrvvalue": str(self.server['port'])
             },
             {
                 "fsrvoption": "dbname",
                 "fsrvvalue": self.db_name
             }
         ],
         "fsrvowner": db_user,
         "name": "test_fsrv_add_%s" % (str(uuid.uuid4())[1:8])
     }
     response = self.tester.post(
         self.url + str(utils.SERVER_GROUP) + '/' +
         str(self.server_id) + '/' + str(self.db_id) +
         '/' + str(self.fdw_id) + '/',
         data=json.dumps(data),
         content_type='html/json')
     self.assertEquals(response.status_code, 200)
Example #26
0
    def runTest(self):
        """ This function will check messages return by query tool polling. """
        database_info = parent_node_dict["database"][-1]
        self.server_id = database_info["server_id"]

        self.db_id = database_info["db_id"]
        db_con = database_utils.connect_database(self,
                                                 utils.SERVER_GROUP,
                                                 self.server_id,
                                                 self.db_id)
        if not db_con["info"] == "Database connected.":
            raise Exception("Could not connect to the database.")

        # Initialize query tool
        url = '/datagrid/initialize/query_tool/{0}/{1}/{2}'.format(
            utils.SERVER_GROUP, self.server_id, self.db_id)
        response = self.tester.post(url)
        self.assertEquals(response.status_code, 200)

        response_data = json.loads(response.data.decode('utf-8'))
        self.trans_id = response_data['data']['gridTransId']

        cnt = 0
        for s in self.sql:
            print("Executing and polling with: " + self.print_messages[cnt])
            # Start query tool transaction
            url = '/sqleditor/query_tool/start/{0}'.format(self.trans_id)
            response = self.tester.post(url, data=json.dumps({"sql": s}),
                                        content_type='html/json')

            self.assertEquals(response.status_code, 200)

            # Query tool polling
            url = '/sqleditor/poll/{0}'.format(self.trans_id)
            response = self.tester.get(url)
            self.assertEquals(response.status_code, 200)
            response_data = json.loads(response.data.decode('utf-8'))

            if self.expected_message[cnt] is not None:
                # Check the returned messages
                self.assertIn(self.expected_message[cnt],
                              response_data['data']['additional_messages'])

            # Check the output
            self.assertEquals(self.expected_result[cnt],
                              response_data['data']['result'][0][0])

            cnt += 1

        # Disconnect the database
        database_utils.disconnect_database(self, self.server_id, self.db_id)
    def runTest(self):
        """ This function will update trigger function under database node. """
        schema_info = parent_node_dict["schema"][-1]
        server_id = schema_info["server_id"]
        db_id = schema_info["db_id"]
        func_name = "test_event_put_%s" % str(uuid.uuid4())[1:8]
        server_con = server_utils.connect_server(self, server_id)
        if not server_con["info"] == "Server connected.":
            raise Exception("Could not connect to server to add resource "
                            "groups.")
        server_version = 0
        if "type" in server_con["data"]:
            if server_con["data"]["version"] < 90300:
                server_version = server_con["data"]["version"]
        self.function_info = trigger_funcs_utils.create_trigger_function(
            self.server, self.db_name, self.schema_name, func_name,
            server_version)
        db_con = database_utils.connect_database(self, utils.SERVER_GROUP,
                                                 server_id, db_id)
        if not db_con['data']["connected"]:
            raise Exception("Could not connect to database to add collation.")
        schema_response = schema_utils.verify_schemas(self.server,
                                                      self.db_name,
                                                      self.schema_name)
        if not schema_response:
            raise Exception("Could not find the schema to add the collation.")
        func_name = self.function_info[1]
        func_response = trigger_funcs_utils.verify_trigger_function(
            self.server,
            self.db_name,
            func_name)
        if not func_response:
            raise Exception("Could not find the trigger function to update"
                            " it's details.")

        trigger_func_id = self.function_info[0]
        data = {
            "description": "This is trigger function update comment",
            "id": trigger_func_id
        }

        put_response = self.tester.put(
            self.url + str(utils.SERVER_GROUP) +
            '/' + str(server_id) + '/' + str(db_id) + '/' +
            str(self.schema_id) + '/' +
            str(trigger_func_id),
            data=json.dumps(data),
            follow_redirects=True)
        self.assertEquals(put_response.status_code, 200)
        # Disconnect the database
        database_utils.disconnect_database(self, server_id, db_id)
Example #28
0
 def setUp(self):
     self.server_data = parent_node_dict["database"][-1]
     self.server_id = self.server_data["server_id"]
     self.db_id = self.server_data['db_id']
     self.db_name = self.server_data["db_name"]
     self.lang_name = "language_%s" % str(uuid.uuid4())[1:8]
     db_con = database_utils.connect_database(self,
                                              utils.SERVER_GROUP,
                                              self.server_id,
                                              self.db_id)
     if not db_con["info"] == "Database connected.":
         raise Exception("Could not connect to database.")
     self.language_id = language_utils.create_language(self.server,
                                                       self.db_name,
                                                       self.lang_name)
Example #29
0
 def runTest(self):
     """This function will fetch foreign data wrapper present under test
      database."""
     db_con = database_utils.connect_database(self,
                                              utils.SERVER_GROUP,
                                              self.server_id,
                                              self.db_id)
     if not db_con["info"] == "Database connected.":
         raise Exception("Could not connect to database.")
     response = self.tester.get(
         self.url + str(utils.SERVER_GROUP) + '/' + str(
             self.server_id) + '/' +
         str(self.db_id) + '/' + str(self.fdw_id),
         content_type='html/json')
     self.assertEquals(response.status_code, 200)
Example #30
0
 def setUp(self):
     self.db_name = parent_node_dict["database"][-1]["db_name"]
     schema_info = parent_node_dict["schema"][-1]
     self.server_id = schema_info["server_id"]
     self.db_id = schema_info["db_id"]
     db_con = database_utils.connect_database(self, utils.SERVER_GROUP,
                                              self.server_id, self.db_id)
     if not db_con['data']["connected"]:
         raise Exception("Could not connect to database to add a type.")
     self.schema_id = schema_info["schema_id"]
     self.schema_name = schema_info["schema_name"]
     schema_response = schema_utils.verify_schemas(self.server,
                                                   self.db_name,
                                                   self.schema_name)
     if not schema_response:
         raise Exception("Could not find the schema to add a type.")
Example #31
0
 def setUp(self):
     self.db_name = parent_node_dict["database"][-1]["db_name"]
     schema_info = parent_node_dict["schema"][-1]
     self.server_id = schema_info["server_id"]
     self.db_id = schema_info["db_id"]
     db_con = database_utils.connect_database(self, utils.SERVER_GROUP,
                                              self.server_id, self.db_id)
     if not db_con['data']["connected"]:
         raise Exception("Could not connect to database to delete rule.")
     self.schema_id = schema_info["schema_id"]
     self.schema_name = schema_info["schema_name"]
     schema_response = schema_utils.verify_schemas(self.server,
                                                   self.db_name,
                                                   self.schema_name)
     if not schema_response:
         raise Exception("Could not find the schema to delete rule.")
     self.table_name = "table_column_%s" % (str(uuid.uuid4())[1:8])
     self.table_id = tables_utils.create_table(self.server, self.db_name,
                                               self.schema_name,
                                               self.table_name)
     self.rule_name = "test_rule_delete_%s" % (str(uuid.uuid4())[1:8])
     self.rule_id = rules_utils.create_rule(self.server, self.db_name,
                                            self.schema_name,
                                            self.table_name, self.rule_name)
Example #32
0
    def runTest(self):
        """This function will fetch foreign data wrapper present under test
         database."""
        db_con = database_utils.connect_database(self, utils.SERVER_GROUP,
                                                 self.server_id, self.db_id)
        if not db_con["info"] == "Database connected.":
            raise Exception("Could not connect to database.")
        fdw_response = fdw_utils.verify_fdw(self.server, self.db_name,
                                            self.fdw_name)
        if not fdw_response:
            raise Exception("Could not find FDW.")

        if self.is_positive_test:
            response = self.get_handlers_fdw()

        else:
            if hasattr(self, "internal_server_error"):
                return_value_object = eval(self.mock_data["return_value"])
                with patch(self.mock_data["function_name"],
                           side_effect=[return_value_object]):
                    response = self.get_handlers_fdw()

        self.assertEqual(response.status_code,
                         self.expected_data["status_code"])
Example #33
0
    def runTest(self):
        """ This function will add cast under test database. """
        super(CastsCreateGetFunctionsTestCase, self).runTest()
        self.data = self.test_data
        self.server_data = parent_node_dict["database"][-1]
        self.server_id = self.server_data["server_id"]
        self.db_id = self.server_data['db_id']
        db_con = database_utils.connect_database(self, utils.SERVER_GROUP,
                                                 self.server_id, self.db_id)
        if not db_con["info"] == "Database connected.":
            raise Exception("Could not connect to database.")

        if self.is_positive_test:
            response = cast_utils.api_create_cast_get_functions(self)
            cast_utils.assert_status_code(self, response)

        else:
            if self.mocking_required:
                return_value_object = eval(self.mock_data["return_value"])
                with patch(self.mock_data["function_name"],
                           side_effect=[return_value_object]):
                    response = cast_utils.api_create_cast_get_functions(self)
                    cast_utils.assert_status_code(self, response)
                    cast_utils.assert_error_message(self, response)
    def runTest(self):
        """ This function will delete the FTS configurations under test
        schema. """

        db_con = database_utils.connect_database(self, utils.SERVER_GROUP,
                                                 self.server_id, self.db_id)

        if not db_con["info"] == "Database connected.":
            raise Exception("Could not connect to database.")

        schema_response = schema_utils.verify_schemas(self.server,
                                                      self.db_name,
                                                      self.schema_name)
        if not schema_response:
            raise Exception("Could not find the schema.")

        data = {'ids': self.fts_conf_ids}
        delete_response = self.tester.delete(
            self.url + str(utils.SERVER_GROUP) + '/' + str(self.server_id) +
            '/' + str(self.db_id) + '/' + str(self.schema_id) + '/',
            follow_redirects=True,
            data=json.dumps(data),
            content_type='html/json')
        self.assertEquals(delete_response.status_code, 200)
Example #35
0
    def runTest(self):
        """This function will fetch foreign data wrapper present under test
         database."""
        db_con = database_utils.connect_database(self, utils.SERVER_GROUP,
                                                 self.server_id, self.db_id)
        if not db_con["info"] == "Database connected.":
            raise Exception("Could not connect to database.")

        if self.is_positive_test:
            response = self.get_fdw_sql()
        else:
            if hasattr(self, "internal_server_error"):
                return_value_object = eval(self.mock_data["return_value"])
                with patch(self.mock_data["function_name"],
                           side_effect=[return_value_object]):
                    response = self.get_fdw_sql()

            if hasattr(self, "wrong_fdw_id"):
                self.fdw_id = 99999
                response = self.get_fdw_sql()

        actual_response_code = response.status_code
        expected_response_code = self.expected_data['status_code']
        self.assertEquals(actual_response_code, expected_response_code)
Example #36
0
    def setUp(self):
        self.db_name = parent_node_dict["database"][-1]["db_name"]
        schema_info = parent_node_dict["schema"][-1]
        self.server_id = schema_info["server_id"]
        self.db_id = schema_info["db_id"]
        db_con = database_utils.connect_database(self, utils.SERVER_GROUP,
                                                 self.server_id, self.db_id)
        if not db_con['data']["connected"]:
            raise Exception("Could not connect to database to add a table.")
        self.schema_id = schema_info["schema_id"]
        self.schema_name = schema_info["schema_name"]
        schema_response = schema_utils.verify_schemas(self.server,
                                                      self.db_name,
                                                      self.schema_name)
        if not schema_response:
            raise Exception("Could not find the schema to add a table.")

        if hasattr(self, 'server_min_version'):
            server_con = server_utils.connect_server(self, self.server_id)
            if not server_con["info"] == "Server connected.":
                raise Exception("Could not connect to server to add "
                                "partitioned table.")
            if server_con["data"]["version"] < self.server_min_version:
                self.skipTest(self.skip_msg)
    def runTest(self):
        """This function will fetch foreign table under test database."""
        # Create db connection
        db_con = database_utils.connect_database(self, utils.SERVER_GROUP,
                                                 self.server_id, self.db_id)

        if not db_con["info"] == "Database connected.":
            raise Exception("Could not connect to database.")

        fsrv_response = fsrv_utils.verify_fsrv(self.server, self.db_name,
                                               self.fsrv_name)

        if not fsrv_response:
            raise Exception("Could not find Foreign Server.")

        if self.is_positive_test:
            if self.is_dependent:
                self.url = self.url + 'dependent/'
                response = ft_utils.api_get(self)
            else:
                self.url = self.url + 'dependency/'
                response = ft_utils.api_get(self)

            utils.assert_status_code(self, response)
Example #38
0
    def runTest(self):
        """ This function will check dependents and dependencies
         of schema under database node. """
        self.server_id = self.database_info["server_id"]
        self.db_id = self.database_info["db_id"]
        db_con = database_utils.connect_database(self, utils.SERVER_GROUP,
                                                 self.server_id, self.db_id)
        if not db_con['data']["connected"]:
            raise Exception("Could not connect to database.")

        self.schema_id = self.schema_details[0]
        schema_name = self.schema_details[1]
        schema_response = schema_utils.verify_schemas(self.server,
                                                      self.db_name,
                                                      schema_name)
        if not schema_response:
            raise Exception("Could not find the schema.")

        if self.is_positive_test:
            response = self.dependents_schema()

        actual_response_code = response.status_code
        expected_response_code = self.expected_data['status_code']
        self.assertEqual(actual_response_code, expected_response_code)
Example #39
0
    def runTest(self):
        """ This function will delete FTS template present under
            test schema. """

        db_con = database_utils.connect_database(self, utils.SERVER_GROUP,
                                                 self.server_id, self.db_id)

        if not db_con["info"] == "Database connected.":
            raise Exception("Could not connect to database.")

        schema_response = schema_utils.verify_schemas(self.server,
                                                      self.db_name,
                                                      self.schema_name)
        if not schema_response:
            raise Exception("Could not find the schema.")

        fts_response = fts_temp_utils.verify_fts_template(
            self.server, self.db_name, self.fts_temp_name)

        if not fts_response:
            raise Exception("Could not find the FTS template.")

        delete_response = self.tester.delete(
            self.url + str(utils.SERVER_GROUP) + '/' + str(self.server_id) +
            '/' + str(self.db_id) + '/' + str(self.schema_id) + '/' +
            str(self.fts_temp_id),
            follow_redirects=True)

        self.assertEqual(delete_response.status_code, 200)

        negative_delete_response = self.tester.delete(
            self.url + str(utils.SERVER_GROUP) + '/' + str(self.server_id) +
            '/' + str(self.db_id) + '/' + str(self.schema_id) + '/' + str(0),
            follow_redirects=True)

        self.assertEqual(negative_delete_response.status_code, 500)
Example #40
0
    def runTest(self):
        """ This function will fetch collation sql under schema node. """
        db_con = database_utils.connect_database(self, utils.SERVER_GROUP,
                                                 self.server_id, self.db_id)
        if not db_con['data']["connected"]:
            raise Exception("Could not connect to database.")

        schema_response = schema_utils.verify_schemas(self.server,
                                                      self.db_name,
                                                      self.schema_name)
        if not schema_response:
            raise Exception("Could not find the schema.")

        if self.is_positive_test:
            response = self.get_collation_sql()
        else:
            if hasattr(self, "error_fetching_collation"):
                with patch(self.mock_data["function_name"],
                           return_value=eval(self.mock_data["return_value"])):
                    response = self.get_collation_sql()

        actual_response_code = response.status_code
        expected_response_code = self.expected_data['status_code']
        self.assertEquals(actual_response_code, expected_response_code)
Example #41
0
    def runTest(self):
        """ This function will update collation under schema node. """
        server_id = self.schema_info["server_id"]
        db_id = self.schema_info["db_id"]
        # Verify database
        db_con = database_utils.connect_database(self, utils.SERVER_GROUP,
                                                 server_id, db_id)
        if not db_con['data']["connected"]:
            raise Exception("Could not connect to database.")
        # Verify schema
        schema_response = schema_utils.verify_schemas(self.server,
                                                      self.db_name,
                                                      self.schema_name)
        if not schema_response:
            raise Exception("Could not find the schema.")
        # Verify collation
        coll_name = self.collation[1]
        collation_response = collation_utils.verify_collation(
            self.server, self.db_name, coll_name)
        if not collation_response:
            raise Exception("Could not find the collation.")

        collation_id = self.collation[0]
        schema_id = self.schema_info["schema_id"]
        data = {
            "description": "This is collation update comment",
            "id": collation_id
        }
        put_response = self.tester.put(
            self.url + str(utils.SERVER_GROUP) + '/' + str(server_id) + '/' +
            str(db_id) + '/' + str(schema_id) + '/' + str(collation_id),
            data=json.dumps(data),
            follow_redirects=True)
        self.assertEquals(put_response.status_code, 200)
        # Disconnect database to delete it
        database_utils.disconnect_database(self, server_id, db_id)
    def runTest(self):
        """This function will fetch foreign table under test database."""
        # Create db connection
        db_con = database_utils.connect_database(self, utils.SERVER_GROUP,
                                                 self.server_id, self.db_id)

        if not db_con["info"] == "Database connected.":
            raise Exception("Could not connect to database.")

        fsrv_response = fsrv_utils.verify_fsrv(self.server, self.db_name,
                                               self.fsrv_name)

        if not fsrv_response:
            raise Exception("Could not find Foreign Server.")

        if self.is_positive_test:
            response = ft_utils.api_get(self)

            # Assert response
            utils.assert_status_code(self, response)
        else:
            if self.mocking_required:
                with patch(self.mock_data["function_name"],
                           side_effect=[eval(self.mock_data["return_value"])]):
                    if self.is_list:
                        response = ft_utils.api_get(self, '')
                    else:
                        response = ft_utils.api_get(self)
            elif 'ft_id' in self.data:
                # Non-existing ft_id id
                self.ft_id = self.data["ft_id"]
                response = ft_utils.api_get(self)

            # Assert response
            utils.assert_status_code(self, response)
            utils.assert_error_message(self, response)
Example #43
0
 def runTest(self):
     """ This function will update extension added under test database. """
     db_con = database_utils.connect_database(self,
                                              utils.SERVER_GROUP,
                                              self.server_id,
                                              self.db_id)
     if not db_con["info"] == "Database connected.":
         raise Exception("Could not connect to database.")
     response = extension_utils.verify_extension(self.server, self.db_name,
                                                 self.extension_name)
     if not response:
         raise Exception("Could not find extension.")
     data = {
         "schema": "public",
         "id": self.extension_id
     }
     put_response = self.tester.put(
         self.url + str(utils.SERVER_GROUP) + '/' +
         str(self.server_id) + '/' + str(
             self.db_id) +
         '/' + str(self.extension_id),
         data=json.dumps(data),
         follow_redirects=True)
     self.assertEquals(put_response.status_code, 200)
Example #44
0
    def runTest(self):
        """ This function will update domain under schema node. """
        db_con = database_utils.connect_database(self, utils.SERVER_GROUP,
                                                 self.server_id, self.db_id)
        if not db_con['data']["connected"]:
            raise Exception("Could not connect to database to get the domain.")
        db_name = self.database_info["db_name"]
        schema_response = schema_utils.verify_schemas(self.server, db_name,
                                                      self.schema_name)
        if not schema_response:
            raise Exception("Could not find the schema to get the domain.")
        domain_response = domain_utils.verify_domain(self.server, db_name,
                                                     self.schema_id,
                                                     self.domain_name)
        if not domain_response:
            raise Exception("Could not find the domain to update.")
        self.domain_id = self.domain_info[0]
        self.test_data['id'] = self.domain_id

        if self.is_positive_test:
            response = self.update_domain()
        else:
            if hasattr(self, "error_updating_domain"):
                return_value_object = eval(self.mock_data["return_value"])
                with patch(self.mock_data["function_name"],
                           side_effect=[return_value_object]):
                    response = self.update_domain()

            if hasattr(self, "error_in_db"):
                with patch(self.mock_data["function_name"],
                           side_effect=eval(self.mock_data["return_value"])):
                    response = self.update_domain()

        actual_response_code = response.status_code
        expected_response_code = self.expected_data['status_code']
        self.assertEqual(actual_response_code, expected_response_code)
    def runTest(self):
        """ This function will delete schema under database node. """

        server_id = self.database_info["server_id"]
        db_id = self.database_info["db_id"]
        db_con = database_utils.connect_database(self, utils.SERVER_GROUP,
                                                 server_id, db_id)
        if not db_con['data']["connected"]:
            raise Exception("Could not connect to database to delete the"
                            " schema.")
        schema_id = self.schema_details[0]
        schema_name = self.schema_details[1]
        schema_response = schema_utils.verify_schemas(self.server,
                                                      self.db_name,
                                                      schema_name)
        if not schema_response:
            raise Exception("Could not find the schema to update.")

        db_user = self.server["username"]
        data = {
            "deffuncacl": {
                "added": [{
                    "grantee":
                    db_user,
                    "grantor":
                    db_user,
                    "privileges": [{
                        "privilege_type": "X",
                        "privilege": True,
                        "with_grant": True
                    }]
                }]
            },
            "defseqacl": {
                "added": [{
                    "grantee":
                    db_user,
                    "grantor":
                    db_user,
                    "privileges": [{
                        "privilege_type": "r",
                        "privilege": True,
                        "with_grant": False
                    }, {
                        "privilege_type": "w",
                        "privilege": True,
                        "with_grant": False
                    }, {
                        "privilege_type": "U",
                        "privilege": True,
                        "with_grant": False
                    }]
                }]
            },
            "deftblacl": {
                "added": [{
                    "grantee":
                    "public",
                    "grantor":
                    db_user,
                    "privileges": [{
                        "privilege_type": "D",
                        "privilege": True,
                        "with_grant": False
                    }, {
                        "privilege_type": "x",
                        "privilege": True,
                        "with_grant": False
                    }]
                }]
            },
            "id": schema_id
        }
        put_response = self.tester.put(self.url + str(utils.SERVER_GROUP) +
                                       '/' + str(server_id) + '/' +
                                       str(db_id) + '/' + str(schema_id),
                                       data=json.dumps(data),
                                       follow_redirects=True)

        self.assertEquals(put_response.status_code, 200)
        # Disconnect the database
        database_utils.disconnect_database(self, server_id, db_id)
    def setUp(self):
        # Load test data
        self.data = self.test_data

        # Create db connection
        self.db_name = parent_node_dict["database"][-1]["db_name"]
        schema_info = parent_node_dict["schema"][-1]
        self.server_id = schema_info["server_id"]
        self.db_id = schema_info["db_id"]
        db_con = database_utils.connect_database(self, utils.SERVER_GROUP,
                                                 self.server_id, self.db_id)

        # Check DB version
        if "server_min_version" in self.data:
            server_con = server_utils.connect_server(self, self.server_id)
            if not server_con["info"] == "Server connected.":
                raise Exception("Could not connect to server to check version")
            if "type" in server_con["data"] and \
                    server_con["data"]["type"] == "pg":
                self.skipTest("Compound Triggers are not supported by PG.")
            elif server_con["data"]["type"] == "ppas" \
                and server_con["data"]["version"] < self.data[
                    "server_min_version"]:
                self.skipTest(self.data["skip_msg"])

        if not db_con['data']["connected"]:
            raise Exception("Could not connect to database to fetch the view.")

        # Create schema
        self.schema_id = schema_info["schema_id"]
        self.schema_name = schema_info["schema_name"]
        schema_response = schema_utils.verify_schemas(self.server,
                                                      self.db_name,
                                                      self.schema_name)
        if not schema_response:
            raise Exception("Could not find the schema to fetch the view.")

        # Create view
        query = self.inventory_data['query']

        self.view_name = "test_view_sql_%s" % (str(uuid.uuid4())[1:8])

        self.view_id = views_utils.create_view(self.server,
                                               self.db_name,
                                               self.schema_name,
                                               self.view_name,
                                               query)

        if hasattr(self, "trigger_fun_required"):
            self.func_name = "trigger_func_get_%s" % str(uuid.uuid4())[1:8]
            self.function_info = views_utils.\
                create_trigger_function_with_trigger(self.server, self.db_name,
                                                     self.schema_name,
                                                     self.func_name)
            self.trigger_name = \
                "test_trigger_get_%s" % (str(uuid.uuid4())[1:8])
            self.trigger_id = views_utils.create_trigger(self.server,
                                                         self.db_name,
                                                         self.schema_name,
                                                         self.view_name,
                                                         self.trigger_name,
                                                         self.func_name,
                                                         "a")
Example #47
0
 def runTest(self):
     """This function will add sequence(s) under schema node."""
     db_name = parent_node_dict["database"][-1]["db_name"]
     schema_info = parent_node_dict["schema"][-1]
     self.server_id = schema_info["server_id"]
     self.db_id = schema_info["db_id"]
     db_con = database_utils.connect_database(self, utils.SERVER_GROUP,
                                              self.server_id, self.db_id)
     if not db_con['data']["connected"]:
         raise Exception("Could not connect to database to add sequence.")
     schema_id = schema_info["schema_id"]
     schema_name = schema_info["schema_name"]
     schema_response = schema_utils.verify_schemas(self.server, db_name,
                                                   schema_name)
     if not schema_response:
         raise Exception("Could not find the schema to add sequence.")
     db_user = self.server["username"]
     data = {
         "cache":
         "1",
         "cycled":
         True,
         "increment":
         "1",
         "maximum":
         "100000",
         "minimum":
         "1",
         "name":
         "test_sequence_add_%s" % (str(uuid.uuid4())[1:8]),
         "relacl": [{
             "grantee":
             db_user,
             "grantor":
             db_user,
             "privileges": [{
                 "privilege_type": "r",
                 "privilege": True,
                 "with_grant": True
             }, {
                 "privilege_type": "w",
                 "privilege": True,
                 "with_grant": False
             }, {
                 "privilege_type": "U",
                 "privilege": True,
                 "with_grant": False
             }]
         }],
         "schema":
         schema_name,
         "securities": [],
         "seqowner":
         db_user,
         "start":
         "100"
     }
     response = self.tester.post(
         self.url + str(utils.SERVER_GROUP) + '/' + str(self.server_id) +
         '/' + str(self.db_id) + '/' + str(schema_id) + '/',
         data=json.dumps(data),
         content_type='html/json')
     self.assertEquals(response.status_code, 200)
Example #48
0
    def runTest(self):
        """ This function will add domain and verify the
         reverse engineered sql. """
        self.db_id = self.database_info["db_id"]
        self.server_id = self.database_info["server_id"]
        db_con = database_utils.connect_database(self, utils.SERVER_GROUP,
                                                 self.server_id, self.db_id)
        if not db_con['data']["connected"]:
            raise Exception("Could not connect to database to get the domain.")

        db_name = self.database_info["db_name"]
        schema_response = schema_utils.verify_schemas(self.server, db_name,
                                                      self.schema_name)
        if not schema_response:
            raise Exception("Could not find the schema to get the domain.")
        self.domain_id = self.domain_info[0]

        # Call GET API to fetch the domain sql
        if self.is_positive_test:
            get_response = self.get_sql()

            expected_response_code = self.expected_data['status_code']
            self.assertEqual(get_response.status_code, expected_response_code)
            orig_sql = json.loads(get_response.data.decode('utf-8'))

            # Replace multiple spaces with one space and check the expected sql
            sql = re.sub('\s+', ' ', orig_sql).strip()
            expected_sql = '-- DOMAIN: {0}.{1} -- DROP DOMAIN IF EXISTS ' \
                           '{0}.{1}; CREATE DOMAIN {0}.{1} {2} ' \
                           'ALTER DOMAIN {0}.{1} OWNER' \
                           ' TO {3};'.format(self.schema_name,
                                             self.test_data['domain_name'],
                                             self.test_data['domain_sql'],
                                             self.server["username"])

            self.assertEqual(sql, expected_sql)

            domain_utils.delete_domain(self.server, db_name, self.schema_name,
                                       self.test_data['domain_name'])

            # Verify the reverse engineered sql with creating domain with
            # the sql we get from the server
            domain_utils.create_domain_from_sql(self.server, db_name, orig_sql)

            domain_utils.delete_domain(self.server, db_name, self.schema_name,
                                       self.test_data['domain_name'])
        else:
            if hasattr(self, "internal_server_error"):
                with patch(self.mock_data["function_name"],
                           return_value=eval(self.mock_data["return_value"])):
                    get_response = self.get_sql()

                    expected_response_code = self.expected_data['status_code']
                    self.assertEqual(get_response.status_code,
                                     expected_response_code)

            if hasattr(self, "wrong_domain_id"):
                self.domain_id = 99999
                get_response = self.get_sql()
                expected_response_code = self.expected_data['status_code']
                self.assertEqual(get_response.status_code,
                                 expected_response_code)
Example #49
0
    def runTest(self):
        """ This function will check update schema under database node. """

        self.server_id = self.database_info["server_id"]
        self.db_id = self.database_info["db_id"]
        db_con = database_utils.connect_database(self, utils.SERVER_GROUP,
                                                 self.server_id, self.db_id)
        if not db_con['data']["connected"]:
            raise Exception("Could not connect to database to delete the"
                            " schema.")
        self.schema_id = self.schema_details[0]
        schema_name = self.schema_details[1]
        schema_response = schema_utils.verify_schemas(self.server,
                                                      self.db_name,
                                                      schema_name)
        if not schema_response:
            raise Exception("Could not find the schema to update.")

        db_user = self.server["username"]
        self.data = {
            "deffuncacl": {
                "added": [{
                    "grantee":
                    db_user,
                    "grantor":
                    db_user,
                    "privileges": [{
                        "privilege_type": "X",
                        "privilege": True,
                        "with_grant": True
                    }]
                }]
            },
            "defseqacl": {
                "added": [{
                    "grantee":
                    db_user,
                    "grantor":
                    db_user,
                    "privileges": [{
                        "privilege_type": "r",
                        "privilege": True,
                        "with_grant": False
                    }, {
                        "privilege_type": "w",
                        "privilege": True,
                        "with_grant": False
                    }, {
                        "privilege_type": "U",
                        "privilege": True,
                        "with_grant": False
                    }]
                }]
            },
            "deftblacl": {
                "added": [{
                    "grantee":
                    "public",
                    "grantor":
                    db_user,
                    "privileges": [{
                        "privilege_type": "D",
                        "privilege": True,
                        "with_grant": False
                    }, {
                        "privilege_type": "x",
                        "privilege": True,
                        "with_grant": False
                    }]
                }]
            },
            "id": self.schema_id
        }

        if self.is_positive_test:
            response = self.update_schema()

        else:
            if hasattr(self, "error_in_db"):
                with patch(self.mock_data["function_name"],
                           side_effect=eval(self.mock_data["return_value"])):
                    response = self.update_schema()

        actual_response_code = response.status_code
        expected_response_code = self.expected_data['status_code']
        self.assertEqual(actual_response_code, expected_response_code)
Example #50
0
    def setUp(self):
        super(CheckConstraintDeleteTestCase, self).setUp()
        # Load test data
        self.data = self.test_data

        # Create db connection
        self.db_name = parent_node_dict["database"][-1]["db_name"]
        schema_info = parent_node_dict["schema"][-1]
        self.server_id = schema_info["server_id"]
        self.db_id = schema_info["db_id"]
        db_con = database_utils.connect_database(self, utils.SERVER_GROUP,
                                                 self.server_id, self.db_id)
        if not db_con['data']["connected"]:
            raise Exception("Could not connect to database to delete a check "
                            "constraint.")

        # Create schema
        self.schema_id = schema_info["schema_id"]
        self.schema_name = schema_info["schema_name"]
        schema_response = schema_utils.verify_schemas(self.server,
                                                      self.db_name,
                                                      self.schema_name)
        if not schema_response:
            raise Exception("Could not find the schema to delete a check "
                            "constraint.")

        # Create table
        self.table_name = "table_checkconstraint_delete_%s" % \
                          (str(uuid.uuid4())[1:8])
        self.table_id = tables_utils.create_table(self.server,
                                                  self.db_name,
                                                  self.schema_name,
                                                  self.table_name)

        # Create constraint to delete
        self.check_constraint_name = "test_checkconstraint_delete_%s" % \
                                     (str(uuid.uuid4())[1:8])
        self.check_constraint_id = \
            check_constraint_utils.create_check_constraint(
                self.server, self.db_name, self.schema_name, self.table_name,
                self.check_constraint_name)

        # Cross check constraint creation
        chk_constraint = check_constraint_utils.verify_check_constraint(
            self.server, self.db_name, self.check_constraint_name)
        if not chk_constraint:
            raise Exception("Could not find the check constraint to delete.")

        # In case of multiple constraints
        if self.is_list:
            # Create constraint to delete
            self.check_constraint_name_2 = \
                "test_checkconstraint_get_list_%s" % (str(uuid.uuid4())[1:8])
            self.check_constraint_id_2 = \
                check_constraint_utils.create_check_constraint(
                    self.server, self.db_name, self.schema_name,
                    self.table_name,
                    self.check_constraint_name_2)

            # constraint list to delete
            self.data['ids'] = [self.check_constraint_id,
                                self.check_constraint_id_2]
    def runTest(self):

        db_con = database_utils.connect_database(self, test_utils.SERVER_GROUP,
                                                 self._sid, self._did)
        if not db_con["info"] == "Database connected.":
            raise Exception("Could not connect to the database.")

        # Initialize query tool
        self.trans_id = str(random.randint(1, 9999999))
        url = self.init_url.format(self.trans_id, test_utils.SERVER_GROUP,
                                   self._sid, self._did)
        response = self.tester.post(url)
        self.assertEqual(response.status_code, 200)

        res = self.initiate_sql_query_tool(self.trans_id, self.sql)

        # If invalid tx test then make the Tx id invalid so that tests fails
        if not self.is_valid_tx:
            self.trans_id = self.trans_id + '007'

        # Check character
        url = self.donwload_url.format(self.trans_id)
        # Disable the console logging from Flask logger
        self.app.logger.disabled = True
        if not self.is_valid and self.is_valid_tx:
            # When user enters wrong query, poll will throw 500, so expecting
            # 500, as poll is never called for a wrong query.
            self.assertEqual(res.status_code, 500)
        elif self.filename is None:
            if self.download_as_txt:
                with patch(
                        'pgadmin.tools.sqleditor.blueprint.'
                        'csv_field_separator.get',
                        return_value=';'), patch(
                            'time.time', return_value=1587031962.3808076):
                    response = self.tester.post(url, data={"query": self.sql})
                    headers = dict(response.headers)
                    # when valid query
                    self.assertEqual(response.status_code, 200)
                    csv_data = response.data.decode()
                    self.assertTrue(self.output_columns in csv_data)
                    self.assertTrue(self.output_values in csv_data)
                    self.assertIn('text/plain', headers['Content-Type'])
                    self.assertIn('1587031962.txt',
                                  headers['Content-Disposition'])
            else:
                with patch('time.time', return_value=1587031962.3808076):
                    response = self.tester.post(url, data={"query": self.sql})
                    headers = dict(response.headers)
                    # when valid query
                    self.assertEqual(response.status_code, 200)
                    csv_data = response.data.decode()
                    self.assertTrue(self.output_columns in csv_data)
                    self.assertTrue(self.output_values in csv_data)
                    self.assertIn('text/csv', headers['Content-Type'])
                    self.assertIn('1587031962.csv',
                                  headers['Content-Disposition'])

        else:
            response = self.tester.post(url,
                                        data={
                                            "query": self.sql,
                                            "filename": self.filename
                                        })
            headers = dict(response.headers)
            # Enable the console logging from Flask logger
            self.app.logger.disabled = False
            if self.is_valid:
                # when valid query
                self.assertEqual(response.status_code, 200)
                csv_data = response.data.decode()
                self.assertTrue(self.output_columns in csv_data)
                self.assertTrue(self.output_values in csv_data)
                self.assertIn('text/csv', headers['Content-Type'])
                self.assertIn(self.filename, headers['Content-Disposition'])
            elif not self.is_valid and self.is_valid_tx:
                # When user enters wrong query
                self.assertEqual(response.status_code, 200)
                response_data = json.loads(response.data.decode('utf-8'))
                self.assertFalse(response_data['data']['status'])
                self.assertTrue(
                    'relation "this_table_does_not_exist" does not exist' in
                    response_data['data']['result'])
            else:
                # when TX id is invalid
                self.assertEqual(response.status_code, 500)

        # Close query tool
        url = '/datagrid/close/{0}'.format(self.trans_id)
        response = self.tester.delete(url)
        self.assertEqual(response.status_code, 200)

        database_utils.disconnect_database(self, self._sid, self._did)
    def runTest(self):
        """ This function will add domain constraint under test database. """
        db_con = database_utils.connect_database(self, utils.SERVER_GROUP,
                                                 self.server_id, self.db_id)
        if not db_con['data']["connected"]:
            raise Exception("Could not connect to database.")
        schema_response = schema_utils.verify_schemas(self.server,
                                                      self.db_name,
                                                      self.schema_name)
        if not schema_response:
            raise Exception("Could not find the schema.")

        self.domain_id = self.domain_info[0]
        domain_name = self.domain_info[1]

        domain_response = domain_cons_utils.verify_domain(
            self.server,
            self.db_name,
            self.schema_id,
            domain_name)
        if not domain_response:
            raise Exception("Could not find the domain.")

        domain_cons_response = domain_cons_utils.verify_domain_constraint(
            self.server, self.db_name,
            self.domain_con_name)
        if not domain_cons_response:
            raise Exception("Could not find domain constraint.")

        if self.is_positive_test and self.invalid:
            if hasattr(self, "node"):

                response = self.get_domain_constraint_node(
                    self.domain_constraint_id_invalid)
            else:
                response = self.get_domain_constraint_node("")

        elif self.is_positive_test:
            if hasattr(self, "node"):
                response = self.get_domain_constraint_node(
                    self.domain_constraint_id)
            else:
                response = self.get_domain_constraint_node("")

        else:
            if hasattr(self, "error_fetching_domain_constraint"):
                with patch(self.mock_data["function_name"],
                           return_value=eval(self.mock_data["return_value"])):
                    if hasattr(self, "node"):
                        response = self.get_domain_constraint_node(
                            self.domain_constraint_id)
                    else:
                        response = self.get_domain_constraint_node("")

            if hasattr(self, "wrong_domain_constraint_id"):
                self.domain_constraint_id = 99999
                response = \
                    self.get_domain_constraint_node(self.domain_constraint_id)

        actual_response_code = response.status_code
        expected_response_code = self.expected_data['status_code']

        self.assertEquals(actual_response_code, expected_response_code)
Example #53
0
    def runTest(self):
        """ This function will add trigger function under schema node. """
        db_name = parent_node_dict["database"][-1]["db_name"]
        schema_info = parent_node_dict["schema"][-1]
        server_id = schema_info["server_id"]
        db_id = schema_info["db_id"]
        prorettypename = "event_trigger/trigger"
        server_con = server_utils.connect_server(self, server_id)
        if not server_con["info"] == "Server connected.":
            raise Exception("Could not connect to server to add resource "
                            "groups.")
        if "type" in server_con["data"]:
            if server_con["data"]["version"] < 90300:
                prorettypename = "trigger"

        db_con = database_utils.connect_database(self, utils.SERVER_GROUP,
                                                 server_id, db_id)
        if not db_con['data']["connected"]:
            raise Exception("Could not connect to database to add a function.")
        schema_id = schema_info["schema_id"]
        schema_name = schema_info["schema_name"]
        schema_response = schema_utils.verify_schemas(self.server,
                                                      db_name,
                                                      schema_name)
        if not schema_response:
            raise Exception("Could not find the schema to add a function.")
        db_user = self.server["username"]
        data = {
            "acl": [
                {
                    "grantee": db_user,
                    "grantor": db_user,
                    "privileges":
                        [
                            {
                                "privilege_type": "X",
                                "privilege": True,
                                "with_grant": True
                            }
                        ]
                }
            ],
            "arguments": [],
            "funcowner": db_user,
            "lanname": "plpgsql",
            "name": "test_abort_any_command",
            "options": [],
            "proleakproof": True,
            "pronamespace": 2200,
            "prorettypename": prorettypename,
            "prosecdef": True,
            "prosrc": "BEGIN RAISE EXCEPTION 'command % is disabled',"
                      " tg_tag; END;",
            "provolatile": "s",
            "seclabels": [],
            "variables": [
                {
                    "name": "enable_sort",
                    "value": True
                }
            ]
        }
        # Get the type from data. We are adding two types
        # i.e. event_trigger and trigger.
        trigger_func_types = data['prorettypename'].split('/')
        for func_type in trigger_func_types:
            data['prorettypename'] = func_type
            data["name"] = "test_event_add_%s" % str(uuid.uuid4())[1:6]
            if schema_id:
                data['pronamespace'] = schema_id
            else:
                schema_id = data['pronamespace']
            response = self.tester.post(
                self.url + str(utils.SERVER_GROUP) + '/' +
                str(server_id) + '/' + str(db_id) + '/' + str(schema_id)
                + '/', data=json.dumps(data), content_type='html/json')

            self.assertEquals(response.status_code, 200)
        # Disconnect the database
        database_utils.disconnect_database(self, server_id, db_id)
Example #54
0
    def setUp(self):
        # Load test data
        self.data = self.test_data

        # Create db connection
        self.db_name = parent_node_dict["database"][-1]["db_name"]
        schema_info = parent_node_dict["schema"][-1]
        self.server_id = schema_info["server_id"]
        self.db_id = schema_info["db_id"]
        db_con = database_utils.connect_database(self, utils.SERVER_GROUP,
                                                 self.server_id, self.db_id)
        if not db_con['data']["connected"]:
            raise Exception("Could not connect to database to add a table.")

        # Create schema
        self.schema_id = schema_info["schema_id"]
        self.schema_name = schema_info["schema_name"]
        schema_response = schema_utils.verify_schemas(self.server,
                                                      self.db_name,
                                                      self.schema_name)
        if not schema_response:
            raise Exception("Could not find the schema to add a table.")

        # Create table
        self.table_name = "table_constraint_delete_%s" % \
                          (str(uuid.uuid4())[1:8])
        self.table_id = tables_utils.create_table(self.server, self.db_name,
                                                  self.schema_name,
                                                  self.table_name)

        # Create Check Constraints
        self.check_constraint_name = "test_constraint_delete_%s" % \
                                     (str(uuid.uuid4())[1:8])
        self.check_constraint_id = \
            chk_constraint_utils.create_check_constraint(
                self.server, self.db_name, self.schema_name, self.table_name,
                self.check_constraint_name)

        self.check_constraint_name_1 = "test_constraint_delete1_%s" % (str(
            uuid.uuid4())[1:8])
        self.check_constraint_id_1 = \
            chk_constraint_utils.create_check_constraint(
                self.server, self.db_name, self.schema_name, self.table_name,
                self.check_constraint_name_1)

        # Create Exclusion Constraint
        self.exclustion_constraint_name = "test_exclusion_get_%s" % (str(
            uuid.uuid4())[1:8])
        self.exclustion_constraint_id = \
            exclusion_utils.create_exclusion_constraint(
                self.server, self.db_name, self.schema_name, self.table_name,
                self.exclustion_constraint_name
            )

        # Create Foreign Key
        self.foreign_table_name = "foreign_table_foreignkey_get_%s" % \
                                  (str(uuid.uuid4())[1:8])
        self.foreign_table_id = tables_utils.create_table(
            self.server, self.db_name, self.schema_name,
            self.foreign_table_name)
        self.foreign_key_name = "test_foreignkey_get_%s" % \
                                (str(uuid.uuid4())[1:8])
        self.foreign_key_id = fk_utils.create_foreignkey(
            self.server, self.db_name, self.schema_name, self.table_name,
            self.foreign_table_name)

        # Create Primary Key
        self.primary_key_name = "test_primary_key_get_%s" % \
                                (str(uuid.uuid4())[1:8])
        self.primary_key_id = \
            index_constraint_utils.create_index_constraint(
                self.server, self.db_name, self.schema_name, self.table_name,
                self.primary_key_name, "PRIMARY KEY")

        # Create Unique Key constraint
        self.unique_constraint_name = "test_unique_constraint_get_%s" % (str(
            uuid.uuid4())[1:8])

        self.unique_constraint_id = \
            index_constraint_utils.create_index_constraint(
                self.server, self.db_name, self.schema_name, self.table_name,
                self.unique_constraint_name, "UNIQUE")