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_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 #5
0
    def test_get_object(self):
        """
        Test :py:meth:`.SingleObjectMixin.get_object` on single field.
        """
        queryset = Mock()
        queryset.get.return_value = 'object'

        mixin = SingleObjectMixin()
        mixin.get_queryset = Mock(return_value=queryset)
        mixin.get_fields = {
            'db_id': 'url_id',
        }
        mixin.kwargs = {
            'url_id': '1234abc',
        }

        result = mixin.get_object()
        queryset.get.assert_called_once_with(db_id='1234abc')
        self.assertEqual('object', result)
Example #6
0
    def test_get_object(self):
        """
        Test :py:meth:`.SingleObjectMixin.get_object` on single field.
        """
        queryset = Mock()
        queryset.get.return_value = 'object'

        mixin = SingleObjectMixin()
        mixin.get_queryset = Mock(return_value=queryset)
        mixin.get_fields = {
            'db_id': 'url_id',
        }
        mixin.kwargs = {
            'url_id': '1234abc',
        }

        result = mixin.get_object()
        queryset.get.assert_called_once_with(db_id='1234abc')
        self.assertEqual('object', result)