Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
django-rest-framework
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
django-rest-framework
Commits
f1af603f
Commit
f1af603f
authored
Jan 22, 2015
by
Tom Christie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Tests for reverse pagination
parent
cae9528c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
73 additions
and
27 deletions
+73
-27
rest_framework/pagination.py
+2
-0
tests/test_pagination.py
+71
-27
No files found.
rest_framework/pagination.py
View file @
f1af603f
...
@@ -408,6 +408,8 @@ def encode_cursor(cursor):
...
@@ -408,6 +408,8 @@ def encode_cursor(cursor):
class
CursorPagination
(
BasePagination
):
class
CursorPagination
(
BasePagination
):
# TODO: handle queries with '' as a legitimate position
# TODO: handle queries with '' as a legitimate position
# Support case where ordering is already negative
# Support tuple orderings
cursor_query_param
=
'cursor'
cursor_query_param
=
'cursor'
page_size
=
5
page_size
=
5
...
...
tests/test_pagination.py
View file @
f1af603f
...
@@ -436,13 +436,22 @@ class TestCursorPagination:
...
@@ -436,13 +436,22 @@ class TestCursorPagination:
def
__init__
(
self
,
items
):
def
__init__
(
self
,
items
):
self
.
items
=
items
self
.
items
=
items
def
filter
(
self
,
created__gt
):
def
filter
(
self
,
created__gt
=
None
,
created__lt
=
None
):
return
[
if
created__gt
is
not
None
:
return
MockQuerySet
([
item
for
item
in
self
.
items
if
item
.
created
>
int
(
created__gt
)
])
assert
created__lt
is
not
None
return
MockQuerySet
([
item
for
item
in
self
.
items
item
for
item
in
self
.
items
if
item
.
created
>
int
(
created__g
t
)
if
item
.
created
<
int
(
created__l
t
)
]
]
)
def
order_by
(
self
,
ordering
):
def
order_by
(
self
,
ordering
):
if
ordering
.
startswith
(
'-'
):
return
MockQuerySet
(
reversed
(
self
.
items
))
return
self
return
self
def
__getitem__
(
self
,
sliced
):
def
__getitem__
(
self
,
sliced
):
...
@@ -485,6 +494,25 @@ class TestCursorPagination:
...
@@ -485,6 +494,25 @@ class TestCursorPagination:
next_url
=
self
.
pagination
.
get_next_link
()
next_url
=
self
.
pagination
.
get_next_link
()
assert
next_url
is
None
assert
next_url
is
None
# Now page back again
previous_url
=
self
.
pagination
.
get_previous_link
()
assert
previous_url
request
=
Request
(
factory
.
get
(
previous_url
))
queryset
=
self
.
paginate_queryset
(
request
)
assert
[
item
.
created
for
item
in
queryset
]
==
[
6
,
7
,
8
,
9
,
10
]
previous_url
=
self
.
pagination
.
get_previous_link
()
assert
previous_url
request
=
Request
(
factory
.
get
(
previous_url
))
queryset
=
self
.
paginate_queryset
(
request
)
assert
[
item
.
created
for
item
in
queryset
]
==
[
1
,
2
,
3
,
4
,
5
]
previous_url
=
self
.
pagination
.
get_previous_link
()
assert
previous_url
is
None
class
TestCrazyCursorPagination
:
class
TestCrazyCursorPagination
:
"""
"""
...
@@ -500,13 +528,22 @@ class TestCrazyCursorPagination:
...
@@ -500,13 +528,22 @@ class TestCrazyCursorPagination:
def
__init__
(
self
,
items
):
def
__init__
(
self
,
items
):
self
.
items
=
items
self
.
items
=
items
def
filter
(
self
,
created__gt
):
def
filter
(
self
,
created__gt
=
None
,
created__lt
=
None
):
return
[
if
created__gt
is
not
None
:
return
MockQuerySet
([
item
for
item
in
self
.
items
if
item
.
created
>
int
(
created__gt
)
])
assert
created__lt
is
not
None
return
MockQuerySet
([
item
for
item
in
self
.
items
item
for
item
in
self
.
items
if
item
.
created
>
int
(
created__g
t
)
if
item
.
created
<
int
(
created__l
t
)
]
]
)
def
order_by
(
self
,
ordering
):
def
order_by
(
self
,
ordering
):
if
ordering
.
startswith
(
'-'
):
return
MockQuerySet
(
reversed
(
self
.
items
))
return
self
return
self
def
__getitem__
(
self
,
sliced
):
def
__getitem__
(
self
,
sliced
):
...
@@ -553,25 +590,32 @@ class TestCrazyCursorPagination:
...
@@ -553,25 +590,32 @@ class TestCrazyCursorPagination:
next_url
=
self
.
pagination
.
get_next_link
()
next_url
=
self
.
pagination
.
get_next_link
()
assert
next_url
is
None
assert
next_url
is
None
# assert content == {
# 'results': [1, 2, 3, 4, 5],
# Now page back again
# 'previous': None,
# 'next': 'http://testserver/?limit=5&offset=5',
previous_url
=
self
.
pagination
.
get_previous_link
()
# 'count': 100
assert
previous_url
# }
# assert context == {
request
=
Request
(
factory
.
get
(
previous_url
))
# 'previous_url': None,
queryset
=
self
.
paginate_queryset
(
request
)
# 'next_url': 'http://testserver/?limit=5&offset=5',
assert
[
item
.
created
for
item
in
queryset
]
==
[
1
,
1
,
2
,
3
,
4
]
# 'page_links': [
# PageLink('http://testserver/?limit=5', 1, True, False),
previous_url
=
self
.
pagination
.
get_previous_link
()
# PageLink('http://testserver/?limit=5&offset=5', 2, False, False),
assert
previous_url
# PageLink('http://testserver/?limit=5&offset=10', 3, False, False),
# PAGE_BREAK,
request
=
Request
(
factory
.
get
(
previous_url
))
# PageLink('http://testserver/?limit=5&offset=95', 20, False, False),
queryset
=
self
.
paginate_queryset
(
request
)
# ]
assert
[
item
.
created
for
item
in
queryset
]
==
[
1
,
1
,
1
,
1
,
1
]
# }
# assert self.pagination.display_page_controls
previous_url
=
self
.
pagination
.
get_previous_link
()
# assert isinstance(self.pagination.to_html(), type(''))
assert
previous_url
request
=
Request
(
factory
.
get
(
previous_url
))
queryset
=
self
.
paginate_queryset
(
request
)
assert
[
item
.
created
for
item
in
queryset
]
==
[
1
,
1
,
1
,
1
,
1
]
previous_url
=
self
.
pagination
.
get_previous_link
()
assert
previous_url
is
None
def
test_get_displayed_page_numbers
():
def
test_get_displayed_page_numbers
():
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment