def test_create_and_delete_table(self, db_type, db_type_key): """ <b>Description:</b> Checks if a table can be created and deleted. <b>Input data:</b> 1. sql-api-example app with bound database <b>Expected results:</b> A table was created and then deleted. <b>Steps:</b> 1. Create a table. 2. Verify the table was created. 3. Delete the table. 4. Verify the table was deleted. """ app = db_type[db_type_key] self.__class__.test_table_name = generate_test_object_name(prefix=DbInput.test_table_name) test_table = Table.post(app, self.test_table_name, self.test_columns) table_list = Table.get_list(app) assert test_table in table_list test_table.delete() table_list = Table.get_list(app) assert test_table not in table_list
def test_2_post_data(self): step("Create test table name") self.__class__.test_table_name = generate_test_object_name( prefix=DbInput.test_table_name) step("Pass POST request to the application") Table.post(self.psql_app, self.test_table_name, self.TEST_COLUMNS) tables = str(Table.get_list(self.psql_app)) step("Check that table with name '{}' was created.".format( self.test_table_name)) assert self.test_table_name in tables, "There is no '{}' table in database".format( self.test_table_name) step("Fill postgres table with data") Row.post(self.psql_app, self.test_table_name, self.TEST_ROWS) step("Check if there is data in table") rows = Row.get_list(self.psql_app, self.test_table_name) assert len(rows) >= 1, "There is no data in table"
def prepare_test(cls, test_org, test_space, add_admin_to_test_org, login_to_cf, psql_app, request): step("Create a table in postgres DB") cls.test_table_name = generate_test_object_name( prefix=DbInput.test_table_name) cls.TEST_TABLE = Table.post(psql_app, cls.test_table_name, cls.TEST_COLUMNS) Row.post(psql_app, cls.test_table_name, cls.TEST_ROWS[0]) step("Create tunnel to cdh-master-0") cls.SSH_TUNNEL = SshTunnel(hostname=config.cdh_master_0_hostname, username=config.jumpbox_username, path_to_key=config.jumpbox_key_path, port=WebhdfsTools.DEFAULT_PORT, via_hostname=config.jumpbox_hostname, via_port=22, local_port=WebhdfsTools.DEFAULT_PORT) cls.SSH_TUNNEL.connect() step("Get psql credentials") PSQL_CREDENTIALS = Psql.get_credentials(psql_app) cls.db_hostname, cls.db_name, cls.username, cls.password, cls.port = PSQL_CREDENTIALS cls.WEBHDFS = WebhdfsTools.create_client(host=cls.TEST_HOST) def fin(): cls.SSH_TUNNEL.disconnect() for table in Table.TABLES: table.delete() request.addfinalizer(fin)
def test_post_multiple_rows(self, db_type, db_type_key): """ <b>Description:</b> Checks if a multiple rows can be inserted. <b>Input data:</b> 1. sql-api-example app with bound database <b>Expected results:</b> A table with multiple rows inserted. <b>Steps:</b> 1. Create a table. 2. Insert multiple rows. 3. Verify a row was inserted. """ app = db_type[db_type_key] Table.post(app, self.test_table_name, self.test_columns) expected_rows = self._get_expected_rows(app) rows = Row.get_list(app, self.test_table_name) assert rows == expected_rows
def prepare_test(cls, test_org, test_space, add_admin_to_test_org, login_to_cf, psql_app, request, class_context): step("Create a table in postgres DB") cls.test_table_name = generate_test_object_name(prefix=DbInput.test_table_name) cls.TEST_TABLE = Table.post(psql_app, cls.test_table_name, cls.TEST_COLUMNS) Row.post(psql_app, cls.test_table_name, cls.TEST_ROWS) step("Get psql credentials") PSQL_CREDENTIALS = Psql.get_credentials(psql_app) cls.db_hostname, cls.db_name, cls.username, cls.password, cls.port = PSQL_CREDENTIALS step("Create context") cls.context = class_context def fin(): for table in Table.TABLES: table.delete() request.addfinalizer(fin)
def test_delete_row(self, db_type, db_type_key): """ <b>Description:</b> Checks if a row can be deleted. <b>Input data:</b> 1. sql-api-example app with bound database <b>Expected results:</b> A table with a deleted row. <b>Steps:</b> 1. Create a table. 2. Insert multiple rows. 3. Delete a row. 4. Verify a row was deleted. """ app = db_type[db_type_key] Table.post(app, self.test_table_name, self.test_columns) posted_rows = self._get_expected_rows(app) posted_rows[1].delete() rows = Row.get_list(app, self.test_table_name) assert posted_rows[1] not in rows
def test_put_row(self, db_type, db_type_key): """ <b>Description:</b> Checks if a row can be updated. <b>Input data:</b> 1. sql-api-example app with bound database <b>Expected results:</b> A table with a updated row. <b>Steps:</b> 1. Create a table. 2. Insert multiple rows with test data. 3. Update a row. 4. Verify a row was updated. """ app = db_type[db_type_key] Table.post(app, self.test_table_name, self.test_columns) expected_rows = self._get_expected_rows(app) new_values = [{"column_name": "col0", "value": self.test_table_name}, {"column_name": "col2", "value": True}] expected_rows[1].put(new_values) row = Row.get(app, self.test_table_name, row_id=expected_rows[1].id) assert expected_rows[1] == row
def test_post_row(self, db_type, db_type_key, row_values): """ <b>Description:</b> Checks if a row can be inserted. <b>Input data:</b> 1. sql-api-example app with bound database <b>Expected results:</b> A table with a row. <b>Steps:</b> 1. Create a table. 2. Insert a row. 3. Verify a row was inserted. """ app = db_type[db_type_key] Table.post(app, self.test_table_name, self.test_columns) new_row_id = Row.post(app, self.test_table_name, row_values) expected_row = self._create_expected_row(app, self.test_table_name, new_row_id, row_values) row_list = Row.get_list(app, self.test_table_name) assert expected_row in row_list row = Row.get(app, self.test_table_name, row_id=1) assert row == expected_row
def test_get_table_columns_msql(self, db_type): """ <b>Description:</b> Checks if a table with columns can be created. <b>Input data:</b> 1. sql-api-example app with bound database <b>Expected results:</b> A table was created and has columns. <b>Steps:</b> 1. Create a table with columns. 2. Verify columns were created. """ app = db_type["app_bound_mysql"] test_table = Table.post(app, self.test_table_name, self.test_columns) expected_columns = [Column.from_json_definition(c) for c in self.mysql_specyfic_columns] expected_columns.append(Column("id", "BIGINT", False, 20)) columns = test_table.get_columns() assert len(columns) == len(expected_columns) for column in expected_columns: assert column in columns