From 3301594f36c03f42ad1084a71cf7ad6fb1db8891 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lie=20Bouttier?= Date: Fri, 27 Sep 2024 12:57:45 +0200 Subject: [PATCH] tests: output response content on assertion error --- .../gn_module_export/tests/test_blueprint.py | 37 ++++++++++--------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/backend/gn_module_export/tests/test_blueprint.py b/backend/gn_module_export/tests/test_blueprint.py index c740d43..7cca6d3 100644 --- a/backend/gn_module_export/tests/test_blueprint.py +++ b/backend/gn_module_export/tests/test_blueprint.py @@ -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 @@ -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 @@ -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", @@ -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 @@ -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 @@ -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"]) @@ -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 @@ -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"]) @@ -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 @@ -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( @@ -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 = { @@ -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): @@ -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) @@ -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) @@ -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) @@ -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) @@ -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 == []