Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Improve test resilience on random ordering python dicts
  • Loading branch information
amol- committed Feb 14, 2015
1 parent f7f4947 commit 59365cc
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions tests/test_stack/rendering/test_pagination.py
Expand Up @@ -95,9 +95,17 @@ def test_pagination_with_link_args(self):

def test_multiple_paginators(self):
url = '/multiple_paginators/42'
goto_page2_params = _urlencode({'testdata2_page':2,
'testdata_page':2})
goto_page2_link = url + '?' + goto_page2_params

try:
from collections import OrderedDict
params = (('testdata_page', 2), ('testdata2_page', 2))
reverse_params = OrderedDict(reversed(params))
params = OrderedDict(params)
except ImportError:
reverse_params = params = {'testdata2_page': 2, 'testdata_page': 2}

goto_page2_link = url + '?' + _urlencode(params)
goto_page2_reverse_link = url + '?' + _urlencode(reverse_params)

page = self.app.get(url)
assert '/multiple_paginators/42?testdata2_page=2' in page, str(page)
Expand All @@ -106,7 +114,9 @@ def test_multiple_paginators(self):
url = '/multiple_paginators/42?testdata_page=2'
page = self.app.get(url)

assert goto_page2_link in page, str(page)
assert (
goto_page2_link in page or goto_page2_reverse_link in page
), str(page)
assert '/multiple_paginators/42?testdata_page=4' in page, str(page)

assert '<li>0</li>' not in page
Expand All @@ -117,7 +127,9 @@ def test_multiple_paginators(self):
url = '/multiple_paginators/42?testdata2_page=2'
page = self.app.get(url)

assert goto_page2_link in page, str(page)
assert (
goto_page2_link in page or goto_page2_reverse_link in page
), str(page)
assert '/multiple_paginators/42?testdata2_page=4' in page, str(page)

assert '<li>0</li>' in page
Expand Down Expand Up @@ -327,4 +339,4 @@ def test_relation(self):
a = self.Author.query.find({'name': 'author1'}).first()
p = Page(a.pages, items_per_page=1, page=1)
assert len(list(p)) == 1
assert list(p)[0].title in ('Hello', 'Another'), list(p)
assert list(p)[0].title in ('Hello', 'Another'), list(p)

0 comments on commit 59365cc

Please sign in to comment.