From 69667006d8875eaccb5ccb658e8083b0b90429a3 Mon Sep 17 00:00:00 2001 From: winkidney Date: Fri, 18 Feb 2022 21:48:44 -0800 Subject: [PATCH] Fix: Fix test failure caused http error code(from 403 to 401) --- core/tests/api.py | 7 ++++--- pinry/settings/base.py | 1 + users/tests.py | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/core/tests/api.py b/core/tests/api.py index 6076e9b..71d11ce 100644 --- a/core/tests/api.py +++ b/core/tests/api.py @@ -32,7 +32,7 @@ class ImageTests(APITestCase): data=data, format='json', ) - self.assertEqual(response.status_code, 403, response.data) + self.assertEqual(response.status_code, 401, response.data) class BoardPrivacyTests(APITestCase): @@ -220,7 +220,7 @@ class PinTests(APITestCase): self.client.logout() uri = reverse("pin-detail", kwargs={"pk": pin.pk}) response = self.client.patch(uri, format='json', data={}) - self.assertEqual(response.status_code, 403) + self.assertEqual(response.status_code, 401, response.data) def test_patch_detail(self): image = create_image() @@ -240,7 +240,8 @@ class PinTests(APITestCase): pin = create_pin(self.user, image, []) uri = reverse("pin-detail", kwargs={"pk": pin.pk}) self.client.logout() - self.assertEqual(self.client.delete(uri).status_code, 403) + resp = self.client.delete(uri) + self.assertEqual(resp.status_code, 401, resp.data) def test_delete_detail(self): image = create_image() diff --git a/pinry/settings/base.py b/pinry/settings/base.py index db6e399..2387c6a 100644 --- a/pinry/settings/base.py +++ b/pinry/settings/base.py @@ -165,6 +165,7 @@ REST_FRAMEWORK = { 'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.LimitOffsetPagination', 'PAGE_SIZE': API_LIMIT_PER_PAGE, 'DEFAULT_AUTHENTICATION_CLASSES': [ + 'rest_framework.authentication.BasicAuthentication', 'rest_framework.authentication.TokenAuthentication', 'rest_framework.authentication.SessionAuthentication', ] diff --git a/users/tests.py b/users/tests.py index 7149cb3..b1f3ce4 100644 --- a/users/tests.py +++ b/users/tests.py @@ -61,7 +61,7 @@ class CreateUserTest(TestCase): reverse('users:user-list'), data=data, ) - self.assertEqual(response.status_code, 403) + self.assertEqual(response.status_code, 401) class LogoutViewTest(TestCase):