AssertionError:'token' not found in{'non_field_errors':[ErrorDetail(string='Unable to authenticate with provided credentials.',code='authorization')]}

Я сделал приложение django rest api и у меня есть эта ошибка в моем тесте: image

Я собираюсь оставить код здесь

Тест:

    def test_create_user_token(self):
        payload = {
            'email': 'test@gmail.com',
            'password': 'test123',
            'name': 'Test'
        }
        create_user(**payload)

        res = self.client.post(TOKEN_URL, payload)

        self.assertIn('token', res.data)
        self.assertEqual(res.status_code, status.HTTP_200_OK)

Класс сериализатора:

class AuthTokenSerializer(serializers.Serializer):
    email = serializers.CharField()
    password = serializers.CharField(
        style={'input_type': 'password'},
        trim_whitespace=False
    )
    def validate(self, attrs):
        email = attrs.get('email')
        password = attrs.get('password')

        user = authenticate(
            request=self.context.get('request'),
            username=email,
            password=password
        )

        if not user:
            msg = _('Unable to authenticate with provided email and password.')
            raise serializers.ValidationError(msg, code='authorization')

        attrs['user'] = user
        return attrs

Уже спасибо большое

Вернуться на верх