From 59737ed221d2d28c1d9c8c8d5a70b77e044837ae Mon Sep 17 00:00:00 2001 From: Armin Patel <72291325+arminpatel@users.noreply.github.com> Date: Wed, 6 Mar 2024 23:18:52 +0530 Subject: [PATCH 1/2] fix rest settings --- backend/accounts/tests.py | 6 +++--- backend/core/settings/base.py | 4 ---- backend/events/tests.py | 4 ++-- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/backend/accounts/tests.py b/backend/accounts/tests.py index 749d140..7c88156 100644 --- a/backend/accounts/tests.py +++ b/backend/accounts/tests.py @@ -91,7 +91,7 @@ def testRetrieveLoggedInAccountView_userNotLoggedIn_returnsForbidden(): response = client.get('/api/accounts/me/', format='json') # Assert - assert response.status_code == status.HTTP_403_FORBIDDEN + assert response.status_code == status.HTTP_401_UNAUTHORIZED @pytest.mark.django_db @@ -111,7 +111,7 @@ def testUpdateLogInAccountView_userLoggedIn_updateSuccesful(api_client, field): @pytest.mark.django_db -def testUpdateLogInAccountView_userNotLoggedIn_returnsForbidden(): +def testUpdateLogInAccountView_userNotLoggedIn_returnsUnauthorized(): # Arrange client = APIClient() @@ -119,4 +119,4 @@ def testUpdateLogInAccountView_userNotLoggedIn_returnsForbidden(): response = client.put('/api/accounts/me/', {}, format='json') # Assert - assert response.status_code == status.HTTP_403_FORBIDDEN + assert response.status_code == status.HTTP_401_UNAUTHORIZED diff --git a/backend/core/settings/base.py b/backend/core/settings/base.py index 9584d58..d4ba6c0 100644 --- a/backend/core/settings/base.py +++ b/backend/core/settings/base.py @@ -51,9 +51,6 @@ REST_FRAMEWORK = { # Use Django's standard `django.contrib.auth` permissions, # or allow read-only access for unauthenticated users. - 'DEFAULT_PERMISSION_CLASSES': [ - 'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly' - ], 'DEFAULT_AUTHENTICATION_CLASSES': ( 'rest_framework_simplejwt.authentication.JWTAuthentication', ) @@ -137,6 +134,5 @@ DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' -REST_FRAMEWORK = {} MEDIA_URL = '/media/' MEDIA_ROOT = os.path.join(BASE_DIR, 'media') diff --git a/backend/events/tests.py b/backend/events/tests.py index 086627a..1ded82d 100644 --- a/backend/events/tests.py +++ b/backend/events/tests.py @@ -101,7 +101,7 @@ def testEventCreation_withValidDetails_byUnauthenticatedUser_shouldNotCreateEven response = unauthenticated_client.post('/api/events/', event_data_copy, format='json') # Assert - assert response.status_code == status.HTTP_403_FORBIDDEN + assert response.status_code == status.HTTP_401_UNAUTHORIZED assert Event.objects.count() == 0 @@ -188,7 +188,7 @@ def testEventUpdate_withValidEventId_byOwner_shouldUpdateEvent( assert response.data['title'] == 'updated title' assert response.data['date'] == '2021-01-02' assert Event.objects.get().title == 'updated title' - assert Event.objects.get().date == '2021-01-02' + assert Event.objects.get().date.strftime('%Y-%m-%d') == '2021-01-02' @pytest.mark.django_db From f284d869d40a6d67a9d560fbb9842c6177527102 Mon Sep 17 00:00:00 2001 From: Armin Patel <72291325+arminpatel@users.noreply.github.com> Date: Wed, 6 Mar 2024 23:21:42 +0530 Subject: [PATCH 2/2] fix test name --- backend/accounts/tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/accounts/tests.py b/backend/accounts/tests.py index 7c88156..3d39360 100644 --- a/backend/accounts/tests.py +++ b/backend/accounts/tests.py @@ -83,7 +83,7 @@ def testRetrieveLoggedInAccountView_userLoggedIn_returnsAccountDetails(api_clien @pytest.mark.django_db -def testRetrieveLoggedInAccountView_userNotLoggedIn_returnsForbidden(): +def testRetrieveLoggedInAccountView_userNotLoggedIn_returnsUnauthorized(): # Arrange client = APIClient()