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.

107 lines
4.1 KiB
Python
Raw Normal View History

import ruamel.yaml as yaml
from validate import check_query_f
import pytest
import os
def env_var_contains(name, contents):
value = os.getenv(name)
return value != None and contents in value
@pytest.mark.skipif(
not env_var_contains('HASURA_GRAPHQL_EXPERIMENTAL_FEATURES', 'naming_convention'),
reason="This test expects the (naming_convention) experimental feature turned on")
class TestNamingConventions:
@classmethod
def dir(cls):
return "queries/naming_conventions"
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')
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
@pytest.mark.skipif(
not env_var_contains('HASURA_GRAPHQL_EXPERIMENTAL_FEATURES', 'naming_convention'),
reason="This test expects the (naming_convention) experimental feature turned on")
class TestNamingConventionsTypeAndFieldNamesGraphqlDefault:
@classmethod
def dir(cls):
return "queries/naming_conventions"
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.skipif(
not env_var_contains('HASURA_GRAPHQL_EXPERIMENTAL_FEATURES', 'naming_convention'),
reason="This test expects the (naming_convention) experimental feature turned on")
class TestNamingConventionsTypeAndFieldNamesHasuraDefault:
@classmethod
def dir(cls):
return "queries/naming_conventions"
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.skipif(
not env_var_contains('HASURA_GRAPHQL_EXPERIMENTAL_FEATURES', 'naming_convention'),
reason="This test expects the (naming_convention) experimental feature turned on")
class TestNamingConventionsTypeAndFieldNamesGraphqlDefaultWithPrefixAndSuffix:
@classmethod
def dir(cls):
return "queries/naming_conventions"
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.skipif(
not env_var_contains('HASURA_GRAPHQL_EXPERIMENTAL_FEATURES', 'naming_convention'),
reason="This test expects the (naming_convention) experimental feature turned on")
class TestNamingConventionsTypeAndFieldNamesHasuraDefaultWithPrefixAndSuffix:
@classmethod
def dir(cls):
return "queries/naming_conventions"
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')
class TestNamingConventionsFailure:
@classmethod
def dir(cls):
return "queries/naming_conventions"
def test_other_than_pg_db_failure(self, hge_ctx):
check_query_f(hge_ctx, self.dir() + '/mssql_naming_convention.yaml')
@pytest.mark.skipif(
not env_var_contains('HASURA_GRAPHQL_EXPERIMENTAL_FEATURES', 'naming_convention') or
not env_var_contains('HASURA_GRAPHQL_DEFAULT_NAMING_CONVENTION', 'graphql-default'),
reason="This test expects the HASURA_GRAPHQL_DEFAULT_NAMING_CONVENTION environment variable set to graphql-default")
class TestDefaultNamingConvention:
@classmethod
def dir(cls):
return "queries/naming_conventions"
def test_default_global_naming_convention(self, hge_ctx):
check_query_f(hge_ctx, self.dir() + '/default_global_naming_convention.yaml')
@pytest.mark.skipif(
env_var_contains('HASURA_GRAPHQL_EXPERIMENTAL_FEATURES', 'naming_convention'),
reason="This test expects the (naming_convention) experimental feature turned OFF")
class TestNamingConventionWithoutExperimentalFeature:
@classmethod
def dir(cls):
return "queries/naming_conventions"
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')