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

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

151 lines
5.4 KiB
Python
Raw Normal View History

import pytest
from validate import check_query_f
@pytest.mark.hge_env('HASURA_GRAPHQL_EXPERIMENTAL_FEATURES', 'naming_convention')
class TestNamingConventions:
@classmethod
def dir(cls):
return "queries/naming_conventions"
@pytest.fixture(scope='class', autouse=True)
def add_customized_source(self, add_source):
add_source('pg1', customization={'naming_convention': 'graphql-default'})
def test_field_name_precedence(self, hge_ctx):
check_query_f(hge_ctx, self.dir() + '/field_name_precedence.yaml')
def test_enum_value_convention(self, hge_ctx):
check_query_f(hge_ctx, self.dir() + '/enum_value_convention.yaml')
@pytest.mark.hge_env('HASURA_GRAPHQL_EXPERIMENTAL_FEATURES', 'naming_convention')
server/tests-py: Split the naming convention tests. This splits two naming convention tests into four classes (and four YAML files), which might seem overkill, but allows us to provision sources declaratively in the future. As each class will require a custom source configuration, we are able to annotate them accordingly, which means the test cases are decoupled from the source database URL, letting us generate a new database for each test case and automatically add it as a source to HGE. The future changes are already prepared, but this has been extracted out as it splits the YAML files, which is a large change best reviewed in isolation. The test case `test_type_and_field_names` has been split into: * `TestNamingConventionsTypeAndFieldNamesGraphqlDefault` * `TestNamingConventionsTypeAndFieldNamesHasuraDefault` The test case `test_type_and_field_names_with_prefix_and_suffix` has been split into: * `TestNamingConventionsTypeAndFieldNamesGraphqlDefaultWithPrefixAndSuffix` * `TestNamingConventionsTypeAndFieldNamesHasuraDefaultWithPrefixAndSuffix` The YAML files have been split in the same way. This was fairly trivial as each test case would add a source, run some tests with the `graphql_default` naming convention, drop the source, and then repeat for the `hasura_default` naming convention. I simply split the file in two. There is a little bit of duplication for provisioning the various database tables, which I think is worth it. PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5496 GitOrigin-RevId: 94825e755c427a5414230f69985b534991b3aad6
2022-08-17 07:35:03 +03:00
class TestNamingConventionsTypeAndFieldNamesGraphqlDefault:
@classmethod
def dir(cls):
return "queries/naming_conventions"
@pytest.fixture(scope='class', autouse=True)
def add_customized_source(self, add_source):
add_source('pg1', customization={'naming_convention': 'graphql-default'})
server/tests-py: Split the naming convention tests. This splits two naming convention tests into four classes (and four YAML files), which might seem overkill, but allows us to provision sources declaratively in the future. As each class will require a custom source configuration, we are able to annotate them accordingly, which means the test cases are decoupled from the source database URL, letting us generate a new database for each test case and automatically add it as a source to HGE. The future changes are already prepared, but this has been extracted out as it splits the YAML files, which is a large change best reviewed in isolation. The test case `test_type_and_field_names` has been split into: * `TestNamingConventionsTypeAndFieldNamesGraphqlDefault` * `TestNamingConventionsTypeAndFieldNamesHasuraDefault` The test case `test_type_and_field_names_with_prefix_and_suffix` has been split into: * `TestNamingConventionsTypeAndFieldNamesGraphqlDefaultWithPrefixAndSuffix` * `TestNamingConventionsTypeAndFieldNamesHasuraDefaultWithPrefixAndSuffix` The YAML files have been split in the same way. This was fairly trivial as each test case would add a source, run some tests with the `graphql_default` naming convention, drop the source, and then repeat for the `hasura_default` naming convention. I simply split the file in two. There is a little bit of duplication for provisioning the various database tables, which I think is worth it. PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5496 GitOrigin-RevId: 94825e755c427a5414230f69985b534991b3aad6
2022-08-17 07:35:03 +03:00
def test_type_and_field_names(self, hge_ctx):
check_query_f(hge_ctx, self.dir() + '/type_and_field_names_graphql_default.yaml')
@pytest.mark.hge_env('HASURA_GRAPHQL_EXPERIMENTAL_FEATURES', 'naming_convention')
server/tests-py: Split the naming convention tests. This splits two naming convention tests into four classes (and four YAML files), which might seem overkill, but allows us to provision sources declaratively in the future. As each class will require a custom source configuration, we are able to annotate them accordingly, which means the test cases are decoupled from the source database URL, letting us generate a new database for each test case and automatically add it as a source to HGE. The future changes are already prepared, but this has been extracted out as it splits the YAML files, which is a large change best reviewed in isolation. The test case `test_type_and_field_names` has been split into: * `TestNamingConventionsTypeAndFieldNamesGraphqlDefault` * `TestNamingConventionsTypeAndFieldNamesHasuraDefault` The test case `test_type_and_field_names_with_prefix_and_suffix` has been split into: * `TestNamingConventionsTypeAndFieldNamesGraphqlDefaultWithPrefixAndSuffix` * `TestNamingConventionsTypeAndFieldNamesHasuraDefaultWithPrefixAndSuffix` The YAML files have been split in the same way. This was fairly trivial as each test case would add a source, run some tests with the `graphql_default` naming convention, drop the source, and then repeat for the `hasura_default` naming convention. I simply split the file in two. There is a little bit of duplication for provisioning the various database tables, which I think is worth it. PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5496 GitOrigin-RevId: 94825e755c427a5414230f69985b534991b3aad6
2022-08-17 07:35:03 +03:00
class TestNamingConventionsTypeAndFieldNamesHasuraDefault:
@classmethod
def dir(cls):
return "queries/naming_conventions"
@pytest.fixture(scope='class', autouse=True)
def add_customized_source(self, add_source):
add_source('pg1', customization={'naming_convention': 'hasura-default'})
server/tests-py: Split the naming convention tests. This splits two naming convention tests into four classes (and four YAML files), which might seem overkill, but allows us to provision sources declaratively in the future. As each class will require a custom source configuration, we are able to annotate them accordingly, which means the test cases are decoupled from the source database URL, letting us generate a new database for each test case and automatically add it as a source to HGE. The future changes are already prepared, but this has been extracted out as it splits the YAML files, which is a large change best reviewed in isolation. The test case `test_type_and_field_names` has been split into: * `TestNamingConventionsTypeAndFieldNamesGraphqlDefault` * `TestNamingConventionsTypeAndFieldNamesHasuraDefault` The test case `test_type_and_field_names_with_prefix_and_suffix` has been split into: * `TestNamingConventionsTypeAndFieldNamesGraphqlDefaultWithPrefixAndSuffix` * `TestNamingConventionsTypeAndFieldNamesHasuraDefaultWithPrefixAndSuffix` The YAML files have been split in the same way. This was fairly trivial as each test case would add a source, run some tests with the `graphql_default` naming convention, drop the source, and then repeat for the `hasura_default` naming convention. I simply split the file in two. There is a little bit of duplication for provisioning the various database tables, which I think is worth it. PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5496 GitOrigin-RevId: 94825e755c427a5414230f69985b534991b3aad6
2022-08-17 07:35:03 +03:00
def test_type_and_field_names(self, hge_ctx):
check_query_f(hge_ctx, self.dir() + '/type_and_field_names_hasura_default.yaml')
@pytest.mark.hge_env('HASURA_GRAPHQL_EXPERIMENTAL_FEATURES', 'naming_convention')
server/tests-py: Split the naming convention tests. This splits two naming convention tests into four classes (and four YAML files), which might seem overkill, but allows us to provision sources declaratively in the future. As each class will require a custom source configuration, we are able to annotate them accordingly, which means the test cases are decoupled from the source database URL, letting us generate a new database for each test case and automatically add it as a source to HGE. The future changes are already prepared, but this has been extracted out as it splits the YAML files, which is a large change best reviewed in isolation. The test case `test_type_and_field_names` has been split into: * `TestNamingConventionsTypeAndFieldNamesGraphqlDefault` * `TestNamingConventionsTypeAndFieldNamesHasuraDefault` The test case `test_type_and_field_names_with_prefix_and_suffix` has been split into: * `TestNamingConventionsTypeAndFieldNamesGraphqlDefaultWithPrefixAndSuffix` * `TestNamingConventionsTypeAndFieldNamesHasuraDefaultWithPrefixAndSuffix` The YAML files have been split in the same way. This was fairly trivial as each test case would add a source, run some tests with the `graphql_default` naming convention, drop the source, and then repeat for the `hasura_default` naming convention. I simply split the file in two. There is a little bit of duplication for provisioning the various database tables, which I think is worth it. PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5496 GitOrigin-RevId: 94825e755c427a5414230f69985b534991b3aad6
2022-08-17 07:35:03 +03:00
class TestNamingConventionsTypeAndFieldNamesGraphqlDefaultWithPrefixAndSuffix:
@classmethod
def dir(cls):
return "queries/naming_conventions"
@pytest.fixture(scope='class', autouse=True)
def add_customized_source(self, add_source):
add_source('pg1', customization={
'naming_convention': 'graphql-default',
'root_fields': {
'prefix': 'test',
'suffix': 'query',
},
})
server/tests-py: Split the naming convention tests. This splits two naming convention tests into four classes (and four YAML files), which might seem overkill, but allows us to provision sources declaratively in the future. As each class will require a custom source configuration, we are able to annotate them accordingly, which means the test cases are decoupled from the source database URL, letting us generate a new database for each test case and automatically add it as a source to HGE. The future changes are already prepared, but this has been extracted out as it splits the YAML files, which is a large change best reviewed in isolation. The test case `test_type_and_field_names` has been split into: * `TestNamingConventionsTypeAndFieldNamesGraphqlDefault` * `TestNamingConventionsTypeAndFieldNamesHasuraDefault` The test case `test_type_and_field_names_with_prefix_and_suffix` has been split into: * `TestNamingConventionsTypeAndFieldNamesGraphqlDefaultWithPrefixAndSuffix` * `TestNamingConventionsTypeAndFieldNamesHasuraDefaultWithPrefixAndSuffix` The YAML files have been split in the same way. This was fairly trivial as each test case would add a source, run some tests with the `graphql_default` naming convention, drop the source, and then repeat for the `hasura_default` naming convention. I simply split the file in two. There is a little bit of duplication for provisioning the various database tables, which I think is worth it. PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5496 GitOrigin-RevId: 94825e755c427a5414230f69985b534991b3aad6
2022-08-17 07:35:03 +03:00
def test_type_and_field_names_with_prefix_and_suffix(self, hge_ctx):
check_query_f(hge_ctx, self.dir() + '/type_and_field_names_graphql_default_with_prefix_and_suffix.yaml')
@pytest.mark.hge_env('HASURA_GRAPHQL_EXPERIMENTAL_FEATURES', 'naming_convention')
server/tests-py: Split the naming convention tests. This splits two naming convention tests into four classes (and four YAML files), which might seem overkill, but allows us to provision sources declaratively in the future. As each class will require a custom source configuration, we are able to annotate them accordingly, which means the test cases are decoupled from the source database URL, letting us generate a new database for each test case and automatically add it as a source to HGE. The future changes are already prepared, but this has been extracted out as it splits the YAML files, which is a large change best reviewed in isolation. The test case `test_type_and_field_names` has been split into: * `TestNamingConventionsTypeAndFieldNamesGraphqlDefault` * `TestNamingConventionsTypeAndFieldNamesHasuraDefault` The test case `test_type_and_field_names_with_prefix_and_suffix` has been split into: * `TestNamingConventionsTypeAndFieldNamesGraphqlDefaultWithPrefixAndSuffix` * `TestNamingConventionsTypeAndFieldNamesHasuraDefaultWithPrefixAndSuffix` The YAML files have been split in the same way. This was fairly trivial as each test case would add a source, run some tests with the `graphql_default` naming convention, drop the source, and then repeat for the `hasura_default` naming convention. I simply split the file in two. There is a little bit of duplication for provisioning the various database tables, which I think is worth it. PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5496 GitOrigin-RevId: 94825e755c427a5414230f69985b534991b3aad6
2022-08-17 07:35:03 +03:00
class TestNamingConventionsTypeAndFieldNamesHasuraDefaultWithPrefixAndSuffix:
@classmethod
def dir(cls):
return "queries/naming_conventions"
@pytest.fixture(scope='class', autouse=True)
def add_customized_source(self, add_source):
add_source('pg1', customization={
'naming_convention': 'hasura-default',
'root_fields': {
'prefix': 'test_',
'suffix': '_query',
},
})
def test_type_and_field_names_with_prefix_and_suffix(self, hge_ctx):
server/tests-py: Split the naming convention tests. This splits two naming convention tests into four classes (and four YAML files), which might seem overkill, but allows us to provision sources declaratively in the future. As each class will require a custom source configuration, we are able to annotate them accordingly, which means the test cases are decoupled from the source database URL, letting us generate a new database for each test case and automatically add it as a source to HGE. The future changes are already prepared, but this has been extracted out as it splits the YAML files, which is a large change best reviewed in isolation. The test case `test_type_and_field_names` has been split into: * `TestNamingConventionsTypeAndFieldNamesGraphqlDefault` * `TestNamingConventionsTypeAndFieldNamesHasuraDefault` The test case `test_type_and_field_names_with_prefix_and_suffix` has been split into: * `TestNamingConventionsTypeAndFieldNamesGraphqlDefaultWithPrefixAndSuffix` * `TestNamingConventionsTypeAndFieldNamesHasuraDefaultWithPrefixAndSuffix` The YAML files have been split in the same way. This was fairly trivial as each test case would add a source, run some tests with the `graphql_default` naming convention, drop the source, and then repeat for the `hasura_default` naming convention. I simply split the file in two. There is a little bit of duplication for provisioning the various database tables, which I think is worth it. PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5496 GitOrigin-RevId: 94825e755c427a5414230f69985b534991b3aad6
2022-08-17 07:35:03 +03:00
check_query_f(hge_ctx, self.dir() + '/type_and_field_names_hasura_default_with_prefix_and_suffix.yaml')
@pytest.mark.backend('mssql')
@pytest.mark.hge_env('HASURA_GRAPHQL_EXPERIMENTAL_FEATURES', 'naming_convention')
class TestNamingConventionsFailure:
@classmethod
def dir(cls):
return "queries/naming_conventions"
def test_other_than_pg_db_failure(self, hge_ctx):
response = hge_ctx.v1metadataq(
q={
"type": "mssql_add_source",
"args": {
"name": "mssql_naming_conventions_db",
"configuration": {
"connection_info": {
"connection_string": {
"from_env": "HASURA_GRAPHQL_MSSQL_SOURCE_URL",
},
},
},
"customization": {
"naming_convention": "graphql-default",
},
}
},
expected_status_code=400,
)
assert response == {
"code": "not-supported",
"path": "$.args",
"error": "sources other than postgres do not support graphql-default as naming convention yet",
}
@pytest.mark.hge_env('HASURA_GRAPHQL_EXPERIMENTAL_FEATURES', 'naming_convention')
@pytest.mark.hge_env('HASURA_GRAPHQL_DEFAULT_NAMING_CONVENTION', 'graphql-default')
class TestDefaultNamingConvention:
@classmethod
def dir(cls):
return "queries/naming_conventions"
@pytest.fixture(scope='class', autouse=True)
def add_another_source(self, add_source):
add_source('pg1')
def test_default_global_naming_convention(self, hge_ctx):
check_query_f(hge_ctx, self.dir() + '/default_global_naming_convention.yaml')
@pytest.mark.hge_env('HASURA_GRAPHQL_EXPERIMENTAL_FEATURES', None) # must be unset
class TestNamingConventionWithoutExperimentalFeature:
@classmethod
def dir(cls):
return "queries/naming_conventions"
@pytest.fixture(scope='class', autouse=True)
def add_customized_source(self, add_source):
add_source('pg1', customization={'naming_convention': 'graphql-default'})
def test_naming_convention_without_feature_turned_on(self, hge_ctx):
check_query_f(hge_ctx, self.dir() + '/naming_convention_without_feature_turned_on.yaml')