mirror of
https://github.com/LukeHagar/connexion.git
synced 2025-12-09 20:37:46 +00:00
Make tests framework agnostic
This commit is contained in:
@@ -41,63 +41,71 @@ def test_validator_map(json_validation_spec_dir, spec):
|
||||
"/v1.0/minlength",
|
||||
data=json.dumps({"foo": "bar"}),
|
||||
content_type="application/json",
|
||||
) # type: flask.Response
|
||||
)
|
||||
assert res.status_code == 200
|
||||
|
||||
res = app_client.post(
|
||||
"/v1.0/minlength", data=json.dumps({"foo": ""}), content_type="application/json"
|
||||
) # type: flask.Response
|
||||
)
|
||||
assert res.status_code == 400
|
||||
|
||||
|
||||
def test_readonly(json_validation_spec_dir, spec):
|
||||
def test_readonly(json_validation_spec_dir, spec, app_class):
|
||||
app = build_app_from_fixture(
|
||||
json_validation_spec_dir, spec, validate_responses=True
|
||||
json_validation_spec_dir,
|
||||
app_class=app_class,
|
||||
spec_file=spec,
|
||||
validate_responses=True,
|
||||
)
|
||||
app_client = app.test_client()
|
||||
|
||||
res = app_client.get("/v1.0/user") # type: flask.Response
|
||||
headers = {"content-type": "application/json"}
|
||||
|
||||
res = app_client.get("/v1.0/user")
|
||||
assert res.status_code == 200
|
||||
assert json.loads(res.data.decode()).get("user_id") == 7
|
||||
assert json.loads(res.text).get("user_id") == 7
|
||||
|
||||
res = app_client.post(
|
||||
"/v1.0/user",
|
||||
data=json.dumps({"name": "max", "password": "1234"}),
|
||||
content_type="application/json",
|
||||
) # type: flask.Response
|
||||
headers=headers,
|
||||
)
|
||||
assert res.status_code == 200
|
||||
assert json.loads(res.data.decode()).get("user_id") == 8
|
||||
assert json.loads(res.text).get("user_id") == 8
|
||||
|
||||
res = app_client.post(
|
||||
"/v1.0/user",
|
||||
data=json.dumps({"user_id": 9, "name": "max"}),
|
||||
content_type="application/json",
|
||||
) # type: flask.Response
|
||||
headers=headers,
|
||||
)
|
||||
assert res.status_code == 400
|
||||
|
||||
|
||||
def test_writeonly(json_validation_spec_dir, spec):
|
||||
def test_writeonly(json_validation_spec_dir, spec, app_class):
|
||||
app = build_app_from_fixture(
|
||||
json_validation_spec_dir, spec, validate_responses=True
|
||||
json_validation_spec_dir,
|
||||
app_class=app_class,
|
||||
spec_file=spec,
|
||||
validate_responses=True,
|
||||
)
|
||||
app_client = app.test_client()
|
||||
|
||||
res = app_client.post(
|
||||
"/v1.0/user",
|
||||
data=json.dumps({"name": "max", "password": "1234"}),
|
||||
content_type="application/json",
|
||||
) # type: flask.Response
|
||||
headers={"content-type": "application/json"},
|
||||
)
|
||||
assert res.status_code == 200
|
||||
assert "password" not in json.loads(res.data.decode())
|
||||
assert "password" not in json.loads(res.text)
|
||||
|
||||
res = app_client.get("/v1.0/user") # type: flask.Response
|
||||
res = app_client.get("/v1.0/user")
|
||||
assert res.status_code == 200
|
||||
assert "password" not in json.loads(res.data.decode())
|
||||
assert "password" not in json.loads(res.text)
|
||||
|
||||
res = app_client.get("/v1.0/user_with_password") # type: flask.Response
|
||||
res = app_client.get("/v1.0/user_with_password")
|
||||
assert res.status_code == 500
|
||||
assert (
|
||||
json.loads(res.data.decode())["title"]
|
||||
json.loads(res.text)["title"]
|
||||
== "Response body does not conform to specification"
|
||||
)
|
||||
|
||||
@@ -108,17 +116,20 @@ def test_nullable_default(json_validation_spec_dir, spec):
|
||||
|
||||
|
||||
@pytest.mark.parametrize("spec", ["openapi.yaml"])
|
||||
def test_multipart_form_json(json_validation_spec_dir, spec):
|
||||
def test_multipart_form_json(json_validation_spec_dir, spec, app_class):
|
||||
app = build_app_from_fixture(
|
||||
json_validation_spec_dir, spec, validate_responses=True
|
||||
json_validation_spec_dir,
|
||||
app_class=app_class,
|
||||
spec_file=spec,
|
||||
validate_responses=True,
|
||||
)
|
||||
app_client = app.test_client()
|
||||
|
||||
res = app_client.post(
|
||||
"/v1.0/multipart_form_json",
|
||||
data={"x": json.dumps({"name": "joe", "age": 20})},
|
||||
content_type="multipart/form-data",
|
||||
headers={"content-type": "multipart/form-data"},
|
||||
)
|
||||
assert res.status_code == 200
|
||||
assert json.loads(res.data.decode())["name"] == "joe-reply"
|
||||
assert json.loads(res.data.decode())["age"] == 30
|
||||
assert json.loads(res.text)["name"] == "joe-reply"
|
||||
assert json.loads(res.text)["age"] == 30
|
||||
|
||||
Reference in New Issue
Block a user