Index: tests/modeltests/serializers/tests.py
|
|
|
219 | 219 | self.assertTrue(date_values) |
220 | 220 | assert date_values[0].startswith("0001") |
221 | 221 | |
| 222 | def test_pkless_serialized_strings(self): |
| 223 | """ |
| 224 | Tests that serialized strings without PKs |
| 225 | can be turned into models |
| 226 | """ |
| 227 | deserial_objs = list(serializers.deserialize(self.serializer_name, |
| 228 | self.pkless_str)) |
| 229 | for obj in deserial_objs: |
| 230 | self.assertFalse(obj.object.id) |
| 231 | obj.save() |
| 232 | self.assertEqual(Category.objects.all().count(), 4) |
| 233 | |
222 | 234 | |
223 | 235 | class XmlSerializerTestCase(SerializersTestBase, TestCase): |
224 | 236 | serializer_name = "xml" |
… |
… |
|
241 | 253 | '<field type="CharField" name="name">' |
242 | 254 | 'Reference</field></object>' |
243 | 255 | '</django-objects>') |
| 256 | pkless_str = ('<?xml version="1.0" encoding="utf-8"?>' |
| 257 | '<django-objects version="1.0">' |
| 258 | '<object model="serializers.category">' |
| 259 | '<field type="CharField" name="name">' |
| 260 | 'Reference</field></object>' |
| 261 | '</django-objects>') |
244 | 262 | |
245 | 263 | @staticmethod |
246 | 264 | def _validate_output(serial_str): |
… |
… |
|
275 | 293 | '"fields": {"name": "Reference"}},' |
276 | 294 | '{"pk": 1, "model": "serializers.author",' |
277 | 295 | '"fields": {"name": "Agnes"}}]') |
| 296 | pkless_str = ('[{"pk": null, "model": "serializers.category",' |
| 297 | '"fields": {"name": "Reference"}}]') |
278 | 298 | |
279 | 299 | @staticmethod |
280 | 300 | def _validate_output(serial_str): |
… |
… |
|
316 | 336 | ' name: Agnes', |
317 | 337 | ' pk: 1', |
318 | 338 | ' model: serializers.author',]) |
| 339 | pkless_str = "\n".join(['- fields:', |
| 340 | ' name: Reference', |
| 341 | ' pk: null', |
| 342 | ' model: serializers.category']) |
319 | 343 | |
320 | 344 | @staticmethod |
321 | 345 | def _validate_output(serial_str): |