Skip to content

Commit

Permalink
[#714] Fix pagination tests
Browse files Browse the repository at this point in the history
Change create_arbitrary() to always create datasets in the same order,
instead of a different order each time. Update pagination tests to
expect datasets in the new default sort order.
  • Loading branch information
Sean Hammond committed Apr 16, 2013
1 parent 14690e4 commit 53c0bf2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions ckan/lib/create_test_data.py
Expand Up @@ -148,15 +148,15 @@ def create_arbitrary(cls, package_dicts, relationships=[],
new_group_names = set()
new_groups = {}

rev = model.repo.new_revision()
rev.author = cls.author
rev.message = u'Creating test packages.'

admins_list = defaultdict(list) # package_name: admin_names
if package_dicts:
if isinstance(package_dicts, dict):
package_dicts = [package_dicts]
for item in package_dicts:
rev = model.repo.new_revision()
rev.author = cls.author
rev.message = u'Creating test packages.'
pkg_dict = {}
for field in cls.pkg_core_fields:
if item.has_key(field):
Expand Down Expand Up @@ -245,7 +245,7 @@ def create_arbitrary(cls, package_dicts, relationships=[],
model.setup_default_user_roles(pkg, admins=[])
for admin in admins:
admins_list[item['name']].append(admin)
model.repo.commit_and_remove()
model.repo.commit_and_remove()

needs_commit = False

Expand Down
8 changes: 4 additions & 4 deletions ckan/tests/functional/test_pagination.py
Expand Up @@ -59,25 +59,25 @@ def test_package_search_p1(self):
res = self.app.get(url_for(controller='package', action='search', q='groups:group_00'))
assert 'href="/dataset?q=groups%3Agroup_00&page=2"' in res
pkg_numbers = scrape_search_results(res, 'dataset')
assert_equal(['00', '01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19'], pkg_numbers)
assert_equal(['50', '49', '48', '47', '46', '45', '44', '43', '42', '41', '40', '39', '38', '37', '36', '35', '34', '33', '32', '31'], pkg_numbers)

def test_package_search_p2(self):
res = self.app.get(url_for(controller='package', action='search', q='groups:group_00', page=2))
assert 'href="/dataset?q=groups%3Agroup_00&page=1"' in res
pkg_numbers = scrape_search_results(res, 'dataset')
assert_equal(['20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31', '32', '33', '34', '35', '36', '37', '38', '39'], pkg_numbers)
assert_equal(['30', '29', '28', '27', '26', '25', '24', '23', '22', '21', '20', '19', '18', '17', '16', '15', '14', '13', '12', '11'], pkg_numbers)

def test_group_datasets_read_p1(self):
res = self.app.get(url_for(controller='group', action='read', id='group_00'))
assert 'href="/group/group_00?page=2' in res, res
pkg_numbers = scrape_search_results(res, 'group_dataset')
assert_equal(['00', '01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19'], pkg_numbers)
assert_equal(['50', '49', '48', '47', '46', '45', '44', '43', '42', '41', '40', '39', '38', '37', '36', '35', '34', '33', '32', '31'], pkg_numbers)

def test_group_datasets_read_p2(self):
res = self.app.get(url_for(controller='group', action='read', id='group_00', page=2))
assert 'href="/group/group_00?page=1' in res, res
pkg_numbers = scrape_search_results(res, 'group_dataset')
assert_equal(['20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31', '32', '33', '34', '35', '36', '37', '38', '39'], pkg_numbers)
assert_equal(['30', '29', '28', '27', '26', '25', '24', '23', '22', '21', '20', '19', '18', '17', '16', '15', '14', '13', '12', '11'], pkg_numbers)

class TestPaginationGroup(TestController):
@classmethod
Expand Down

0 comments on commit 53c0bf2

Please sign in to comment.