コード例 #1
0
    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)
コード例 #2
0
    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()
コード例 #3
0
    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"])