def test_list_vehicle_model(self):
        url = reverse('vehicles:VehicleModel-list')
        response = self.client.get(url)
        vehicle_model = self.objects_list
        serializer = VehicleModelSerializer(vehicle_model, many=True)

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.data, serializer.data)
    def test_get_vehicle_model(self):
        url = reverse('vehicles:VehicleModel-detail',
                      kwargs={'pk': self.object_get.pk})

        response = self.client.get(url)
        vehicle_model = self.object_get
        serializer = VehicleModelSerializer(vehicle_model)

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.data, serializer.data)
    def test_filter_engine_greater(self):
        url = reverse('vehicles:VehicleModel-list')
        query = urlencode({
            'engine__gte': 1.2
        })

        url = '{}?{}'.format(url, query)
        response = self.client.get(url)
        vehicle_model = self.objects_filter_engine_gte
        serializer = VehicleModelSerializer(vehicle_model, many=True)

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.data, serializer.data)
    def test_create_vehicle_model_motorcycle(self):

        data = {
            'name': 'CG',
            'model': ModelsTypesChoices.motorcycle.id,
            'engine': 150,
            'automaker': self.auto_maker.pk
        }

        url = reverse('vehicles:VehicleModel-list')

        response = self.client.post(url, data=data)

        vehicle_model = VehicleModel.objects.get(name=data.get('name'))
        serializer = VehicleModelSerializer(vehicle_model)

        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
        self.assertEqual(response.data, serializer.data)
    def test_update_partial_vehicle_model(self):
        url = reverse('vehicles:VehicleModel-detail',
                      kwargs={'pk': self.model_car_update.pk})

        data = {
            'name': 'Civic',
            'engine': 2.0,
        }

        new_data = json.dumps(data)

        response = self.client.patch(
            url, data=new_data, content_type='application/json')

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

        vehicle_model = VehicleModel.objects.get(name=data.get('name'))
        serializer = VehicleModelSerializer(vehicle_model)

        self.assertEqual(response.data, serializer.data)
    def test_update_vehicle_model(self):
        url = reverse('vehicles:VehicleModel-detail',
                      kwargs={'pk': self.model_car_update.pk})

        data = {
            'name': 'Fazer',
            'engine': 250,
            'model': ModelsTypesChoices.motorcycle.id,
            'automaker': self.auto_maker_update.id
        }

        new_data = json.dumps(data)

        response = self.client.patch(
            url, data=new_data, content_type='application/json')

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

        vehicle_model = VehicleModel.objects.get(name=data.get('name'))
        serializer = VehicleModelSerializer(vehicle_model)

        self.assertEqual(response.data, serializer.data)