make MockObject, MockQuerySet and ExamplePagination visible outside of setup

This commit is contained in:
homm 2015-06-14 01:52:30 +03:00
parent a6983565f8
commit 33e7363203

View File

@ -186,6 +186,7 @@ class TestPageNumberPagination:
def setup(self):
class ExamplePagination(pagination.PageNumberPagination):
page_size = 5
self.pagination = ExamplePagination()
self.queryset = range(1, 101)
@ -475,8 +476,6 @@ class TestCursorPagination:
"""
Unit tests for `pagination.CursorPagination`.
"""
def setup(self):
class MockObject(object):
def __init__(self, idx):
self.created = idx
@ -487,20 +486,20 @@ class TestCursorPagination:
def filter(self, created__gt=None, created__lt=None):
if created__gt is not None:
return MockQuerySet([
return type(self)([
item for item in self.items
if item.created > int(created__gt)
])
assert created__lt is not None
return MockQuerySet([
return type(self)([
item for item in self.items
if item.created < int(created__lt)
])
def order_by(self, *ordering):
if ordering[0].startswith('-'):
return MockQuerySet(list(reversed(self.items)))
return type(self)(list(reversed(self.items)))
return self
def __getitem__(self, sliced):
@ -512,17 +511,18 @@ class TestCursorPagination:
max_page_size = 20
ordering = 'created'
self.pagination = ExamplePagination()
self.queryset = MockQuerySet([
MockObject(idx) for idx in [
def setup(self):
self.pagination = self.ExamplePagination()
self.queryset = self.MockQuerySet(
map(self.MockObject, [
1, 1, 1, 1, 1,
1, 2, 3, 4, 4,
4, 4, 5, 6, 7,
7, 7, 7, 7, 7,
7, 7, 7, 8, 9,
9, 9, 9, 9, 9
]
])
)
def get_pages(self, url):
"""