def test_offset(self):
        paginator = Paginator({}, self.data_set, limit=20, offset=0)

        paginator.offset = '10'
        self.assertEqual(paginator.get_offset(), 10)

        paginator.offset = 0
        self.assertEqual(paginator.get_offset(), 0)

        paginator.offset = 10
        self.assertEqual(paginator.get_offset(), 10)

        paginator.offset = -10
        self.assertRaises(BadRequest, paginator.get_offset)

        paginator.offset = 'hAI!'
        self.assertRaises(BadRequest, paginator.get_offset)
    def test_offset(self):
        paginator = Paginator({}, self.data_set, limit=20, offset=0)

        paginator.offset = '10'
        self.assertEqual(paginator.get_offset(), 10)

        paginator.offset = 0
        self.assertEqual(paginator.get_offset(), 0)

        paginator.offset = 10
        self.assertEqual(paginator.get_offset(), 10)

        paginator.offset= -10
        self.assertRaises(BadRequest, paginator.get_offset)

        paginator.offset = 'hAI!'
        self.assertRaises(BadRequest, paginator.get_offset)
    def test_offset(self):
        paginator = Paginator({}, self.data_set, limit=20, offset=0)

        paginator.offset = '10'
        self.assertEqual(paginator.get_offset(), 10)

        paginator.offset = 0
        self.assertEqual(paginator.get_offset(), 0)

        paginator.offset = 10
        self.assertEqual(paginator.get_offset(), 10)

        paginator.offset = -10
        raised = False
        try:
            paginator.get_offset()
        except BadRequest as e:
            raised = e
        self.assertTrue(raised)
        self.assertEqual(
            str(raised),
            "Invalid offset '-10' provided. Please provide a positive integer >= 0."
        )

        paginator.offset = 'hAI!'
        raised = False
        try:
            paginator.get_offset()
        except BadRequest as e:
            raised = e
        self.assertTrue(raised)
        self.assertEqual(
            str(raised),
            "Invalid offset 'hAI!' provided. Please provide an integer.")
Beispiel #4
0
    def test_offset(self):
        paginator = Paginator({}, self.data_set, limit=20, offset=0)

        paginator.offset = '10'
        self.assertEqual(paginator.get_offset(), 10)

        paginator.offset = 0
        self.assertEqual(paginator.get_offset(), 0)

        paginator.offset = 10
        self.assertEqual(paginator.get_offset(), 10)

        paginator.offset = -10
        raised = False
        try:
            paginator.get_offset()
        except BadRequest as e:
            raised = e
        self.assertTrue(raised)
        self.assertEqual(str(raised), "Invalid offset '-10' provided. Please provide a positive integer >= 0.")

        paginator.offset = 'hAI!'
        raised = False
        try:
            paginator.get_offset()
        except BadRequest as e:
            raised = e
        self.assertTrue(raised)
        self.assertEqual(str(raised), "Invalid offset 'hAI!' provided. Please provide an integer.")
Beispiel #5
0
    def test_offset(self):
        paginator = Paginator({}, self.data_set, limit=20, offset=0)

        paginator.offset = '10'
        self.assertEqual(paginator.get_offset(), 10)

        paginator.offset = 0
        self.assertEqual(paginator.get_offset(), 0)

        paginator.offset = 10
        self.assertEqual(paginator.get_offset(), 10)

        paginator.offset = -10
        raised = False
        try:
            paginator.get_offset()
        except BadRequest, e:
            raised = e
    def test_offset(self):
        paginator = Paginator({}, self.data_set, limit=20, offset=0)

        paginator.offset = '10'
        self.assertEqual(paginator.get_offset(), 10)

        paginator.offset = 0
        self.assertEqual(paginator.get_offset(), 0)

        paginator.offset = 10
        self.assertEqual(paginator.get_offset(), 10)

        paginator.offset= -10
        raised = False
        try:
            paginator.get_offset()
        except BadRequest, e:
            raised = e
    def test_offset(self):
        request = QueryDict('', mutable=True)
        paginator = Paginator(request, self.data_set, limit=20, offset=0)

        paginator.offset = '10'
        self.assertEqual(paginator.get_offset(), 10)

        paginator.offset = 0
        self.assertEqual(paginator.get_offset(), 0)

        paginator.offset = 10
        self.assertEqual(paginator.get_offset(), 10)

        paginator.offset = -10
        self.assertRaises(BadRequest, paginator.get_offset)

        paginator.offset = 'hAI!'
        self.assertRaises(BadRequest, paginator.get_offset)
Beispiel #8
0
        paginator.offset = -10
        raised = False
        try:
            paginator.get_offset()
        except BadRequest, e:
            raised = e
        self.assertTrue(raised)
        self.assertEqual(
            str(raised),
            "Invalid offset '-10' provided. Please provide a positive integer >= 0."
        )

        paginator.offset = 'hAI!'
        raised = False
        try:
            paginator.get_offset()
        except BadRequest, e:
            raised = e
        self.assertTrue(raised)
        self.assertEqual(
            str(raised),
            "Invalid offset 'hAI!' provided. Please provide an integer.")

    def test_regression_nonqueryset(self):
        paginator = Paginator({}, ['foo', 'bar', 'baz'], limit=2, offset=0)
        # This would fail due to ``count`` being present on ``list`` but called
        # differently.
        page = paginator.page()
        self.assertEqual(page['objects'], ['foo', 'bar'])

    def test_unicode_request(self):
        paginator.offset = 10
        self.assertEqual(paginator.get_offset(), 10)

        paginator.offset= -10
        raised = False
        try:
            paginator.get_offset()
        except BadRequest, e:
            raised = e
        self.assertTrue(raised)
        self.assertEqual(str(raised), "Invalid offset '-10' provided. Please provide a positive integer >= 0.")

        paginator.offset = 'hAI!'
        raised = False
        try:
            paginator.get_offset()
        except BadRequest, e:
            raised = e
        self.assertTrue(raised)
        self.assertEqual(str(raised), "Invalid offset 'hAI!' provided. Please provide an integer.")

    def test_regression_nonqueryset(self):
        paginator = Paginator({}, ['foo', 'bar', 'baz'], limit=2, offset=0)
        # This would fail due to ``count`` being present on ``list`` but called
        # differently.
        page = paginator.page()
        self.assertEqual(page['objects'], ['foo', 'bar'])

    def test_unicode_request(self):
        request = {
            'slug__startswith': u'☃',