Python 当从test.py get测试api不存在时,匹配的查询不存在,而从postman测试相同的api时,它运行得很好

Python 当从test.py get测试api不存在时,匹配的查询不存在,而从postman测试相同的api时,它运行得很好,python,django,unit-testing,django-rest-framework,Python,Django,Unit Testing,Django Rest Framework,test.py views.py from django.test import TestCase, Client import json from django.urls import reverse from rest_framework import status from ..serializers import * from ..models import * client = Client() class Parking(TestCase): def setUp(se

test.py

views.py

from django.test import TestCase, Client
import json
from django.urls import reverse
from rest_framework import status
from ..serializers import *
from ..models import *

client = Client()


class Parking(TestCase):

    def setUp(self):
        self.park_data = {
            "car_id": 36,
            "slot_id": 327
        }
    def test_unpark(self):
        unpark_data = {
            "car_id": 33,
        }
        response = client.post(
            reverse('unpark'),
            data=json.dumps(unpark_data),
            content_type='application/json'
        )
        self.assertEqual(response.status_code, status.HTTP_200_OK)
控制台

@api_view(['POST'])
@csrf_exempt
def unpark_my_car(request):
    car_id = request.data.get('car_id')
    if car_id is not None:
        car_object = Car.objects.get(id=car_id)
        if car_object:
            slot_id = car_object.slot_id
            slot_object = Slot.objects.get(id=slot_id)
            slot_object.parked_car = None
            slot_object.status = "VACANT"
            slot_object.save()
            park_id = car_object.park_id
            park_object = ParkingArea.objects.get(id=park_id)
            valet_id = car_object.valet_assigned_id
            valet_object = Valet.objects.get(id=valet_id)
            valet_object.is_Currently_Parking = False
            valet_object.vehicle_assigned = None
            valet_object.save()
            park_object.filled_parking_slots = park_object.filled_parking_slots - 1
            if park_object.status == "FULL":
                park_object.status = "VACANT"
                notify_owner_car_is_unparked.delay(park_object.id)
                notify_airport_security_car_is_unparked.delay(park_object.id)
            park_object.save()
            car_object.is_parked = False
            car_object.slot_id = None
            car_object.park_id = None
            car_object.valet_assigned_id = None
            car_object.save()
            return Response(status=HTTP_200_OK, data={'msg': 'Car Un-parked'})
        else:
            return Response(status=HTTP_400_BAD_REQUEST, data={"msg": 'Car not Found'})

    else:
        return Response(status=HTTP_400_BAD_REQUEST, data={"msg": "car id provided is null"})

当从test.py进行测试时,它给出了上述错误,但当我使用postman访问相同的API时,它运行良好。 我是django的新手,编写代码本身也有帮助。我确实有数据匹配它确实存在的同一个查询,但它仍然给出错误。
我可以在数据库中查看数据,也可以通过jango rest API视图和管理面板查看数据。

您需要在
设置
方法中添加样本数据,并在测试方法中使用它们。添加如下所示的示例数据

Saurabh@DESKTOP-Q8U2ADF MINGW64 /f/Fellowship/ParkingLot/Parking_Lot (UC-9)
$ python manage.py test
Creating test database for alias 'default'...
System check identified no issues (0 silenced).
........E
======================================================================
ERROR: test_unpark (ParkingSystemApp.tests_parking.test_views.Parking)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "F:\Fellowship\ParkingLot\Parking_Lot\ParkingSystemApp\tests_parking\test_views.py", line 34, in test_unpark
    content_type='application/json'
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\django\test\client.py", line 748, in post
    response = super().post(path, data=data, content_type=content_type, secure=secure, **extra)
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\django\test\client.py", line 405, in post
    secure=secure, **extra)
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\django\test\client.py", line 470, in generic
    return self.request(**r)
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\django\test\client.py", line 716, in request
    self.check_exception(response)
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\django\test\client.py", line 577, in check_exception
    raise exc_value
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\django\core\handlers\exception.py", line 47, in inner
    response = get_response(request)
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\django\core\handlers\base.py", line 179, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\django\views\decorators\csrf.py", line 54, in wrapped_view
    return view_func(*args, **kwargs)
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\django\views\generic\base.py", line 70, in view
    return self.dispatch(request, *args, **kwargs)
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\rest_framework\views.py", line 509, in dispatch
    response = self.handle_exception(exc)
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\rest_framework\views.py", line 469, in handle_exception
    self.raise_uncaught_exception(exc)
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\rest_framework\views.py", line 480, in raise_uncaught_exception
    raise exc
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\rest_framework\views.py", line 506, in dispatch
    response = handler(request, *args, **kwargs)
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\rest_framework\decorators.py", line 50, in handler
    return func(*args, **kwargs)
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\django\views\decorators\csrf.py", line 54, in wrapped_view
    return view_func(*args, **kwargs)
  File "F:\Fellowship\ParkingLot\Parking_Lot\ParkingSystemApp\views.py", line 368, in unpark_my_car
    car_object = Car.objects.get(id=car_id)
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\django\db\models\manager.py", line 85, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\django\db\models\query.py", line 431, in get
    self.model._meta.object_name
