def test_get_value_from_lazy_object(self):
     field = DEDField(attr='translation')
     instance = NonCallableMock(translation=_("foo"))
     self.assertIsInstance(
         field.get_value_from_instance(instance), string_types
     )
     self.assertEqual(field.get_value_from_instance(instance), "foo")
 def test_get_value_from_none(self):
     field = DEDField(attr='related.none')
     instance = NonCallableMock(attr1="foo", related=None)
     self.assertEqual(field.get_value_from_instance(instance), None)
 def test_get_value_from_instance_related_attr(self):
     field = DEDField(attr='related.attr1')
     instance = NonCallableMock(attr1="foo",
                                related=NonCallableMock(attr1="bar"))
     self.assertEqual(field.get_value_from_instance(instance), "bar")
 def test_get_value_from_instance_related_callable(self):
     field = DEDField(attr='related.callable')
     instance = NonCallableMock(related=NonCallableMock(
         callable=Mock(return_value="bar"), attr1="foo"))
     self.assertEqual(field.get_value_from_instance(instance), "bar")
 def test_get_value_from_instance_attr(self):
     field = DEDField(attr='attr1')
     instance = NonCallableMock(attr1="foo", attr2="bar")
     self.assertEqual(field.get_value_from_instance(instance), "foo")