Example #1
0
    def test_get_context_object_name_set(self):
        """
        Test :py:meth:`.MultipleObjectMixin.get_context_object_name`.

        This tests with ``context_object_name`` variable set.

        """
        mixin = MultipleObjectMixin()
        mixin.context_object_name = 'myobject_list'
        self.assertEqual('myobject_list', mixin.get_context_object_name())
Example #2
0
    def test_get_context_object_name_set(self):
        """
        Test :py:meth:`.MultipleObjectMixin.get_context_object_name`.

        This tests with ``context_object_name`` variable set.

        """
        mixin = MultipleObjectMixin()
        mixin.context_object_name = 'myobject_list'
        self.assertEqual('myobject_list', mixin.get_context_object_name())
Example #3
0
    def test_get_ontext_object_name_from_object(self):
        """
        Test :py:meth:`.MultipleObjectMixin.get_context_object_name`.

        This tests generating the object name from the document class.

        """
        class MyObject(object):
            pass

        mixin = MultipleObjectMixin()
        mixin.document_class = MyObject
        self.assertEqual('myobject_list', mixin.get_context_object_name())
Example #4
0
    def test_get_ontext_object_name_from_object(self):
        """
        Test :py:meth:`.MultipleObjectMixin.get_context_object_name`.

        This tests generating the object name from the document class.

        """
        class MyObject(object):
            pass

        mixin = MultipleObjectMixin()
        mixin.document_class = MyObject
        self.assertEqual('myobject_list', mixin.get_context_object_name())
Example #5
0
    def test_get_context_data_unpaginated(self):
        """
        Test :py:meth:`.MultipleObjectMixin.get_context_data` unpaginated.
        """
        mixin = MultipleObjectMixin()
        mixin.get_page_number = Mock(return_value=1)
        mixin.get_page_count = Mock(return_value=None)
        mixin.get_context_object_name = Mock(return_value='foo_bar')
        mixin.get_paginated_object_list = Mock()

        self.assertEqual({
            'foo': 'bar',
            'is_paginated': False,
            'current_page_number': 1,
            'total_page_count': None,
            'foo_bar': mixin.get_paginated_object_list.return_value,
        }, mixin.get_context_data(foo='bar'))
Example #6
0
    def test_get_context_data_paginated(self):
        """
        Test :py:meth:`.MultipleObjectMixin.get_context_data` paginated.
        """
        mixin = MultipleObjectMixin()
        mixin.items_per_page = 1
        mixin.get_page_number = Mock(return_value=5)
        mixin.get_page_count = Mock(return_value=10)
        mixin.get_context_object_name = Mock(return_value='foo_bar')
        mixin.get_paginated_object_list = Mock()

        self.assertEqual({
            'foo': 'bar',
            'is_paginated': True,
            'current_page_number': 5,
            'total_page_count': 10,
            'foo_bar': mixin.get_paginated_object_list.return_value,
        }, mixin.get_context_data(foo='bar'))
Example #7
0
    def test_get_context_data_unpaginated(self):
        """
        Test :py:meth:`.MultipleObjectMixin.get_context_data` unpaginated.
        """
        mixin = MultipleObjectMixin()
        mixin.get_page_number = Mock(return_value=1)
        mixin.get_page_count = Mock(return_value=None)
        mixin.get_context_object_name = Mock(return_value='foo_bar')
        mixin.get_paginated_object_list = Mock()

        self.assertEqual(
            {
                'foo': 'bar',
                'is_paginated': False,
                'current_page_number': 1,
                'total_page_count': None,
                'foo_bar': mixin.get_paginated_object_list.return_value,
            }, mixin.get_context_data(foo='bar'))
Example #8
0
    def test_get_context_data_paginated(self):
        """
        Test :py:meth:`.MultipleObjectMixin.get_context_data` paginated.
        """
        mixin = MultipleObjectMixin()
        mixin.items_per_page = 1
        mixin.get_page_number = Mock(return_value=5)
        mixin.get_page_count = Mock(return_value=10)
        mixin.get_context_object_name = Mock(return_value='foo_bar')
        mixin.get_paginated_object_list = Mock()

        self.assertEqual(
            {
                'foo': 'bar',
                'is_paginated': True,
                'current_page_number': 5,
                'total_page_count': 10,
                'foo_bar': mixin.get_paginated_object_list.return_value,
            }, mixin.get_context_data(foo='bar'))