Django DRF APITestCase post url приводит к 404 ошибке

Я изучаю тестовые примеры DRF, и в моем файле test.py мой URL в пост-вызове клиента возвращается в виде ошибки статуса 400:

Вот мой urls.py:

from django.contrib import admin
from django.urls import path, include

#from rest_auth.views import LoginView, LogoutView

urlpatterns = [
    path('admin/', admin.site.urls),
    path("api/", include("profiles.api.urls")),
    path("api-auth/", include("rest_framework.urls")),
    path("api/rest-auth/", include("rest_auth.urls")),
    path("api/rest-auth/registration/", include("rest_auth.registration.urls"))
]

from django.conf.urls.static import static
from django.conf import settings

if settings.DEBUG:
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

Вот мой файл test.py

import json
from django.contrib.auth.models import User
from django.urls import reverse
from rest_framework.authtoken.models import Token
from rest_framework.test import APITestCase
from rest_framework import status
from profiles.models import Profile
from profiles.api.serializers import ProfileSerializer


class RegistrationTestCase(APITestCase):

    def test_registration(self):
        data = {"username": "testuser1", "email": "test@localhost.app", "password1": "A41&14all", "password2": "A41@14all"}
        response = self.client.post("/api/rest-auth/registration/", data)

        self.assertEqual(response.status_code, status.HTTP_201_CREATED)

Кажется, что строка self.client.post.... не может найти конечную точку. Что я упускаю?

Спасибо!

Вам нужно вызвать APIClient, вот так:

    from rest_framework.test import APIClient

    client = APIClient()

    class RegistrationTestCase(APITestCase):
       def test_registration(self):
            data = {""}
            response = client.post("URL", data)
            self.assertEqual(response.status_code, status.HTTP_201_CREATED)
Вернуться на верх