mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-09-21 03:19:00 +03:00
make MockObject, MockQuerySet and ExamplePagination visible outside of setup
This commit is contained in:
parent
ab03729b58
commit
b3716ccb91
|
@ -186,6 +186,7 @@ class TestPageNumberPagination:
|
||||||
def setup(self):
|
def setup(self):
|
||||||
class ExamplePagination(pagination.PageNumberPagination):
|
class ExamplePagination(pagination.PageNumberPagination):
|
||||||
page_size = 5
|
page_size = 5
|
||||||
|
|
||||||
self.pagination = ExamplePagination()
|
self.pagination = ExamplePagination()
|
||||||
self.queryset = range(1, 101)
|
self.queryset = range(1, 101)
|
||||||
|
|
||||||
|
@ -475,52 +476,51 @@ class TestCursorPagination:
|
||||||
"""
|
"""
|
||||||
Unit tests for `pagination.CursorPagination`.
|
Unit tests for `pagination.CursorPagination`.
|
||||||
"""
|
"""
|
||||||
|
class MockObject(object):
|
||||||
|
def __init__(self, idx):
|
||||||
|
self.created = idx
|
||||||
|
|
||||||
def setup(self):
|
class MockQuerySet(object):
|
||||||
class MockObject(object):
|
def __init__(self, items):
|
||||||
def __init__(self, idx):
|
self.items = list(items)
|
||||||
self.created = idx
|
|
||||||
|
|
||||||
class MockQuerySet(object):
|
def filter(self, created__gt=None, created__lt=None):
|
||||||
def __init__(self, items):
|
if created__gt is not None:
|
||||||
self.items = items
|
return type(self)([
|
||||||
|
|
||||||
def filter(self, created__gt=None, created__lt=None):
|
|
||||||
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__lt)
|
if item.created > int(created__gt)
|
||||||
])
|
])
|
||||||
|
|
||||||
def order_by(self, *ordering):
|
assert created__lt is not None
|
||||||
if ordering[0].startswith('-'):
|
return type(self)([
|
||||||
return MockQuerySet(list(reversed(self.items)))
|
item for item in self.items
|
||||||
return self
|
if item.created < int(created__lt)
|
||||||
|
])
|
||||||
|
|
||||||
def __getitem__(self, sliced):
|
def order_by(self, *ordering):
|
||||||
return self.items[sliced]
|
if ordering[0].startswith('-'):
|
||||||
|
return type(self)(list(reversed(self.items)))
|
||||||
|
return self
|
||||||
|
|
||||||
class ExamplePagination(pagination.CursorPagination):
|
def __getitem__(self, sliced):
|
||||||
page_size = 5
|
return self.items[sliced]
|
||||||
ordering = 'created'
|
|
||||||
|
|
||||||
self.pagination = ExamplePagination()
|
class ExamplePagination(pagination.CursorPagination):
|
||||||
self.queryset = MockQuerySet([
|
page_size = 5
|
||||||
MockObject(idx) for idx in [
|
ordering = 'created'
|
||||||
|
|
||||||
|
def setup(self):
|
||||||
|
self.pagination = self.ExamplePagination()
|
||||||
|
self.queryset = self.MockQuerySet(
|
||||||
|
map(self.MockObject, [
|
||||||
1, 1, 1, 1, 1,
|
1, 1, 1, 1, 1,
|
||||||
1, 2, 3, 4, 4,
|
1, 2, 3, 4, 4,
|
||||||
4, 4, 5, 6, 7,
|
4, 4, 5, 6, 7,
|
||||||
7, 7, 7, 7, 7,
|
7, 7, 7, 7, 7,
|
||||||
7, 7, 7, 8, 9,
|
7, 7, 7, 8, 9,
|
||||||
9, 9, 9, 9, 9
|
9, 9, 9, 9, 9
|
||||||
]
|
])
|
||||||
])
|
)
|
||||||
|
|
||||||
def get_pages(self, url):
|
def get_pages(self, url):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue
Block a user