def test_get_queryset(self): """ Test :py:meth:`.SingleObjectMixin.get_queryset`. """ mixin = SingleObjectMixin() mixin.document_class = Mock() mixin.document_class.objects = 'objects-qs' self.assertEqual('objects-qs', mixin.get_queryset())
def test_get_object_not_found(self): """ Test :py:meth:`.SingleObjectMixin.get_object` raising 404 exception. """ mixin = SingleObjectMixin() mixin.document_class = Mock() mixin.document_class.DoesNotExist = Exception queryset = Mock() queryset.get.side_effect = mixin.document_class.DoesNotExist('Boom!') mixin.get_queryset = Mock(return_value=queryset) mixin.kwargs = { 'id': '1234abc', } self.assertRaises(mixin.document_class.DoesNotExist, mixin.get_object)
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())