Example #1
0
 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())
Example #2
0
 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())
Example #3
0
    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)
Example #4
0
    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())
Example #5
0
    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)
Example #6
0
    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())