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)
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_too_long_model_data(self): self.serializer_data["model"] = "t" * 151 serializer = CarPostSerializer(data=self.serializer_data) self.assertEqual(serializer.is_valid(), False) self.assertCountEqual(serializer.errors.keys(), ["model"])