2022-05-26 14:54:30 +03:00
|
|
|
import ruamel.yaml as yaml
|
|
|
|
from validate import check_query_f
|
|
|
|
import pytest
|
|
|
|
import os
|
|
|
|
|
2022-07-05 15:36:17 +03:00
|
|
|
|
|
|
|
def env_var_contains(name, contents):
|
|
|
|
value = os.getenv(name)
|
|
|
|
return value != None and contents in value
|
|
|
|
|
2022-05-26 14:54:30 +03:00
|
|
|
@pytest.mark.skipif(
|
2022-07-05 15:36:17 +03:00
|
|
|
not env_var_contains('HASURA_GRAPHQL_EXPERIMENTAL_FEATURES', 'naming_convention'),
|
2022-05-27 08:55:45 +03:00
|
|
|
reason="This test expects the (naming_convention) experimental feature turned on")
|
2022-05-26 14:54:30 +03:00
|
|
|
class TestNamingConventions:
|
|
|
|
|
|
|
|
@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.yaml')
|
|
|
|
|
|
|
|
def test_field_name_precedence(self, hge_ctx):
|
|
|
|
check_query_f(hge_ctx, self.dir() + '/field_name_precedence.yaml')
|
2022-07-05 15:36:17 +03:00
|
|
|
|
2022-05-26 14:54:30 +03:00
|
|
|
def test_enum_value_convention(self, hge_ctx):
|
|
|
|
check_query_f(hge_ctx, self.dir() + '/enum_value_convention.yaml')
|
2022-07-05 15:36:17 +03:00
|
|
|
|
|
|
|
def test_type_and_field_names_with_prefix_and_suffix(self, hge_ctx):
|
2022-05-26 14:54:30 +03:00
|
|
|
check_query_f(hge_ctx, self.dir() + '/type_and_field_names_with_prefix_and_suffix.yaml')
|
|
|
|
|
|
|
|
@pytest.mark.parametrize("backend", ['mssql'])
|
|
|
|
class TestNamingConventionsFailure:
|
|
|
|
@classmethod
|
|
|
|
def dir(cls):
|
|
|
|
return "queries/naming_conventions"
|
2022-07-05 15:36:17 +03:00
|
|
|
|
2022-05-26 14:54:30 +03:00
|
|
|
def test_other_than_pg_db_failure(self, hge_ctx):
|
|
|
|
check_query_f(hge_ctx, self.dir() + '/mssql_naming_convention.yaml')
|
|
|
|
|
|
|
|
@pytest.mark.skipif(
|
2022-07-19 09:55:42 +03:00
|
|
|
not env_var_contains('HASURA_GRAPHQL_EXPERIMENTAL_FEATURES', 'naming_convention') or
|
2022-07-05 15:36:17 +03:00
|
|
|
not env_var_contains('HASURA_GRAPHQL_DEFAULT_NAMING_CONVENTION', 'graphql-default'),
|
2022-05-26 14:54:30 +03:00
|
|
|
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"
|
2022-07-05 15:36:17 +03:00
|
|
|
|
2022-05-26 14:54:30 +03:00
|
|
|
def test_default_global_naming_convention(self, hge_ctx):
|
|
|
|
check_query_f(hge_ctx, self.dir() + '/default_global_naming_convention.yaml')
|
2022-06-30 08:55:50 +03:00
|
|
|
|
2022-07-05 15:36:17 +03:00
|
|
|
@pytest.mark.skipif(
|
|
|
|
env_var_contains('HASURA_GRAPHQL_EXPERIMENTAL_FEATURES', 'naming_convention'),
|
2022-06-30 08:55:50 +03:00
|
|
|
reason="This test expects the (naming_convention) experimental feature turned OFF")
|
|
|
|
class TestNamingConventionWithoutExperimentalFeature:
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def dir(cls):
|
|
|
|
return "queries/naming_conventions"
|
2022-07-05 15:36:17 +03:00
|
|
|
|
2022-06-30 08:55:50 +03:00
|
|
|
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')
|