diff --git a/requirements-server.txt b/requirements-server.txt --- a/requirements-server.txt +++ b/requirements-server.txt @@ -1,4 +1,4 @@ -django < 3 +django >= 2, < 4 djangorestframework psycopg2 < 2.9 setuptools diff --git a/swh/deposit/auth.py b/swh/deposit/auth.py --- a/swh/deposit/auth.py +++ b/swh/deposit/auth.py @@ -80,8 +80,8 @@ response = self.get_response(request) if response.status_code is status.HTTP_401_UNAUTHORIZED: - content_type = response._headers.get("content-type") - if content_type == ("Content-Type", "application/json"): + content_type = response.get("content-type") + if content_type == "application/json": return convert_response(request, response.content) return response diff --git a/swh/deposit/tests/api/test_collection_reuse_slug.py b/swh/deposit/tests/api/test_collection_reuse_slug.py --- a/swh/deposit/tests/api/test_collection_reuse_slug.py +++ b/swh/deposit/tests/api/test_collection_reuse_slug.py @@ -7,6 +7,7 @@ from django.urls import reverse_lazy as reverse from rest_framework import status +import xmltodict from swh.deposit.config import ( COL_IRI, @@ -35,10 +36,10 @@ ) assert response.status_code == status.HTTP_400_BAD_REQUEST - msg = "You can only act on deposit with status '%s'" % ( - DEPOSIT_STATUS_PARTIAL, + assert ( + xmltodict.parse(response.content)["sword:error"]["summary"] + == f"You can only act on deposit with status '{DEPOSIT_STATUS_PARTIAL}'" ) - assert msg in response.content.decode("utf-8") def test_add_deposit_when_partial_makes_new_deposit( diff --git a/swh/deposit/tests/api/test_delete.py b/swh/deposit/tests/api/test_delete.py --- a/swh/deposit/tests/api/test_delete.py +++ b/swh/deposit/tests/api/test_delete.py @@ -8,6 +8,7 @@ from django.urls import reverse_lazy as reverse from rest_framework import status +import xmltodict from swh.deposit.config import ( ARCHIVE_KEY, @@ -82,7 +83,8 @@ # then assert response.status_code == status.HTTP_400_BAD_REQUEST assert ( - b"You can only act on deposit with status 'partial'" in response.content + xmltodict.parse(response.content)["sword:error"]["summary"] + == "You can only act on deposit with status 'partial'" ) deposit = Deposit.objects.get(pk=deposit.id) @@ -124,7 +126,8 @@ # then assert response.status_code == status.HTTP_400_BAD_REQUEST assert ( - b"You can only act on deposit with status 'partial'" in response.content + xmltodict.parse(response.content)["sword:error"]["summary"] + == "You can only act on deposit with status 'partial'" ) deposit = Deposit.objects.get(pk=deposit.id) diff --git a/swh/deposit/tests/api/test_deposit_update_binary.py b/swh/deposit/tests/api/test_deposit_update_binary.py --- a/swh/deposit/tests/api/test_deposit_update_binary.py +++ b/swh/deposit/tests/api/test_deposit_update_binary.py @@ -10,6 +10,7 @@ from django.core.files.uploadedfile import InMemoryUploadedFile from django.urls import reverse_lazy as reverse from rest_framework import status +import xmltodict from swh.deposit.config import COL_IRI, DEPOSIT_STATUS_DEPOSITED, EM_IRI, SE_IRI from swh.deposit.models import Deposit, DepositRequest @@ -325,7 +326,10 @@ ) assert r.status_code == status.HTTP_400_BAD_REQUEST - assert b"You can only act on deposit with status 'partial'" in r.content + assert ( + xmltodict.parse(r.content)["sword:error"]["summary"] + == "You can only act on deposit with status 'partial'" + ) # adding file is no longer possible since the deposit's status # is ready @@ -338,7 +342,10 @@ ) assert r.status_code == status.HTTP_400_BAD_REQUEST - assert b"You can only act on deposit with status 'partial'" in r.content + assert ( + xmltodict.parse(r.content)["sword:error"]["summary"] + == "You can only act on deposit with status 'partial'" + ) # replacing metadata is no longer possible since the deposit's # status is ready @@ -351,7 +358,10 @@ ) assert r.status_code == status.HTTP_400_BAD_REQUEST - assert b"You can only act on deposit with status 'partial'" in r.content + assert ( + xmltodict.parse(r.content)["sword:error"]["summary"] + == "You can only act on deposit with status 'partial'" + ) # adding new metadata is no longer possible since the # deposit's status is ready @@ -364,7 +374,10 @@ ) assert r.status_code == status.HTTP_400_BAD_REQUEST - assert b"You can only act on deposit with status 'partial'" in r.content + assert ( + xmltodict.parse(r.content)["sword:error"]["summary"] + == "You can only act on deposit with status 'partial'" + ) archive_content = b"some content representing archive" archive = InMemoryUploadedFile( @@ -394,7 +407,10 @@ ) assert r.status_code == status.HTTP_400_BAD_REQUEST - assert b"You can only act on deposit with status 'partial'" in r.content + assert ( + xmltodict.parse(r.content)["sword:error"]["summary"] + == "You can only act on deposit with status 'partial'" + ) # adding new metadata is no longer possible since the # deposit's status is ready @@ -405,4 +421,7 @@ ) assert r.status_code == status.HTTP_400_BAD_REQUEST - assert b"You can only act on deposit with status 'partial'" in r.content + assert ( + xmltodict.parse(r.content)["sword:error"]["summary"] + == "You can only act on deposit with status 'partial'" + ) diff --git a/tox.ini b/tox.ini --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist=flake8,mypy,py3-django2 +envlist=flake8,mypy,py3-django2,py3-django3 [testenv] extras = @@ -12,6 +12,7 @@ dev: pdbpp pytest-cov django2: Django>=2,<3 + django3: Django>=3,<4 commands = pytest \ !dev: --cov {envsitepackagesdir}/swh/deposit --cov-branch \ @@ -78,4 +79,4 @@ # turn warnings into errors SPHINXOPTS = -W commands = - make -I ../.tox/sphinx-dev/src/swh-docs/swh/ -C docs \ No newline at end of file + make -I ../.tox/sphinx-dev/src/swh-docs/swh/ -C docs