ParkingSystemApp.models.Car.DoesNotExist: Car matching query does not exist.

----------------------------------------------------------------------
Ran 9 tests in 0.305s

FAILED (errors=1)
Destroying test database for alias 'default'...

Saurabh@DESKTOP-Q8U2ADF MINGW64 /f/Fellowship/ParkingLot/Parking_Lot (UC-9)
$ python manage.py test
Creating test database for alias 'default'...
System check identified no issues (0 silenced).
........E
======================================================================
ERROR: test_unpark (ParkingSystemApp.tests_parking.test_views.Parking)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "F:\Fellowship\ParkingLot\Parking_Lot\ParkingSystemApp\tests_parking\test_views.py", line 34, in test_unpark
    content_type='application/json'
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\django\test\client.py", line 748, in post
    response = super().post(path, data=data, content_type=content_type, secure=secure, **extra)
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\django\test\client.py", line 405, in post
    secure=secure, **extra)
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\django\test\client.py", line 470, in generic
    return self.request(**r)
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\django\test\client.py", line 716, in request
    self.check_exception(response)
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\django\test\client.py", line 577, in check_exception
    raise exc_value
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\django\core\handlers\exception.py", line 47, in inner
    response = get_response(request)
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\django\core\handlers\base.py", line 179, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\django\views\decorators\csrf.py", line 54, in wrapped_view
    return view_func(*args, **kwargs)
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\django\views\generic\base.py", line 70, in view
    return self.dispatch(request, *args, **kwargs)
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\rest_framework\views.py", line 509, in dispatch
    response = self.handle_exception(exc)
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\rest_framework\views.py", line 469, in handle_exception
    self.raise_uncaught_exception(exc)
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\rest_framework\views.py", line 480, in raise_uncaught_exception
    raise exc
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\rest_framework\views.py", line 506, in dispatch
    response = handler(request, *args, **kwargs)
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\rest_framework\decorators.py", line 50, in handler
    return func(*args, **kwargs)
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\django\views\decorators\csrf.py", line 54, in wrapped_view
    return view_func(*args, **kwargs)
  File "F:\Fellowship\ParkingLot\Parking_Lot\ParkingSystemApp\views.py", line 368, in unpark_my_car
    car_object = Car.objects.get(id=car_id)
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\django\db\models\manager.py", line 85, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\django\db\models\query.py", line 431, in get
    self.model._meta.object_name
ParkingSystemApp.models.Car.DoesNotExist: Car matching query does not exist.

----------------------------------------------------------------------
Ran 9 tests in 0.473s

FAILED (errors=1)
Destroying test database for alias 'default'...

