Example #1
0
 def test_update(self):
     serializer = ChildSideloadSerializer(
         instance=self.child, data=self.payload)
     self.assertEqual(
         ChildModel.objects.get(pk=self.child.pk).old_parent, self.old_parent)
     serializer.is_valid()
     serializer.save()
     self.assertEqual(
         ChildModel.objects.get(pk=self.child.pk).old_parent, self.parent)
Example #2
0
 def test_errors_response_format(self):
     self.payload['child_model'].pop('parent')
     serializer = ChildSideloadSerializer(
         data=self.payload, instance=self.child)
     try:
         serializer.is_valid(True)
     except ValidationError as e:
         response = exception_handler(e)
         self.assertEqual(response.data,
             {'errors': {'parent': ['This field is required.']}})
         self.assertEqual(response.status_code, 422)
 def test_deserialize(self):
     serializer = ChildSideloadSerializer(
         instance=self.child, data=self.payload)
     self.assertTrue(serializer.is_valid())
     serializer.data
 def test_deserialize_field_validation_works(self):
     self.payload['child_model'].pop('parent')
     serializer = ChildSideloadSerializer(
         data=self.payload, instance=self.child)
     self.assertFalse(serializer.is_valid())
 def test_create(self):
     serializer = ChildSideloadSerializer(data=self.payload)
     self.assertEqual(ChildModel.objects.count(), 0)
     serializer.is_valid()
     serializer.save()
     self.assertEqual(ChildModel.objects.count(), 1)
 def test_deserialize(self):
     serializer = ChildSideloadSerializer(data=self.payload)
     self.assertTrue(serializer.is_valid())