MCPcopy
hub / github.com/hasura/graphql-engine / check_query_f

Function check_query_f

server/tests-py/validate.py:488–557  ·  view source on GitHub ↗
(hge_ctx, f, transport='http', add_auth=True, gqlws = False)

Source from the content-addressed store, hash-verified

486 return yaml.YAML().load(c)
487
488def check_query_f(hge_ctx, f, transport='http', add_auth=True, gqlws = False):
489 hge_ctx.may_skip_test_teardown = False
490 should_write_back = False
491
492 def add_spec(file, conf):
493 spec = None
494 response = conf.get('response')
495
496 status = conf.get('status')
497 if status is None:
498 status = 200
499
500 query = conf["query"]
501 if "query" in query:
502 query = query["query"]
503
504 headers = conf.get("headers")
505
506 spec = PortToHaskell.PostSpec(
507 conf.get("description"),
508 file,
509 conf["url"],
510 headers,
511 query, # TODO: handle variables
512 status,
513 response)
514
515 PortToHaskell.with_test(hge_ctx.request.cls.__qualname__).add_spec(
516 hge_ctx.request._pyfuncitem.originalname,
517 spec)
518
519 with open(f, 'r+') as c:
520 # ruamel will preserve order so that we can test the JSON ordering
521 # property conforms to YAML spec. It also lets us write back the yaml
522 # nicely when we `--accept.`
523 yml = yaml.YAML()
524
525 # NOTE: preserve ordering with ruamel
526 conf = yml.load(c)
527
528 if isinstance(conf, list):
529 for ix, sconf in enumerate(conf):
530 if PytestConf.config.getoption("--port-to-haskell"):
531 add_spec(f + " [" + str(ix) + "]", sconf)
532 else:
533 actual_resp, matched = check_query(hge_ctx, sconf, transport, add_auth, gqlws)
534 if PytestConf.config.getoption("--accept") and not matched:
535 conf[ix]['response'] = actual_resp
536 should_write_back = True
537 else:
538 if PytestConf.config.getoption("--port-to-haskell"):
539 add_spec(f, conf)
540 else:
541 if conf['status'] != 200:
542 hge_ctx.may_skip_test_teardown = True
543 actual_resp, matched = check_query(hge_ctx, conf, transport, add_auth, gqlws)
544 # If using `--accept` write the file back out with the new expected
545 # response set to the actual response we got:

Calls 4

add_specFunction · 0.85
check_queryFunction · 0.85
YAMLMethod · 0.80
openFunction · 0.50