Saurabh@DESKTOP-Q8U2ADF MINGW64 /f/Fellowship/ParkingLot/Parking_Lot (UC-9)
$ python manage.py test
Creating test database for alias 'default'...
System check identified no issues (0 silenced).
........E
======================================================================
ERROR: test_unpark (ParkingSystemApp.tests_parking.test_views.Parking)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "F:\Fellowship\ParkingLot\Parking_Lot\ParkingSystemApp\tests_parking\test_views.py", line 34, in test_unpark
    content_type='application/json'
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\django\test\client.py", line 748, in post
    response = super().post(path, data=data, content_type=content_type, secure=secure, **extra)
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\django\test\client.py", line 405, in post
    secure=secure, **extra)
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\django\test\client.py", line 470, in generic
    return self.request(**r)
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\django\test\client.py", line 716, in request
    self.check_exception(response)
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\django\test\client.py", line 577, in check_exception
    raise exc_value
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\django\core\handlers\exception.py", line 47, in inner
    response = get_response(request)
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\django\core\handlers\base.py", line 179, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\django\views\decorators\csrf.py", line 54, in wrapped_view
    return view_func(*args, **kwargs)
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\django\views\generic\base.py", line 70, in view
    return self.dispatch(request, *args, **kwargs)
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\rest_framework\views.py", line 509, in dispatch
    response = self.handle_exception(exc)
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\rest_framework\views.py", line 469, in handle_exception
    self.raise_uncaught_exception(exc)
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\rest_framework\views.py", line 480, in raise_uncaught_exception
    raise exc
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\rest_framework\views.py", line 506, in dispatch
    response = handler(request, *args, **kwargs)
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\rest_framework\decorators.py", line 50, in handler
    return func(*args, **kwargs)
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\django\views\decorators\csrf.py", line 54, in wrapped_view
    return view_func(*args, **kwargs)
  File "F:\Fellowship\ParkingLot\Parking_Lot\ParkingSystemApp\views.py", line 368, in unpark_my_car
    car_object = Car.objects.get(id=car_id)
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\django\db\models\manager.py", line 85, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\django\db\models\query.py", line 431, in get
    self.model._meta.object_name
ParkingSystemApp.models.Car.DoesNotExist: Car matching query does not exist.

----------------------------------------------------------------------
Ran 9 tests in 0.363s

FAILED (errors=1)
Destroying test database for alias 'default'...

Saurabh@DESKTOP-Q8U2ADF MINGW64 /f/Fellowship/ParkingLot/Parking_Lot (UC-9)
$ python manage.py test
Creating test database for alias 'default'...
System check identified no issues (0 silenced).
........E
======================================================================
ERROR: test_unpark (ParkingSystemApp.tests_parking.test_views.Parking)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "F:\Fellowship\ParkingLot\Parking_Lot\ParkingSystemApp\tests_parking\test_views.py", line 33, in test_unpark
    data=json.dumps(unpark_data),
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\django\test\client.py", line 748, in post
    response = super().post(path, data=data, content_type=content_type, secure=secure, **extra)
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\django\test\client.py", line 402, in post
    post_data = self._encode_data(data, content_type)
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\django\test\client.py", line 361, in _encode_data
    return encode_multipart(BOUNDARY, data)
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\django\test\client.py", line 242, in encode_multipart
    for (key, value) in data.items():
AttributeError: 'str' object has no attribute 'items'

----------------------------------------------------------------------
Ran 9 tests in 0.287s

FAILED (errors=1)
Destroying test database for alias 'default'...

Saurabh@DESKTOP-Q8U2ADF MINGW64 /f/Fellowship/ParkingLot/Parking_Lot (UC-9)
$ python manage.py test
Creating test database for alias 'default'...
System check identified no issues (0 silenced).
........E
======================================================================
ERROR: test_unpark (ParkingSystemApp.tests_parking.test_views.Parking)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "F:\Fellowship\ParkingLot\Parking_Lot\ParkingSystemApp\tests_parking\test_views.py", line 34, in test_unpark
    content_type='application/json'
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\django\test\client.py", line 748, in post
    response = super().post(path, data=data, content_type=content_type, secure=secure, **extra)
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\django\test\client.py", line 405, in post
    secure=secure, **extra)
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\django\test\client.py", line 470, in generic
    return self.request(**r)
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\django\test\client.py", line 716, in request
    self.check_exception(response)
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\django\test\client.py", line 577, in check_exception
    raise exc_value
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\django\core\handlers\exception.py", line 47, in inner
    response = get_response(request)
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\django\core\handlers\base.py", line 179, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\django\views\decorators\csrf.py", line 54, in wrapped_view
    return view_func(*args, **kwargs)
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\django\views\generic\base.py", line 70, in view
    return self.dispatch(request, *args, **kwargs)
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\rest_framework\views.py", line 509, in dispatch
    response = self.handle_exception(exc)
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\rest_framework\views.py", line 469, in handle_exception
    self.raise_uncaught_exception(exc)
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\rest_framework\views.py", line 480, in raise_uncaught_exception
    raise exc
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\rest_framework\views.py", line 506, in dispatch
    response = handler(request, *args, **kwargs)
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\rest_framework\decorators.py", line 50, in handler
    return func(*args, **kwargs)
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\django\views\decorators\csrf.py", line 54, in wrapped_view
    return view_func(*args, **kwargs)
  File "F:\Fellowship\ParkingLot\Parking_Lot\ParkingSystemApp\views.py", line 368, in unpark_my_car
    car_object = Car.objects.get(id=car_id)
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\django\db\models\manager.py", line 85, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\django\db\models\query.py", line 431, in get
    self.model._meta.object_name
