def test_generated_openapi_json_spec(flowapi_url, diff_reporter): """ Verify the OpenAPI spec for FlowAPI. """ spec = requests.get(f"{flowapi_url}/api/0/spec/openapi.json").json() spec_version = spec["info"].pop("version") assert spec_version == flowapi.__version__ spec_as_json_string = json.dumps(sort_recursively(spec), indent=2, sort_keys=True) diff_reporter(spec_as_json_string)
def test_generated_openapi_yaml_spec(flowapi_url, diff_reporter): """ Verify the OpenAPI spec for FlowAPI in yaml form. """ spec = yaml.load( requests.get(f"{flowapi_url}/api/0/spec/openapi.yaml").content) spec_version = spec["info"].pop("version") assert spec_version == flowapi.__version__ spec_as_json_string = json.dumps(sort_recursively(spec), indent=2, sort_keys=True) verify(spec_as_json_string, diff_reporter)
def test_api_spec_of_flowmachine_query_schemas(zmq_host, zmq_port, diff_reporter): """ Verify the API spec for flowmachine queries. """ msg = {"action": "get_query_schemas", "request_id": "DUMMY_ID"} reply = send_zmq_message_and_receive_reply(msg, port=zmq_port, host=zmq_host) print(reply) assert "success" == reply["status"] spec_as_json_string = json.dumps( sort_recursively(reply["payload"]["query_schemas"]), indent=2 ) diff_reporter(spec_as_json_string)
def test_sort_recursively(): """ Test that `sort_recursively` recursively sorts all components of the input dictionary. """ d = { "cc": { "foo": 23, "bar": 42 }, "aa": [("quux2", 100), ("quux1", 200)], "bb": "hello", } d_sorted_expected = { "aa": [("quux1", 200), ("quux2", 100)], "bb": "hello", "cc": { "bar": 42, "foo": 23 }, } assert d_sorted_expected == sort_recursively(d)