graphql-engine/server/tests-py/test_v2_queries.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

76 lines
2.8 KiB
Python
Raw Normal View History

from validate import check_query_f
import pytest
usefixtures = pytest.mark.usefixtures
# use_mutation_fixtures = usefixtures(
# 'per_class_db_schema_for_mutation_tests',
# 'per_method_db_data_for_mutation_tests'
# )
@usefixtures('per_class_tests_db_state')
class TestV2SelectBasic: # Basic RQL Tests on v2/query
@classmethod
def dir(cls):
return 'queries/v2/basic'
def test_select_query_author(self, hge_ctx):
check_query_f(hge_ctx, self.dir() + '/select_article.yaml')
def test_select_query_author_with_user_role_success(self, hge_ctx):
check_query_f(hge_ctx, self.dir() + '/select_article_role_success.yaml')
# TODO: Fix this test for JWT
# def test_select_query_author_with_user_role_failure(self, hge_ctx):
# check_query_f(hge_ctx, self.dir() + '/select_article_role_error.yaml')
server/mssql: add cascade to mssql_run_sql <!-- Thank you for ss in the Title above ^ --> ## Description <!-- Please fill thier. --> <!-- Describe the changes from a user's perspective --> We don't have dependency reporting mechanism for `mssql_run_sql` API i.e when a database object (table, column etc.) is dropped through the API we should raise an exception if any dependencies (relationships, permissions etc.) with the database object exists in the metadata. This PR addresses the above mentioned problem by -> Integrating transaction to the API to rollback the SQL query execution if dependencies exists and exception is thrown -> Accepting `cascade` optional field in the API payload to drop the dependencies, if any -> Accepting `check_metadata_consistency` optional field to bypass (if value set to `false`) the dependency check ### Related Issues <!-- Please make surt title --> <!-- Add the issue number below (e.g. #234) --> Close #1853 ### Solution and Design <!-- How is this iss --> <!-- It's better if we elaborate --> The design/solution follows the `run_sql` API implementation for Postgres backend. ### Steps to test and verify <!-- If this is a fehis is a bug-fix, how do we verify the fix? --> - Create author - article tables and track them - Defined object and array relationships - Try to drop the article table without cascade or cascade set to `false` - The server should raise the relationship dependency exists exception ## Changelog - ✅ `CHANGELOG.md` is updated with user-facing content relevant to this PR. If no changelog is required, then add the `no-changelog-required` label. ## Affected components <!-- Remove non-affected components from the list --> - ✅ Server - ❎ Console - ❎ CLI - ❎ Docs - ❎ Community Content - ❎ Build System - ✅ Tests - ❎ Other (list it) PR-URL: https://github.com/hasura/graphql-engine-mono/pull/2636 GitOrigin-RevId: 0ab152295394056c4ca6f02923142a1658ad25dc
2021-10-22 17:49:15 +03:00
@pytest.mark.parametrize("backend", ['mssql'])
@usefixtures('per_class_tests_db_state')
class TestRunSQLMSSQL:
def test_drop_article_table_without_cascade(self, hge_ctx, backend):
check_query_f(hge_ctx, self.dir() + '/drop_article_table_without_cascade.yaml')
def test_drop_article_table_with_cascade(self, hge_ctx, backend):
check_query_f(hge_ctx, self.dir() + '/drop_article_table_with_cascade.yaml')
def test_create_author_table_fail(self, hge_ctx, backend):
check_query_f(hge_ctx, self.dir() + '/create_author_table_fail.yaml')
def test_invalid_sql_query(self, hge_ctx, backend):
check_query_f(hge_ctx, self.dir() + '/invalid_sql_query.yaml')
def test_select_query(self, hge_ctx, backend):
check_query_f(hge_ctx, self.dir() + '/sql_select_query_mssql.yaml')
def test_drop_table(self, hge_ctx, backend):
check_query_f(hge_ctx, self.dir() + '/sql_drop_table_mssql.yaml')
def test_rename_table(self, hge_ctx, backend):
check_query_f(hge_ctx, self.dir() + '/sql_rename_table_mssql.yaml')
def test_drop_column(self, hge_ctx, backend):
check_query_f(hge_ctx, self.dir() + '/sql_drop_column_mssql.yaml')
def test_add_column(self, hge_ctx, backend):
check_query_f(hge_ctx, self.dir() + '/sql_add_column_mssql.yaml')
def test_rename_column(self, hge_ctx, backend):
check_query_f(hge_ctx, self.dir() + '/sql_rename_column_mssql.yaml')
def test_select_query_fail(self, hge_ctx, backend):
check_query_f(hge_ctx, self.dir() + '/sql_select_query_fail.yaml')
def test_add_column_fail(self, hge_ctx, backend):
check_query_f(hge_ctx, self.dir() + '/sql_add_column_fail.yaml')
def test_drop_column_fail(self, hge_ctx, backend):
check_query_f(hge_ctx, self.dir() + '/sql_drop_column_fail.yaml')
def test_create_index_fail(self, hge_ctx, backend):
check_query_f(hge_ctx, self.dir() + '/create_index_fail.yaml')
server/mssql: add cascade to mssql_run_sql <!-- Thank you for ss in the Title above ^ --> ## Description <!-- Please fill thier. --> <!-- Describe the changes from a user's perspective --> We don't have dependency reporting mechanism for `mssql_run_sql` API i.e when a database object (table, column etc.) is dropped through the API we should raise an exception if any dependencies (relationships, permissions etc.) with the database object exists in the metadata. This PR addresses the above mentioned problem by -> Integrating transaction to the API to rollback the SQL query execution if dependencies exists and exception is thrown -> Accepting `cascade` optional field in the API payload to drop the dependencies, if any -> Accepting `check_metadata_consistency` optional field to bypass (if value set to `false`) the dependency check ### Related Issues <!-- Please make surt title --> <!-- Add the issue number below (e.g. #234) --> Close #1853 ### Solution and Design <!-- How is this iss --> <!-- It's better if we elaborate --> The design/solution follows the `run_sql` API implementation for Postgres backend. ### Steps to test and verify <!-- If this is a fehis is a bug-fix, how do we verify the fix? --> - Create author - article tables and track them - Defined object and array relationships - Try to drop the article table without cascade or cascade set to `false` - The server should raise the relationship dependency exists exception ## Changelog - ✅ `CHANGELOG.md` is updated with user-facing content relevant to this PR. If no changelog is required, then add the `no-changelog-required` label. ## Affected components <!-- Remove non-affected components from the list --> - ✅ Server - ❎ Console - ❎ CLI - ❎ Docs - ❎ Community Content - ❎ Build System - ✅ Tests - ❎ Other (list it) PR-URL: https://github.com/hasura/graphql-engine-mono/pull/2636 GitOrigin-RevId: 0ab152295394056c4ca6f02923142a1658ad25dc
2021-10-22 17:49:15 +03:00
@classmethod
def dir(cls):
return 'queries/v2/mssql/run_sql'