ParkingSystemApp.models.Car.DoesNotExist: Car matching query does not exist.

----------------------------------------------------------------------
Ran 9 tests in 0.450s

FAILED (errors=1)
Destroying test database for alias 'default'...

Saurabh@DESKTOP-Q8U2ADF MINGW64 /f/Fellowship/ParkingLot/Parking_Lot (UC-9)
$ python manage.py test
Creating test database for alias 'default'...
System check identified no issues (0 silenced).
........E
======================================================================
ERROR: test_unpark (ParkingSystemApp.tests_parking.test_views.Parking)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "F:\Fellowship\ParkingLot\Parking_Lot\ParkingSystemApp\tests_parking\test_views.py", line 34, in test_unpark
    content_type='application/json'
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\django\test\client.py", line 748, in post
    response = super().post(path, data=data, content_type=content_type, secure=secure, **extra)
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\django\test\client.py", line 405, in post
    secure=secure, **extra)
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\django\test\client.py", line 470, in generic
    return self.request(**r)
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\django\test\client.py", line 716, in request
    self.check_exception(response)
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\django\test\client.py", line 577, in check_exception
    raise exc_value
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\django\core\handlers\exception.py", line 47, in inner
    response = get_response(request)
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\django\core\handlers\base.py", line 179, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\django\views\decorators\csrf.py", line 54, in wrapped_view
    return view_func(*args, **kwargs)
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\django\views\generic\base.py", line 70, in view
    return self.dispatch(request, *args, **kwargs)
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\rest_framework\views.py", line 509, in dispatch
    response = self.handle_exception(exc)
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\rest_framework\views.py", line 469, in handle_exception
    self.raise_uncaught_exception(exc)
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\rest_framework\views.py", line 480, in raise_uncaught_exception
    raise exc
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\rest_framework\views.py", line 506, in dispatch
    response = handler(request, *args, **kwargs)
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\rest_framework\decorators.py", line 50, in handler
    return func(*args, **kwargs)
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\django\views\decorators\csrf.py", line 54, in wrapped_view
    return view_func(*args, **kwargs)
  File "F:\Fellowship\ParkingLot\Parking_Lot\ParkingSystemApp\views.py", line 368, in unpark_my_car
    car_object = Car.objects.get(id=car_id)
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\django\db\models\manager.py", line 85, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "F:\Fellowship\ParkingLot\VirtualEnv\lib\site-packages\django\db\models\query.py", line 431, in get
    self.model._meta.object_name
ParkingSystemApp.models.Car.DoesNotExist: Car matching query does not exist.

----------------------------------------------------------------------
Ran 9 tests in 1.121s

FAILED (errors=1)
Destroying test database for alias 'default'...

请注意,我在
test\u unpark
unpark\u data
中引用了
car

您是否碰巧在postman中设置了一些标题,或者该特定ID的数据应该是无的?您没有从django为您的测试用例创建数据。快捷方式导入get\u object\u或\u 404 comment=get\u object\u或\u 404(Car,pk=comment\u id)或者我认为您犯的另一个错误是“request.data.get('Car\u id')”而不是request,它应该是Car,这样它就知道它必须查看哪个模型,如果您想要一个特定列,那么接下来在get方法中,您可以像这样更改代码Car.objects.values('Car\u id'))这个答案让我知道,我必须在测试时创建我要查找的所有数据,因为它无法访问现有的数据库。@ProgrammerSaurav,没错。它将创建一个新的测试数据库,并在其上运行测试,同时保持原始数据库的完整性。
class Parking(TestCase):

    def setUp(self):
        self.car = Car.objects.create(...)
        self.park_data = {
            "car_id": 36,
            "slot_id": 327
        }
    def test_unpark(self):
        unpark_data = {
            "car_id": self.car.id,
        }
        response = client.post(
            reverse('unpark'),
            data=json.dumps(unpark_data),
            content_type='application/json'
        )
        self.assertEqual(response.status_code, status.HTTP_200_OK)