def test_get_context_object_name_from_attr(self): """ Test :py:meth:`.SingleObjectMixin.get_context_object_name` from attr. """ mixin = SingleObjectMixin() mixin.context_object_name = 'foo' self.assertEqual('foo', mixin.get_context_object_name())
def test_get_context_data(self): """ Test :py:meth:`.SingleObjectMixin.get_context_data`. """ mixin = SingleObjectMixin() mixin.object = Mock() mixin.get_context_object_name = Mock(return_value='obj_name') self.assertEqual({ 'foo': 'bar', 'obj_name': mixin.object, }, mixin.get_context_data(foo='bar'))
def test_get_context_object_name_from_obj(self): """ Test :py:meth:`.SingleObjectMixin.get_context_object_name` from obj. """ class Foo(object): pass class Bar(object): pass for class_obj, expected in [ (Foo, 'foo'), (Bar, 'bar'), ]: mixin = SingleObjectMixin() mixin.document_class = class_obj self.assertEqual(expected, mixin.get_context_object_name())