Changeset View
Changeset View
Standalone View
Standalone View
swh/deposit/tests/api/test_service_document.py
Show All 21 Lines | def test_service_document_no_auth_with_http_auth_should_not_break(client): | ||||
"""Without auth, sd endpoint through browser should return 401 | """Without auth, sd endpoint through browser should return 401 | ||||
""" | """ | ||||
url = reverse(SD_IRI) | url = reverse(SD_IRI) | ||||
response = client.get(url, HTTP_ACCEPT="text/html,application/xml;q=9,*/*,q=8") | response = client.get(url, HTTP_ACCEPT="text/html,application/xml;q=9,*/*,q=8") | ||||
assert response.status_code == status.HTTP_401_UNAUTHORIZED | assert response.status_code == status.HTTP_401_UNAUTHORIZED | ||||
def test_service_document(authenticated_client, deposit_user): | def test_service_document(authenticated_client): | ||||
"""With authentication, service document list user's collection | """With authentication, service document list user's collection | ||||
""" | """ | ||||
url = reverse(SD_IRI) | url = reverse(SD_IRI) | ||||
response = authenticated_client.get(url) | response = authenticated_client.get(url) | ||||
check_response(response, deposit_user.username) | check_response(response, authenticated_client.deposit_client.username) | ||||
def test_service_document_with_http_accept_header(authenticated_client, deposit_user): | def test_service_document_with_http_accept_header(authenticated_client): | ||||
"""With authentication, with browser, sd list user's collection | """With authentication, with browser, sd list user's collection | ||||
""" | """ | ||||
url = reverse(SD_IRI) | url = reverse(SD_IRI) | ||||
response = authenticated_client.get( | response = authenticated_client.get( | ||||
url, HTTP_ACCEPT="text/html,application/xml;q=9,*/*,q=8" | url, HTTP_ACCEPT="text/html,application/xml;q=9,*/*,q=8" | ||||
) | ) | ||||
check_response(response, deposit_user.username) | check_response(response, authenticated_client.deposit_client.username) | ||||
def check_response(response, username): | def check_response(response, username): | ||||
assert response.status_code == status.HTTP_200_OK | assert response.status_code == status.HTTP_200_OK | ||||
assert ( | assert ( | ||||
response.content.decode("utf-8") | response.content.decode("utf-8") | ||||
== """<?xml version="1.0" ?> | == """<?xml version="1.0" ?> | ||||
<service xmlns:dcterms="http://purl.org/dc/terms/" | <service xmlns:dcterms="http://purl.org/dc/terms/" | ||||
Show All 27 Lines |