Django TestCase, использующий self.client.post(), отправляет GET-запрос

Я создаю интеграционный тестовый класс. self.client.get работает нормально, но self.client.post отправляет GET и я получаю [httpResponse("Method Not Allowed", 405)].

from django.test import TestCase
import json

class Test_Integration(TestCase):

    def test_create_exist_product(self):
        response = self.client.post('http://127.0.0.1:8201/v1/products/create', {"name": "product7", "latest_version": "0"}, follow=True, secure=False)
        print(response)
        self.assertEqual(response, "Product name already exists")

  • Функция
def create_product(request):
    logger.info("Entering function create_product..")
    logger.info("REQUEST TYPE: "+str(request.method))
    if request.method == "POST":
        CODE HERE
    return HttpResponse("Method Not Allowed", 405)

  • Журнал ошибок:
Found 4 test(s).
Creating test database for alias 'default'...
System check identified no issues (0 silenced).
INFO 2022-11-16 13:45:12,066 views 13612 19052 Entering function create_product..
INFO 2022-11-16 13:45:12,068 views 13612 19052 REQUEST TYPE: GET
<HttpResponse status_code=200, "405">

======================================================================
FAIL: test_create_exist_product (project.Tests.test_integration.Test_Integration)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Users\backend\project\Tests\test_integration.py", line 23, in test_create_exist_product
    self.assertEqual(response, "Product name already exists")
AssertionError: <HttpResponse status_code=200, "405"> != 'Product name already exists'

----------------------------------------------------------------------
Ran 4 tests in 6.523s

FAILED (failures=1)
Destroying test database for alias 'default'...
Вернуться на верх