Changeset View
Changeset View
Standalone View
Standalone View
swh/deposit/tests/api/test_service_document.py
# Copyright (C) 2017-2018 The Software Heritage developers | # Copyright (C) 2017-2018 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
from django.core.urlresolvers import reverse | from django.core.urlresolvers import reverse | ||||
from nose.tools import istest | |||||
from rest_framework import status | from rest_framework import status | ||||
from rest_framework.test import APITestCase | from rest_framework.test import APITestCase | ||||
from swh.deposit.tests import TEST_CONFIG | from swh.deposit.tests import TEST_CONFIG | ||||
from swh.deposit.config import SD_IRI | from swh.deposit.config import SD_IRI | ||||
from ..common import BasicTestCase, WithAuthTestCase | from ..common import BasicTestCase, WithAuthTestCase | ||||
class ServiceDocumentNoAuthCase(APITestCase, BasicTestCase): | class ServiceDocumentNoAuthCase(APITestCase, BasicTestCase): | ||||
"""Service document endpoints are protected with basic authentication. | """Service document endpoints are protected with basic authentication. | ||||
""" | """ | ||||
@istest | def test_service_document_no_authentication_fails(self): | ||||
def service_document_no_authentication_fails(self): | |||||
"""Without authentication, service document endpoint should return 401 | """Without authentication, service document endpoint should return 401 | ||||
""" | """ | ||||
url = reverse(SD_IRI) | url = reverse(SD_IRI) | ||||
response = self.client.get(url) | response = self.client.get(url) | ||||
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED) | self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED) | ||||
@istest | def test_service_document_with_http_accept_should_not_break(self): | ||||
def service_document_with_http_accept_should_not_break(self): | |||||
"""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) | ||||
# when | # when | ||||
response = self.client.get( | response = self.client.get( | ||||
url, | url, | ||||
Show All 33 Lines | <service xmlns:dcterms="http://purl.org/dc/terms/" | ||||
</workspace> | </workspace> | ||||
</service> | </service> | ||||
''' % (TEST_CONFIG['max_upload_size'], | ''' % (TEST_CONFIG['max_upload_size'], | ||||
self.username, | self.username, | ||||
self.username, | self.username, | ||||
self.username, | self.username, | ||||
self.username)) # noqa | self.username)) # noqa | ||||
@istest | def test_service_document(self): | ||||
def service_document(self): | |||||
"""With authentication, service document list user's collection | """With authentication, service document list user's collection | ||||
""" | """ | ||||
url = reverse(SD_IRI) | url = reverse(SD_IRI) | ||||
# when | # when | ||||
response = self.client.get(url) | response = self.client.get(url) | ||||
# then | # then | ||||
self.assertResponseOk(response) | self.assertResponseOk(response) | ||||
@istest | def test_service_document_with_http_accept_header(self): | ||||
def service_document_with_http_accept_header(self): | |||||
"""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) | ||||
# when | # when | ||||
response = self.client.get( | response = self.client.get( | ||||
url, | url, | ||||
HTTP_ACCEPT='text/html,application/xml;q=9,*/*,q=8') | HTTP_ACCEPT='text/html,application/xml;q=9,*/*,q=8') | ||||
self.assertResponseOk(response) | self.assertResponseOk(response) |