def test_execute_from_file_should_insert_data(self): object_name = 'store.ProductCategory' query = f"SELECT COUNT(*) FROM {object_name}" result = self.engine.execute(query).fetchall() assert result[0] == (0, ) ahjo.execute_from_file(self.engine, f'database/data/{object_name}.sql') result = self.engine.execute(query).fetchall() assert result[0] == (3, )
def test_execute_from_file_should_create_view(self, object_name): schema, name = object_name.split('.') query = "SELECT * FROM INFORMATION_SCHEMA.VIEWS WHERE TABLE_SCHEMA = ? AND TABLE_NAME = ?" result = self.engine.execute(query, (schema, name)).fetchall() assert not result ahjo.execute_from_file(self.engine, f'database/views/{object_name}.sql') result = self.engine.execute(query, (schema, name)).fetchall() assert len(result) == 1
def test_split_to_batches_with_mssql_dialect_should_split_with_indented_go( self, mssql_sample, file_name): result = ahjo.execute_from_file( self.engine, path.join(mssql_sample, f'database/tests/{file_name}.sql')) assert result[0][0] == 1 assert result[1][0] == 2
def test_split_to_batches_should_preserve_tabs(self, mssql_sample, file_name): result = ahjo.execute_from_file( self.engine, path.join(mssql_sample, f'database/tests/{file_name}.sql')) assert result[0][0] == 2 assert result[1][0] == 1
def test_execute_from_file_should_return_query_results( self, query_name, result_set): query_result = ahjo.execute_from_file( self.engine, f'database/tests/{query_name}.sql', include_headers=True) assert query_result == result_set
def test_execute_from_file_should_handle_variables(self, query_name, result_set, test_db_name): query_result = ahjo.execute_from_file( self.engine, f'database/tests/{query_name}.sql', scripting_variables={"DB_NAME": test_db_name}, include_headers=True) assert query_result == result_set
def test_execute_from_file_should_not_raise_error_if_file_contains_colon( self, mssql_sample, file_name): ahjo.execute_from_file( self.engine, path.join(mssql_sample, f'database/tests/{file_name}.sql'))
def test_execute_from_file_should_raise_error_if_file_is_not_utf_8_bom( mssql_sample, file_name): sql_file = path.join(mssql_sample, f'database/error/{file_name}.sql') with pytest.raises(ValueError): ahjo.execute_from_file(None, sql_file)