From: Stephen Finucane Date: Mon, 15 May 2023 12:00:27 +0000 (+0100) Subject: tests: Always enable REST API X-Git-Tag: v3.2.0~85 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8a960622ab03d8d3298bf0c9d4c3ae5312fe31b2;p=thirdparty%2Fpatchwork.git tests: Always enable REST API This means django-rest-framework is now a hard requirement for unit tests. That seems reasonable. Signed-off-by: Stephen Finucane --- diff --git a/patchwork/tests/api/test_bundle.py b/patchwork/tests/api/test_bundle.py index c2a5fce3..a7173f1c 100644 --- a/patchwork/tests/api/test_bundle.py +++ b/patchwork/tests/api/test_bundle.py @@ -3,11 +3,10 @@ # # SPDX-License-Identifier: GPL-2.0-or-later -import unittest - -from django.conf import settings +from django.test import override_settings from django.urls import NoReverseMatch from django.urls import reverse +from rest_framework import status from patchwork.models import Bundle from patchwork.tests.api import utils @@ -17,11 +16,8 @@ from patchwork.tests.utils import create_patch from patchwork.tests.utils import create_project from patchwork.tests.utils import create_user -if settings.ENABLE_REST_API: - from rest_framework import status - -@unittest.skipUnless(settings.ENABLE_REST_API, 'requires ENABLE_REST_API') +@override_settings(ENABLE_REST_API=True) class TestBundleAPI(utils.APITestCase): fixtures = ['default_tags'] diff --git a/patchwork/tests/api/test_check.py b/patchwork/tests/api/test_check.py index 25c70aa4..cc57cd21 100644 --- a/patchwork/tests/api/test_check.py +++ b/patchwork/tests/api/test_check.py @@ -3,10 +3,10 @@ # # SPDX-License-Identifier: GPL-2.0-or-later -import unittest - -from django.conf import settings +from django.test import override_settings from django.urls import reverse +from rest_framework import status +from rest_framework.test import APITestCase as BaseAPITestCase from patchwork.models import Check from patchwork.tests.api import utils @@ -16,15 +16,8 @@ from patchwork.tests.utils import create_maintainer from patchwork.tests.utils import create_project from patchwork.tests.utils import create_user -if settings.ENABLE_REST_API: - from rest_framework import status - from rest_framework.test import APITestCase as BaseAPITestCase -else: - # stub out APITestCase - from django.test import TestCase as BaseAPITestCase - -@unittest.skipUnless(settings.ENABLE_REST_API, 'requires ENABLE_REST_API') +@override_settings(ENABLE_REST_API=True) class TestCheckAPI(utils.APITestCase): fixtures = ['default_tags'] @@ -201,7 +194,7 @@ class TestCheckAPI(utils.APITestCase): self.assertEqual(status.HTTP_405_METHOD_NOT_ALLOWED, resp.status_code) -@unittest.skipUnless(settings.ENABLE_REST_API, 'requires ENABLE_REST_API') +@override_settings(ENABLE_REST_API=True) class TestCheckAPIMultipart(BaseAPITestCase): """Test a minimal subset of functionality where the data is passed as multipart form data rather than as a JSON blob. diff --git a/patchwork/tests/api/test_comment.py b/patchwork/tests/api/test_comment.py index 994db70b..45432089 100644 --- a/patchwork/tests/api/test_comment.py +++ b/patchwork/tests/api/test_comment.py @@ -3,11 +3,10 @@ # # SPDX-License-Identifier: GPL-2.0-or-later -import unittest - -from django.conf import settings +from django.test import override_settings from django.urls import NoReverseMatch from django.urls import reverse +from rest_framework import status from patchwork.models import PatchComment from patchwork.models import CoverComment @@ -22,11 +21,8 @@ from patchwork.tests.utils import create_person from patchwork.tests.utils import create_user from patchwork.tests.utils import SAMPLE_CONTENT -if settings.ENABLE_REST_API: - from rest_framework import status - -@unittest.skipUnless(settings.ENABLE_REST_API, 'requires ENABLE_REST_API') +@override_settings(ENABLE_REST_API=True) class TestCoverComments(utils.APITestCase): @staticmethod def api_url(cover, version=None, item=None): @@ -259,7 +255,7 @@ class TestCoverComments(utils.APITestCase): self.assertEqual(status.HTTP_405_METHOD_NOT_ALLOWED, resp.status_code) -@unittest.skipUnless(settings.ENABLE_REST_API, 'requires ENABLE_REST_API') +@override_settings(ENABLE_REST_API=True) class TestPatchComments(utils.APITestCase): @staticmethod def api_url(patch, version=None, item=None): diff --git a/patchwork/tests/api/test_cover.py b/patchwork/tests/api/test_cover.py index 44ae2ebf..4f16eef5 100644 --- a/patchwork/tests/api/test_cover.py +++ b/patchwork/tests/api/test_cover.py @@ -4,11 +4,11 @@ # SPDX-License-Identifier: GPL-2.0-or-later import email.parser -import unittest -from django.conf import settings +from django.test import override_settings from django.urls import NoReverseMatch from django.urls import reverse +from rest_framework import status from patchwork.tests.api import utils from patchwork.tests.utils import create_cover @@ -17,11 +17,8 @@ from patchwork.tests.utils import create_maintainer from patchwork.tests.utils import create_series from patchwork.tests.utils import create_user -if settings.ENABLE_REST_API: - from rest_framework import status - -@unittest.skipUnless(settings.ENABLE_REST_API, 'requires ENABLE_REST_API') +@override_settings(ENABLED_REST_API=True) class TestCoverAPI(utils.APITestCase): fixtures = ['default_tags'] diff --git a/patchwork/tests/api/test_event.py b/patchwork/tests/api/test_event.py index 1a0d811d..0f93774b 100644 --- a/patchwork/tests/api/test_event.py +++ b/patchwork/tests/api/test_event.py @@ -3,10 +3,11 @@ # # SPDX-License-Identifier: GPL-2.0-or-later -import unittest - -from django.conf import settings +from django.test import override_settings from django.urls import reverse +from rest_framework import status +from rest_framework.test import APITestCase + from patchwork.models import Event from patchwork.tests.api import utils @@ -19,17 +20,10 @@ from patchwork.tests.utils import create_patch_comment from patchwork.tests.utils import create_series from patchwork.tests.utils import create_state -if settings.ENABLE_REST_API: - from rest_framework import status - from rest_framework.test import APITestCase -else: - # stub out APITestCase - from django.test import TestCase as APITestCase - # FIXME(stephenfin: This should inherit from 'utils.APITestCase', but we need # to fix our schema to work with recent versions of openapi_core -@unittest.skipUnless(settings.ENABLE_REST_API, 'requires ENABLE_REST_API') +@override_settings(ENABLE_REST_API=True) class TestEventAPI(APITestCase): @staticmethod def api_url(version=None): diff --git a/patchwork/tests/api/test_patch.py b/patchwork/tests/api/test_patch.py index 03b5be11..f4c9f676 100644 --- a/patchwork/tests/api/test_patch.py +++ b/patchwork/tests/api/test_patch.py @@ -5,11 +5,11 @@ import email.parser from email.utils import make_msgid -import unittest -from django.conf import settings +from django.test import override_settings from django.urls import NoReverseMatch from django.urls import reverse +from rest_framework import status from patchwork.models import Patch from patchwork.tests.api import utils @@ -22,9 +22,6 @@ from patchwork.tests.utils import create_series from patchwork.tests.utils import create_state from patchwork.tests.utils import create_user -if settings.ENABLE_REST_API: - from rest_framework import status - # a diff different from the default, required to test hash filtering SAMPLE_DIFF = """--- /dev/null\t2019-01-01 00:00:00.000000000 +0800 +++ a\t2019-01-01 00:00:00.000000000 +0800 @@ -33,7 +30,7 @@ SAMPLE_DIFF = """--- /dev/null\t2019-01-01 00:00:00.000000000 +0800 """ -@unittest.skipUnless(settings.ENABLE_REST_API, 'requires ENABLE_REST_API') +@override_settings(ENABLED_REST_API=True) class TestPatchAPI(utils.APITestCase): fixtures = ['default_tags'] diff --git a/patchwork/tests/api/test_person.py b/patchwork/tests/api/test_person.py index 64c80651..ab0a8dc2 100644 --- a/patchwork/tests/api/test_person.py +++ b/patchwork/tests/api/test_person.py @@ -3,22 +3,18 @@ # # SPDX-License-Identifier: GPL-2.0-or-later -import unittest - -from django.conf import settings +from django.test import override_settings from django.urls import NoReverseMatch from django.urls import reverse +from rest_framework import status from patchwork.tests.api import utils from patchwork.tests.utils import create_maintainer from patchwork.tests.utils import create_person from patchwork.tests.utils import create_user -if settings.ENABLE_REST_API: - from rest_framework import status - -@unittest.skipUnless(settings.ENABLE_REST_API, 'requires ENABLE_REST_API') +@override_settings(ENABLE_REST_API=True) class TestPersonAPI(utils.APITestCase): @staticmethod def api_url(item=None): diff --git a/patchwork/tests/api/test_project.py b/patchwork/tests/api/test_project.py index 79a71d81..599f7aec 100644 --- a/patchwork/tests/api/test_project.py +++ b/patchwork/tests/api/test_project.py @@ -3,10 +3,9 @@ # # SPDX-License-Identifier: GPL-2.0-or-later -import unittest - -from django.conf import settings +from django.test import override_settings from django.urls import reverse +from rest_framework import status from patchwork.models import Project from patchwork.tests.api import utils @@ -14,11 +13,8 @@ from patchwork.tests.utils import create_maintainer from patchwork.tests.utils import create_project from patchwork.tests.utils import create_user -if settings.ENABLE_REST_API: - from rest_framework import status - -@unittest.skipUnless(settings.ENABLE_REST_API, 'requires ENABLE_REST_API') +@override_settings(ENABLE_REST_API=True) class TestProjectAPI(utils.APITestCase): @staticmethod def api_url(item=None, version=None): diff --git a/patchwork/tests/api/test_relation.py b/patchwork/tests/api/test_relation.py index d7518cb3..edbe951f 100644 --- a/patchwork/tests/api/test_relation.py +++ b/patchwork/tests/api/test_relation.py @@ -3,10 +3,9 @@ # # SPDX-License-Identifier: GPL-2.0-or-later -import unittest - -from django.conf import settings +from django.test import override_settings from django.urls import reverse +from rest_framework import status from patchwork.models import Patch from patchwork.models import PatchRelation @@ -18,11 +17,8 @@ from patchwork.tests.utils import create_project from patchwork.tests.utils import create_relation from patchwork.tests.utils import create_user -if settings.ENABLE_REST_API: - from rest_framework import status - -@unittest.skipUnless(settings.ENABLE_REST_API, 'requires ENABLE_REST_API') +@override_settings(ENABLED_REST_API=True) class TestRelationSimpleAPI(utils.APITestCase): @staticmethod def api_url(item=None, version=None): diff --git a/patchwork/tests/api/test_series.py b/patchwork/tests/api/test_series.py index 10a074a1..890a9654 100644 --- a/patchwork/tests/api/test_series.py +++ b/patchwork/tests/api/test_series.py @@ -3,11 +3,10 @@ # # SPDX-License-Identifier: GPL-2.0-or-later -import unittest - -from django.conf import settings +from django.test import override_settings from django.urls import NoReverseMatch from django.urls import reverse +from rest_framework import status from patchwork.tests.api import utils from patchwork.tests.utils import create_cover @@ -18,11 +17,8 @@ from patchwork.tests.utils import create_project from patchwork.tests.utils import create_series from patchwork.tests.utils import create_user -if settings.ENABLE_REST_API: - from rest_framework import status - -@unittest.skipUnless(settings.ENABLE_REST_API, 'requires ENABLE_REST_API') +@override_settings(ENABLE_REST_API=True) class TestSeriesAPI(utils.APITestCase): fixtures = ['default_tags'] diff --git a/patchwork/tests/api/test_user.py b/patchwork/tests/api/test_user.py index 10865757..b4933b55 100644 --- a/patchwork/tests/api/test_user.py +++ b/patchwork/tests/api/test_user.py @@ -3,21 +3,17 @@ # # SPDX-License-Identifier: GPL-2.0-or-later -import unittest - -from django.conf import settings +from django.test import override_settings from django.urls import NoReverseMatch from django.urls import reverse +from rest_framework import status from patchwork.tests.api import utils from patchwork.tests.utils import create_maintainer from patchwork.tests.utils import create_user -if settings.ENABLE_REST_API: - from rest_framework import status - -@unittest.skipUnless(settings.ENABLE_REST_API, 'requires ENABLE_REST_API') +@override_settings(ENABLE_REST_API=True) class TestUserAPI(utils.APITestCase): @staticmethod def api_url(item=None, version=None): diff --git a/patchwork/tests/api/utils.py b/patchwork/tests/api/utils.py index bf88ca92..c39bbbaf 100644 --- a/patchwork/tests/api/utils.py +++ b/patchwork/tests/api/utils.py @@ -7,16 +7,12 @@ import functools import json import os -from django.conf import settings from django.test import testcases from patchwork.tests.api import validator -if settings.ENABLE_REST_API: - from rest_framework.test import APIClient as BaseAPIClient - from rest_framework.test import APIRequestFactory -else: - from django.test import Client as BaseAPIClient +from rest_framework.test import APIClient as BaseAPIClient +from rest_framework.test import APIRequestFactory # docs/api/samples diff --git a/patchwork/tests/views/test_bundles.py b/patchwork/tests/views/test_bundles.py index dd22bcfb..e5ac1efa 100644 --- a/patchwork/tests/views/test_bundles.py +++ b/patchwork/tests/views/test_bundles.py @@ -5,10 +5,9 @@ import base64 import datetime -import unittest -from django.conf import settings from django.test import TestCase +from django.test import override_settings from django.urls import reverse from django.utils.html import escape from django.utils.http import urlencode @@ -305,7 +304,7 @@ class BundlePrivateViewTest(BundleTestBase): self.assertEqual(response.status_code, 404) -@unittest.skipUnless(settings.ENABLE_REST_API, 'requires ENABLE_REST_API') +@override_settings(ENABLE_REST_API=True) class BundlePrivateViewMboxTest(BundlePrivateViewTest): """Ensure that non-owners can't view private bundle mboxes""" @@ -824,10 +823,7 @@ class BundleReorderTest(BundleTestBase): self.check_reordering([0, 2, 3, 1, 4], 1, 4) -@unittest.skipUnless( - settings.COMPAT_REDIR, - 'requires compat redirection (use the COMPAT_REDIR setting)', -) +@override_settings(COMPAT_REDIR=True) class BundleRedirTest(BundleTestBase): """Validate redirection of legacy URLs."""