From d3b5d3f213c640b019ed7a3db60063dbd2831289 Mon Sep 17 00:00:00 2001 From: Sietse Snel Date: Wed, 17 Apr 2024 14:49:08 +0200 Subject: [PATCH] YDA-5664: fix delete API call that had no effect Also adjust integration tests to verify effect of calls to delete API endpoint. --- yoda_eus/app.py | 2 ++ yoda_eus/tests/test_integration.py | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/yoda_eus/app.py b/yoda_eus/app.py index 2590b62..b30cab6 100644 --- a/yoda_eus/app.py +++ b/yoda_eus/app.py @@ -229,6 +229,8 @@ def delete_user() -> Response: if len(UserZone.query.filter_by(user_id=user.id).all()) == 0: User.query.filter_by(username=content['username']).delete() + db.session.commit() + # Return result response = {"status": "ok", "message": "User {} deleted from zone {}.".format(content["username"], content["userzone"])} diff --git a/yoda_eus/tests/test_integration.py b/yoda_eus/tests/test_integration.py index 3009d96..ce576f5 100644 --- a/yoda_eus/tests/test_integration.py +++ b/yoda_eus/tests/test_integration.py @@ -66,6 +66,9 @@ def test_add_and_remove_user_once(self, test_client): assert response1.status_code == 201 response2 = c.post('/api/user/delete', json=rm_params, headers=auth_headers) assert response2.status_code == 204 + # This delete call is to verify that the user is really gone + response3 = c.post('/api/user/delete', json=rm_params, headers=auth_headers) + assert response3.status_code == 404 def test_add_and_remove_user_twice(self, test_client): auth_headers = {'X-Yoda-External-User-Secret': 'dummy_api_secret'} @@ -87,6 +90,9 @@ def test_add_and_remove_user_twice(self, test_client): assert response3.status_code == 204 response4 = c.post('/api/user/delete', json=rm2_params, headers=auth_headers) assert response4.status_code == 204 + # This delete call is to verify that the user is really gone + response5 = c.post('/api/user/delete', json=rm2_params, headers=auth_headers) + assert response5.status_code == 404 def test_forgot_password_show_form(self, test_client): with test_client as c: