Skip to content

Commit

Permalink
Updated docstring and added test
Browse files Browse the repository at this point in the history
  • Loading branch information
rossjones committed Nov 24, 2014
1 parent c1f154e commit 88ebc69
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
4 changes: 2 additions & 2 deletions ckan/logic/action/get.py
Expand Up @@ -385,7 +385,7 @@ def _group_or_org_list(context, data_dict, is_org=False):

sort_info = _unpick_search(sort,
allowed_fields=['name', 'packages',
'package_count'],
'package_count', 'title'],
total=1)

all_fields = data_dict.get('all_fields', None)
Expand Down Expand Up @@ -444,7 +444,7 @@ def group_list(context, data_dict):
:type order_by: string
:param sort: sorting of the search results. Optional. Default:
"name asc" string of field name and sort-order. The allowed fields are
'name' and 'package_count'
'name', 'package_count' and 'title'
:type sort: string
:param groups: a list of names of the groups to return, if given only
groups whose names are in this list will be returned (optional)
Expand Down
22 changes: 20 additions & 2 deletions ckan/tests/functional/test_group.py
Expand Up @@ -43,12 +43,18 @@ def test_sorting(self):
model.Session.add(pkg1)
model.Session.add(pkg2)

CreateTestData.create_groups([{'name': "alpha", 'packages': []},
CreateTestData.create_groups([{'name': "alpha",
'title': "Alpha",
'packages': []},
{'name': "beta",
'title': "Beta",
'packages': ["pkg1", "pkg2"]},
{'name': "delta",
'title': 'Delta',
'packages': ["pkg1"]},
{'name': "gamma", 'packages': []}],
{'name': "gamma",
'title': "Gamma",
'packages': []}],
admin_user_name='testsysadmin')

context = {'model': model, 'session': model.Session,
Expand All @@ -59,6 +65,18 @@ def test_sorting(self):
assert results[0]['name'] == u'alpha', results[0]['name']
assert results[-1]['name'] == u'gamma', results[-1]['name']

# Test title forward
data_dict = {'all_fields': True, 'sort': 'title asc'}
results = get_action('group_list')(context, data_dict)
assert results[0]['name'] == u'alpha', results[0]['name']
assert results[-1]['name'] == u'gamma', results[-1]['name']

# Test title reverse
data_dict = {'all_fields': True, 'sort': 'title desc'}
results = get_action('group_list')(context, data_dict)
assert results[0]['name'] == u'gamma', results[0]['name']
assert results[-1]['name'] == u'alpha', results[-1]['name']

# Test name reverse
data_dict = {'all_fields': True, 'sort': 'name desc'}
results = get_action('group_list')(context, data_dict)
Expand Down

0 comments on commit 88ebc69

Please sign in to comment.