mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-15 17:31:56 +03:00
91aee7fdeb
We add a new pytest flag `--accept` that will automatically write back yaml files with updated responses. This makes it much easier and less error-prone to update test cases when we expect output to change, or when authoring new tests. Second we make sure to test that we actually preserve the order of the selection set when returning results. This is a "SHOULD" part of the spec but seems pretty important and something that users will rely on. To support both of the above we use ruamel.yaml which preserves a certain amount of formatting and comments (so that --accept can work in a failry ergonomic way), as well as ordering (so that when we write yaml the order of keys has meaning that's preserved during parsing). Use ruamel.yaml everywhere for consistency (since both libraries have different quirks). Quirks of ruamel.yaml: - trailing whitespace in multiline strings in yaml files isn't written back out as we'd like: https://bitbucket.org/ruamel/yaml/issues/47/multiline-strings-being-changed-if-they - formatting is only sort of preserved; ruamel e.g. normalizes indentation. Normally the diff is pretty clean though, and you can always just check in portions of your test file after --accept fixup
58 lines
1.9 KiB
Python
58 lines
1.9 KiB
Python
#!/usrbin/env python3
|
|
|
|
import pytest
|
|
from validate import check_query, check_query_f
|
|
|
|
def check_post_404(hge_ctx,url):
|
|
return check_query(hge_ctx, {
|
|
'url': url,
|
|
'status': 404,
|
|
'query': {}
|
|
})[0]
|
|
|
|
|
|
@pytest.mark.skipif(not pytest.config.getoption("--test-metadata-disabled"),
|
|
reason="flag --test-metadata-disabled is not set. Cannot run tests for metadata disabled")
|
|
class TestMetadataDisabled:
|
|
|
|
def test_metadata_v1_query_disabled(self, hge_ctx):
|
|
check_post_404(hge_ctx,'/v1/query')
|
|
|
|
def test_metadata_v1_template_disabled(self, hge_ctx):
|
|
check_post_404(hge_ctx,'/v1/template/foo')
|
|
|
|
def test_metadata_api_1_disabled(self, hge_ctx):
|
|
check_post_404(hge_ctx,'/api/1/table/foo/select')
|
|
|
|
|
|
@pytest.mark.skipif(not pytest.config.getoption("--test-graphql-disabled"),
|
|
reason="--test-graphql-disabled is not set. Cannot run GraphQL disabled tests")
|
|
class TestGraphQLDisabled:
|
|
|
|
def test_graphql_endpoint_disabled(self, hge_ctx):
|
|
check_post_404(hge_ctx, '/v1/graphql')
|
|
|
|
def test_graphql_explain_disabled(self, hge_ctx):
|
|
check_post_404(hge_ctx, '/v1/graphql/explain')
|
|
|
|
|
|
@pytest.mark.skipif(pytest.config.getoption("--test-graphql-disabled"),
|
|
reason="--test-graphql-disabled is set. Cannot run GraphQL enabled tests")
|
|
class TestGraphQLEnabled:
|
|
|
|
def test_graphql_introspection(self, hge_ctx):
|
|
check_query_f(hge_ctx, "queries/graphql_introspection/introspection_only_kind_of_queryType.yaml")
|
|
|
|
|
|
@pytest.mark.skipif(pytest.config.getoption("--test-metadata-disabled"),
|
|
reason="--test-metadata-disabled is set. Cannot run metadata enabled tests")
|
|
class TestMetadataEnabled:
|
|
|
|
def test_reload_metadata(self, hge_ctx):
|
|
check_query_f(hge_ctx, "queries/v1/metadata/reload_metadata.yaml")
|
|
|
|
def test_run_sql(self, hge_ctx):
|
|
check_query_f(hge_ctx, "queries/v1/run_sql/sql_set_timezone.yaml")
|
|
|
|
|