Skip to content

Commit

Permalink
tests: output response content on assertion error
Browse files Browse the repository at this point in the history
  • Loading branch information
bouttier committed Sep 27, 2024
1 parent 7f34092 commit 3301594
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions backend/gn_module_export/tests/test_blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def test_private_export_without_token_or_login(self, users, exports):
id_export=exports["private_user_associated"].id,
)
)
assert response.status_code == 403
assert response.status_code == 403, response.data

def test_private_export_with_fake_token(self, users, exports):
# with fake token
Expand All @@ -32,7 +32,7 @@ def test_private_export_with_fake_token(self, users, exports):
token="fake_token",
)
)
assert response.status_code == 403
assert response.status_code == 403, response.data

def test_private_export_with_good_token(self, users, exports):
# With good token
Expand All @@ -43,7 +43,7 @@ def test_private_export_with_good_token(self, users, exports):
token=exports["private_user_associated"].cor_roles_exports[0].token,
)
)
assert response.status_code == 200
assert response.status_code == 200, response.data

@pytest.mark.skipif(
os.environ.get("CI") == "true",
Expand All @@ -66,8 +66,8 @@ def test_private_export_with_token_in_header_Authorization_Bearer(self, users, e
),
headers=headers,
)
assert response.status_code == 200, response.data
assert response.request.headers["api-key"] == token
assert response.status_code == 200

def test_private_export_with_token_in_header_Authorization(self, users, exports):
# Compatibility with Swagger not adding "Bearer" prefix to authorization header value
Expand All @@ -86,8 +86,8 @@ def test_private_export_with_token_in_header_Authorization(self, users, exports)
),
headers=headers,
)
assert response.status_code == 200, response.data
assert response.request.headers["api-key"] == token
assert response.status_code == 200

def test_private_export_with_allowed_id_role(self, users, exports):
# with an allowed user and without token
Expand All @@ -98,7 +98,7 @@ def test_private_export_with_allowed_id_role(self, users, exports):
id_export=exports["private_user_associated"].id,
)
)
assert response.status_code == 200
assert response.status_code == 200, response.data

def test_private_admin_export(self, exports, users):
set_logged_user_cookie(self.client, users["admin_user"])
Expand All @@ -108,7 +108,7 @@ def test_private_admin_export(self, exports, users):
id_export=exports["private_user_associated"].id,
)
)
assert response.status_code == 200
assert response.status_code == 200, response.data

def test_private_export_with_allowed_group(self, group_and_user, exports):
# log with a user which is in a group associated with "private_group_associated" export
Expand All @@ -119,7 +119,7 @@ def test_private_export_with_allowed_group(self, group_and_user, exports):
id_export=exports["private_group_associated"].id,
)
)
assert response.status_code == 200
assert response.status_code == 200, response.data

def test_private_export_with_scope_3(self, users, exports):
set_logged_user_cookie(self.client, users["admin_user"])
Expand All @@ -129,7 +129,7 @@ def test_private_export_with_scope_3(self, users, exports):
id_export=exports["private_user_associated"].id,
)
)
assert response.status_code == 200
assert response.status_code == 200, response.data

def test_private_export_with_unautorized_user(self, users, exports):
# with an not allowed user and without token
Expand All @@ -140,7 +140,7 @@ def test_private_export_with_unautorized_user(self, users, exports):
id_export=exports["private_user_associated"].id,
)
)
assert response.status_code == 403
assert response.status_code == 403, response.data

def test_get_one_export_api_public(self, exports):
response = self.client.get(
Expand All @@ -149,7 +149,7 @@ def test_get_one_export_api_public(self, exports):
id_export=exports["public"].id,
)
)
assert response.status_code == 200
assert response.status_code == 200, response.data

def test_export_schema(self, exports, users):
schema = {
Expand All @@ -176,7 +176,7 @@ def test_export_schema(self, exports, users):
id_export=exports["private_user_associated"].id,
)
)
assert response.status_code == 200
assert response.status_code == 200, response.data
validate_json(instance=response.json, schema=schema)

def test_export_orderby(self, synthese_data, export_synthese_sinp, users):
Expand All @@ -187,7 +187,7 @@ def test_export_orderby(self, synthese_data, export_synthese_sinp, users):
id_export=export_synthese_sinp.id,
)
)
assert response.status_code == 200
assert response.status_code == 200, response.data

unordered_id_synthese = [i["id_synthese"] for i in response.json["items"]]
ordered_id_synthese = sorted(unordered_id_synthese)
Expand All @@ -203,19 +203,20 @@ def test_export_orderby(self, synthese_data, export_synthese_sinp, users):
"exports.get_one_export_api", id_export=export_synthese_sinp.id, orderby="cd_nom"
)
)
assert response.status_code == 200, response.data
return_cd_noms = [i["cd_nom"] for i in response.json["items"]]
assert ordered_cd_noms == return_cd_noms

def test_unknown_export(self, exports, users):
set_logged_user_cookie(self.client, users["admin_user"])
response = self.client.get(url_for("exports.get_one_export_api", id_export=1000000))
assert response.status_code == 404
assert response.status_code == 404, response.data

def test_get_all_exports_with_scope_3(self, exports, users):
fixtures_export_id = set([export.id for _, export in exports.items()])
set_logged_user_cookie(self.client, users["admin_user"])
response = self.client.get(url_for("exports.get_exports"))
assert response.status_code == 200
assert response.status_code == 200, response.data
response_id_export = set([exp["id"] for exp in response.json])
assert fixtures_export_id.issubset(response_id_export)

Expand All @@ -226,7 +227,7 @@ def test_get_all_exports_with_scope_1_2_no_group(self, exports, users):
allowed_fixture_ids.add(exp.id)
set_logged_user_cookie(self.client, users["self_user"])
response = self.client.get(url_for("exports.get_exports"))
assert response.status_code == 200
assert response.status_code == 200, response.data
response_id_export = set([exp["id"] for exp in response.json])
assert allowed_fixture_ids.issubset(response_id_export)

Expand All @@ -237,7 +238,7 @@ def test_get_all_exports_with_scope_1_2_group(self, exports, users, group_and_us
allowed_fixture_ids.add(exp.id)
set_logged_user_cookie(self.client, group_and_user["user"])
response = self.client.get(url_for("exports.get_exports"))
assert response.status_code == 200
assert response.status_code == 200, response.data
response_id_export = set([exp["id"] for exp in response.json])
assert allowed_fixture_ids.issubset(response_id_export)

Expand All @@ -249,5 +250,5 @@ def test_get_all_exports_with_empty_response(self, users, group_and_user):
db.session.delete(export)
set_logged_user_cookie(self.client, group_and_user["user"])
response = self.client.get(url_for("exports.get_exports"))
assert response.status_code == 200
assert response.status_code == 200, response.data
assert response.json == []

0 comments on commit 3301594

Please sign in to comment.