From cffdba2d25ed0f8c814cec3d008784b16d18e81d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Tue, 28 Jul 2020 14:41:59 +0200 Subject: [PATCH] tests: adapt tests to new 401/403 differences: --- tests/test_api.py | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/tests/test_api.py b/tests/test_api.py index 7ddb1d5..96c0219 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -42,14 +42,14 @@ def test_signed_api_get(client_service, url_signed): def test_api_post(mock_phantomjs_result, client, url, payload): if client.session.values(): - status_code = {'success': 200, 'failure': 401} + status_code = {'success': 200, 'failure': (401, 403)} else: - status_code = {'success': 403, 'failure': 403} + status_code = {'success': 403, 'failure': (401, 403)} if payload.get('name_id_content') == '12345': response = client.post(url, data=payload, format='json') - assert response.status_code == status_code['failure'] + assert response.status_code in status_code['failure'] if client.session.values(): kevin = get_user(first_name='kevin') @@ -76,14 +76,14 @@ def test_api_post(mock_phantomjs_result, client, url, payload): @mock.patch('mandayejs.mandaye.api.exec_phantom') def test_signed_api_post(mock_phantomjs_result, client_service, url_signed, payload): if url_signed.orig == 'testserver': - status_code = {'success': 200, 'failure': 401} + status_code = {'success': 200, 'failure': (401, 403)} else: - status_code = {'success': 403, 'failure': 403} + status_code = {'success': 403, 'failure': (401, 403)} if payload.get('name_id_content') == '12345': response = client_service.post(url_signed.url, data=payload, format='json') - assert response.status_code == status_code['failure'] + assert response.status_code in status_code['failure'] if url_signed.orig == 'testserver': kevin = get_user(first_name='kevin') @@ -96,14 +96,15 @@ def test_signed_api_post(mock_phantomjs_result, client_service, url_signed, payl response = client_service.post(url_signed.url, data=payload, format='json') - assert response.status_code == status_code['success'] - if url_signed.orig == 'testserver': + assert response.status_code == status_code['success'] josh = get_user(username='77777') josh_creds = UserCredentials.objects.filter(user=josh)[0] assert josh_creds.to_login_info()['#login'] == 'josh' assert josh_creds.to_login_info(decrypt=True)['#password'] == 'josh password' + else: + assert response.status_code in status_code['failure'] # DELETE @@ -133,14 +134,14 @@ def test_api_delete(client, url): @pytest.mark.skipif(settings.HOBO is None, reason="hobo is required") def test_signed_api_delete(client_service, url_signed): if url_signed.orig == 'testserver': - status_code = {'success': 200, 'failure': 404} + status_code = {'success': 200, 'failure': (404,)} else: - status_code = {'success': 403, 'failure': 403} + status_code = {'success': 403, 'failure': (401, 403)} kevin = get_user(first_name='kevin') assert UserCredentials.objects.filter(user=kevin).exists() is False response = client_service.delete(url_signed.url, data={'name_id_content': '12345'}, format='json') - assert response.status_code == status_code['failure'] + assert response.status_code in status_code['failure'] josh = create_user(username='77777') create_credentials(josh, { @@ -150,9 +151,11 @@ def test_signed_api_delete(client_service, url_signed): assert UserCredentials.objects.filter(user=josh).exists() is True response = client_service.delete(url_signed.url, data={'name_id_content': '77777'}, format='json') - assert response.status_code == status_code['success'] if url_signed.orig == 'testserver': + assert response.status_code == status_code['success'] assert UserCredentials.objects.filter(user=josh).exists() is False + else: + assert response.status_code in status_code['failure'] def test_api_stats(client):