Logo

dev-resources.site

for different kinds of informations.

AssertionError: 403

Published at
11/28/2024
Categories
drf
django
Author
hyun_hyun
Categories
2 categories in total
drf
open
django
open
Author
9 person written this
hyun_hyun
open
AssertionError: 403

The error messages.

apple@GH-MacBook-Pro hyunphoto-cbv % docker compose run --rm app sh -c "python manage.py test"
[+] Creating 1/0
 ✔ Container hyunphoto-cbv-db-1  Running                                                                                             0.0s 
Creating test database for alias 'default'...
System check identified no issues (0 silenced).
..............FFFWaiting for database...
Database unavailable, wating 1 second ...
Database unavailable, wating 1 second ...
Database unavailable, wating 1 second ...
Database unavailable, wating 1 second ...
Database unavailable, wating 1 second ...
Database available!
.Waiting for database...
Database available!
.
======================================================================
FAIL: test_signup_user_exist_error (user.tests.test_user_api.PublicUserApiTests)
Test signup a user is fail, email already exists.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/app/user/tests/test_user_api.py", line 47, in test_signup_user_exist_error
    self.assertEqual(res.status_code, status.HTTP_400_BAD_REQUEST)
AssertionError: 403 != 400

======================================================================
FAIL: test_signup_user_password_short_error (user.tests.test_user_api.PublicUserApiTests)
Test signup a user is fail, password is too short.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/app/user/tests/test_user_api.py", line 58, in test_signup_user_password_short_error
    self.assertEqual(res.status_code, status.HTTP_400_BAD_REQUEST)
AssertionError: 403 != 400

======================================================================
FAIL: test_signup_user_success (user.tests.test_user_api.PublicUserApiTests)
Test creating/signup a user is successful.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/app/user/tests/test_user_api.py", line 32, in test_signup_user_success
    self.assertEqual(res.status_code, status.HTTP_201_CREATED)
AssertionError: 403 != 201

----------------------------------------------------------------------
Ran 19 tests in 8.604s

FAILED (failures=3)
Destroying test database for alias 'default'...
Enter fullscreen mode Exit fullscreen mode

The causes can be

  1. views.py
  2. serializers.py
  3. something else

It was my views.py code.

class CreateUserView(generics.ListCreateAPIView):
    serializer_class = UserSerializer
Enter fullscreen mode Exit fullscreen mode

I couldn't believe this situation. Because it worked very well yesterday. I don't know why it doesn't work but I have to figure out.

I have suspicion to permission.

I modified views.py and

class CreateUserView(generics.CreateAPIView):
    serializer_class = UserSerializer
    permission_classes = [AllowAny]
Enter fullscreen mode Exit fullscreen mode

It fixed.

----------------------------------------------------------------------
Ran 19 tests in 8.788s

OK
Destroying test database for alias 'default'...
Enter fullscreen mode Exit fullscreen mode

I just... still have a question... Why it worked yesterday...?

drf Article's
30 articles in total
Favicon
Djoser+SimpleJWT
Favicon
AssertionError: 403
Favicon
extra_kwargs arguments
Favicon
To Django or to DjangoREST?
Favicon
Django API | queryset & object, filter() & get()
Favicon
I just tried to compare values between model and serializer
Favicon
Customize Schema with @extend_schema_view
Favicon
Seperate serializers
Favicon
Leveraging Headers for Dynamic Localization in Django
Favicon
Django REST Framework warning: `UnorderedObjectListWarning`
Favicon
DRF create @property decorator in view and use property in serializer
Favicon
why Serializers used for? easy to understand
Favicon
Async API Calls Unleashed: Exploring Django 4 and Django Rest Framework
Favicon
# Comprehensive Security for Class-Based Views in Django Rest Framework
Favicon
HATEOAS Principle - Generating Full Paths for Objects in Django Rest Framework.
Favicon
Instance version control in DRF with Django Reversion
Favicon
Django News #171 - DjangoCon US 2023 Preview
Favicon
How to create thumbnails programmatically in Django
Favicon
Automatically Add Logged In User Under 'created_by' and 'updated_by' to Model in Django Rest Framework
Favicon
how to fix raise ImproperlyConfigured("settings.DATABASES is improperly configured. "
Favicon
CSRF verification failed. Request aborted. in django rest framework
Favicon
CSRF verification failed. Request aborted. in django rest framework
Favicon
How to fix "Must supply api_key"
Favicon
Updating A Many-To-Many Relationship In Django
Favicon
Excluding Fields in Django Rest Framework Serializers
Favicon
JWT Authentication with Django REST Framework - What? Why? How?
Favicon
How to implement Auto Expiring Token in Django Rest Framework
Favicon
Building web applications with Django, Django REST Framework and Nuxt
Favicon
How to use Postman to authenticate to Django Rest Framework
Favicon
Setting Up Django Rest Framework

Featured ones: