mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-15 09:22:43 +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
32 lines
1015 B
Python
32 lines
1015 B
Python
import ruamel.yaml as yaml
|
|
from super_classes import DefaultTestSelectQueries
|
|
import os
|
|
|
|
resp_pg_version_map = {
|
|
'9_5': 'response_9',
|
|
'9_6': 'response_9',
|
|
'10': 'response_10_11',
|
|
'11': 'response_10_11',
|
|
'12': 'response_10_11',
|
|
'latest': 'response_10_11'
|
|
}
|
|
|
|
class TestPGDump(DefaultTestSelectQueries):
|
|
|
|
def test_pg_dump_for_public_schema(self, hge_ctx):
|
|
query_file = self.dir() + '/pg_dump_public.yaml'
|
|
PG_VERSION = os.getenv('PG_VERSION', 'latest')
|
|
with open(query_file, 'r') as stream:
|
|
q = yaml.safe_load(stream)
|
|
headers = {}
|
|
if hge_ctx.hge_key is not None:
|
|
headers['x-hasura-admin-secret'] = hge_ctx.hge_key
|
|
resp = hge_ctx.http.post(hge_ctx.hge_url + q['url'], json=q['query'], headers=headers)
|
|
body = resp.text
|
|
assert resp.status_code == q['status']
|
|
assert body == q[resp_pg_version_map[PG_VERSION]]
|
|
|
|
@classmethod
|
|
def dir(cls):
|
|
return "pgdump"
|