forked from hasura/graphql-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_naming_conventions.py
150 lines (118 loc) · 5.43 KB
/
test_naming_conventions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
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')
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'})
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')
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'})
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')
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',
},
})
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')
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):
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')