Beispiel #1
0
 def test_set_context_function_not_add_context_for_default(self):
     instance = fields.CreateOnlyDefault(self.FakeDefault)
     fake_parent = type('FakeParent', (), {'instance': object()})
     serializer_field = fields.IntegerField()
     serializer_field.bind('pk', fake_parent)
     instance.set_context(serializer_field)
     self.assertTrue(instance.is_update)
     self.assertFalse(hasattr(serializer_field, 'test_attr'))
Beispiel #2
0
 def test_repr(self):
     instance = fields.CreateOnlyDefault('value')
     self.assertEqual(instance.__repr__(), 'CreateOnlyDefault(value)')
Beispiel #3
0
    def test_call_raise_skip_field_exception(self):
        instance = fields.CreateOnlyDefault(self.FakeDefault)
        instance.is_update = True

        with self.assertRaises(SkipField):
            instance()
Beispiel #4
0
 def test_call_returns_default_from_callable(self):
     instance = fields.CreateOnlyDefault(self.FakeDefault)
     instance.is_update = False
     self.assertIsInstance(instance(), self.FakeDefault)
Beispiel #5
0
 def test_call_returns_default(self):
     instance = fields.CreateOnlyDefault('value')
     instance.is_update = False
     self.assertEqual(instance(), instance.default)
Beispiel #6
0
 def test_can_set_context_returns_false_for_not_instance_class(self):
     instance = fields.CreateOnlyDefault('default')
     instance.is_update = True
     self.assertFalse(instance._can_set_context())
Beispiel #7
0
 def test_can_set_context_returns_true_for_instance_class(self):
     instance = fields.CreateOnlyDefault(self.FakeDefault)
     instance.is_update = False
     self.assertTrue(instance._can_set_context())