Ejemplo n.º 1
0
 def test_pagination_headers_no_ranges_no_results(self):
     rest.write_pagination_headers({'results': {}}, 0, None,
                                   bottle.response, '/widgets', 'widget')
     self.assertEqual(200, bottle.response.status_code)
     self.assertEqual([('Content-Range', 'widget 0-0/0'),
                       ('Content-Type', 'text/html; charset=UTF-8')],
                      bottle.response.headerlist)
Ejemplo n.º 2
0
 def test_pagination_headers_unknown_count(self):
     rest.write_pagination_headers(
         {'results': {'1': {}}, 'collection-count': None},
         1, 1, bottle.response, '/widgets', 'widget')
     self.assertEqual(206, bottle.response.status_code)
     self.assertIn(
         ('Content-Range', 'widget 1-1/*'),
         bottle.response.headerlist
     )
Ejemplo n.º 3
0
 def test_pagination_headers_unknown_count(self):
     rest.write_pagination_headers(
         {'results': {'1': {}}, 'collection-count': None},
         1, 1, bottle.response, '/widgets', 'widget')
     self.assertEqual(206, bottle.response.status_code)
     self.assertIn(
         ('Content-Range', 'widget 1-1/*'),
         bottle.response.headerlist
     )
Ejemplo n.º 4
0
 def test_pagination_no_count(self):
     rest.write_pagination_headers(
         {'data': ['A']},
         0, 1, bottle.response, '/fibbles', 'fibble'
     )
     self.assertEqual(206, bottle.response.status_code)
     self.assertIn(
         ('Content-Range', 'fibble 0-0/*'),
         bottle.response.headerlist
     )
Ejemplo n.º 5
0
 def test_pagination_no_count(self):
     rest.write_pagination_headers(
         {'data': ['A']},
         0, 1, bottle.response, '/fibbles', 'fibble'
     )
     self.assertEqual(206, bottle.response.status_code)
     self.assertIn(
         ('Content-Range', 'fibble 0-0/*'),
         bottle.response.headerlist
     )
Ejemplo n.º 6
0
 def test_pagination_headers_no_ranges_no_results(self):
     rest.write_pagination_headers({'results': {}}, 0, None,
                                   bottle.response, '/widgets', 'widget')
     self.assertEqual(200, bottle.response.status_code)
     self.assertEqual(
         [
             ('Content-Range', 'widget 0-0/0'),
             ('Content-Type', 'text/html; charset=UTF-8')
         ],
         bottle.response.headerlist
     )
Ejemplo n.º 7
0
 def test_pagination_headers_last_page_overlap(self):
     rest.write_pagination_headers(
         {
             'collection-count': 4,
             'results': {'3': {}, '4': {}}
         },
         3, 3, bottle.response, '/widgets', 'widget'
     )
     self.assertEqual(206, bottle.response.status_code)
     self.assertIn(
         ('Link', '</widgets?offset=3>; rel="last"; title="Last page"'),
         bottle.response.headerlist)
Ejemplo n.º 8
0
 def test_pagination_headers_last_page_overlap(self):
     rest.write_pagination_headers(
         {
             'collection-count': 4,
             'results': {'3': {}, '4': {}}
         },
         3, 3, bottle.response, '/widgets', 'widget'
     )
     self.assertEqual(206, bottle.response.status_code)
     self.assertIn(
         ('Link', '</widgets?offset=3>; rel="last"; title="Last page"'),
         bottle.response.headerlist)
Ejemplo n.º 9
0
 def test_pagination_headers_no_ranges_but_with_results(self):
     rest.write_pagination_headers(
         {
             'collection-count': 4,
             'results': {
                 '1': {},
                 '2': {},
                 '3': {},
                 '4': {}
             }
         }, 0, None, bottle.response, '/fibbles', 'fibble')
     self.assertEqual(200, bottle.response.status_code)
     self.assertEqual([('Content-Range', 'fibble 0-3/4'),
                       ('Content-Type', 'text/html; charset=UTF-8')],
                      bottle.response.headerlist)
