DEV Community

Gahyun Son
Gahyun Son

Posted on

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...?

Top comments (0)