def test_save_not_existed_car_request(self): self.serializer_data["model"] = "unknown" with self.assertRaises(NotFound): serializer = CarPostSerializer(data=self.serializer_data) serializer.is_valid() with patch("cars.serializers.requests.get") as mock_get: mock_get.return_value.ok = False serializer.save()
def test_save_proper_request(self): serializer = CarPostSerializer(data=self.serializer_data) serializer.is_valid() with patch("cars.serializers.requests.get") as mock_get: mock_get.return_value.ok = True mock_get.return_value.json.return_value = self.external_API_Response self.assertEqual(serializer.save(), self.car)