Ejemplo n.º 10
0
 def test_pagination_headers_no_ranges_but_with_results(self):
     rest.write_pagination_headers(
         {
             'collection-count': 4,
             'results': {'1': {}, '2': {}, '3': {}, '4': {}}
         },
         0, None, bottle.response, '/fibbles', 'fibble'
     )
     self.assertEqual(200, bottle.response.status_code)
     self.assertEqual(
         [
             ('Content-Range', 'fibble 0-3/4'),
             ('Content-Type', 'text/html; charset=UTF-8')
         ],
         bottle.response.headerlist
     )
Ejemplo n.º 11
0
 def test_pagination_headers_with_ranges_and_within_results(self):
     rest.write_pagination_headers(
         {
             'collection-count': 4,
             'results': {'2': {}, '3': {}}
         },
         1, 2, bottle.response, '/widgets', 'widget'
     )
     self.assertEqual(206, bottle.response.status_code)
     six.assertCountEqual(self, [
         ('Link', '</widgets?limit=2>; rel="first"; '
                  'title="First page"'),
         ('Link', '</widgets?offset=2>; rel="last"; '
                  'title="Last page"'),
         ('Content-Range', 'widget 1-2/4'),
         ('Content-Type', 'text/html; charset=UTF-8')
     ], bottle.response.headerlist)
Ejemplo n.º 12
0
 def test_pagination_headers_with_ranges_and_within_results(self):
     rest.write_pagination_headers(
         {
             'collection-count': 4,
             'results': {'2': {}, '3': {}}
         },
         1, 2, bottle.response, '/widgets', 'widget'
     )
     self.assertEqual(206, bottle.response.status_code)
     six.assertCountEqual(self, [
         ('Link', '</widgets?limit=2>; rel="first"; '
                  'title="First page"'),
         ('Link', '</widgets?offset=2>; rel="last"; '
                  'title="Last page"'),
         ('Content-Range', 'widget 1-2/4'),
         ('Content-Type', 'text/html; charset=UTF-8')
     ], bottle.response.headerlist)
Ejemplo n.º 13
0
 def test_pagination_headers_with_all_links(self):
     rest.write_pagination_headers(
         {
             'collection-count': 8,
             'results': {'3': {}, '4': {}}
         },
         3, 2, bottle.response, '/widgets', 'widget'
     )
     self.assertEqual(206, bottle.response.status_code)
     six.assertCountEqual(self, [
         ('Link', '</widgets?limit=2>; rel="first"; '
                  'title="First page"'),
         ('Link', '</widgets?offset=6>; rel="last"; '
                  'title="Last page"'),
         ('Link', '</widgets?limit=2&offset=5>; rel="next"; '
                  'title="Next page"'),
         ('Link', '</widgets?limit=2&offset=1>; rel="previous"; '
                  'title="Previous page"'),
         ('Content-Range', 'widget 3-4/8'),
         ('Content-Type', 'text/html; charset=UTF-8')
     ], bottle.response.headerlist)
Ejemplo n.º 14
0
 def test_pagination_headers_with_all_links(self):
     rest.write_pagination_headers(
         {
             'collection-count': 8,
             'results': {'3': {}, '4': {}}
         },
         3, 2, bottle.response, '/widgets', 'widget'
     )
     self.assertEqual(206, bottle.response.status_code)
     six.assertCountEqual(self, [
         ('Link', '</widgets?limit=2>; rel="first"; '
                  'title="First page"'),
         ('Link', '</widgets?offset=6>; rel="last"; '
                  'title="Last page"'),
         ('Link', '</widgets?limit=2&offset=5>; rel="next"; '
                  'title="Next page"'),
         ('Link', '</widgets?limit=2&offset=1>; rel="previous"; '
                  'title="Previous page"'),
         ('Content-Range', 'widget 3-4/8'),
         ('Content-Type', 'text/html; charset=UTF-8')
     ], bottle.response.headerlist)