Пример #1
0
    def test_get_value_from_instance_with_unknown_attr(self):
        class Dummy:
            attr1 = "foo"

        field = DEDField(attr="attr2")
        self.assertRaises(VariableLookupError, field.get_value_from_instance,
                          Dummy())
Пример #2
0
 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")
Пример #3
0
 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)
Пример #4
0
 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")
Пример #5
0
 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")
Пример #6
0
 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")
Пример #7
0
    def test_attr_to_path(self):
        field = DEDField(attr="field")
        self.assertEqual(field._path, ["field"])

        field = DEDField(attr="obj.field")
        self.assertEqual(field._path, ["obj", "field"])