tests: adapt tests to new 401/403 differences:

This commit is contained in:
Frédéric Péters 2020-07-28 14:41:59 +02:00
parent f0f4fd15b6
commit cffdba2d25
1 changed files with 15 additions and 12 deletions

View File

@ -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):