Skip to content

Commit

Permalink
Fix a crash in dashboard_activity_list auth
Browse files Browse the repository at this point in the history
Fix the dashboard_activity_list auth function to not crash when no user
is logged in, and add some tests for this case.
  • Loading branch information
Sean Hammond committed Nov 20, 2012
1 parent 0326af3 commit 611b87a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 21 deletions.
2 changes: 1 addition & 1 deletion ckan/logic/auth/get.py
Expand Up @@ -192,7 +192,7 @@ def get_site_user(context, data_dict):


def dashboard_activity_list(context, data_dict):
if 'user' in context:
if context.get('user'):
return {'success': True}
else:
return {'success': False,
Expand Down
50 changes: 30 additions & 20 deletions ckan/tests/functional/api/test_dashboard.py
Expand Up @@ -46,27 +46,32 @@ def setup_class(cls):
def teardown_class(cls):
ckan.model.repo.rebuild_db()

def post(self, action, params=None, apikey=None, status=200):
'''Post to the CKAN API and return the result.'''
if params is None:
params = {}
params = json.dumps(params)
response = self.app.post('/api/action/{0}'.format(action),
params=params,
extra_environ={'Authorization': str(apikey)},
status=status)
if status in (200,):
assert response.json['success'] is True
return response.json['result']
else:
assert response.json['success'] is False
return response.json['error']

def dashboard_new_activities_count(self, user):
'''Return the given user's new activities count from the CKAN API.'''
params = json.dumps({})
response = self.app.post('/api/action/dashboard_new_activities_count',
params=params,
extra_environ={'Authorization': str(user['apikey'])})
assert response.json['success'] is True
new_activities_count = response.json['result']
return new_activities_count
return self.post('dashboard_new_activities_count',
apikey=user['apikey'])

def dashboard_activity_list(self, user):
'''Return the given user's dashboard activity list from the CKAN API.
'''
params = json.dumps({})
response = self.app.post('/api/action/dashboard_activity_list',
params=params,
extra_environ={'Authorization': str(user['apikey'])})
assert response.json['success'] is True
activity_list = response.json['result']
return activity_list
return self.post('dashboard_activity_list', apikey=user['apikey'])

def dashboard_new_activities(self, user):
'''Return the activities from the user's dashboard activity stream
Expand All @@ -75,12 +80,17 @@ def dashboard_new_activities(self, user):
return [activity for activity in activity_list if activity['is_new']]

def dashboard_mark_all_new_activities_as_old(self, user):
params = json.dumps({})
response = self.app.post(
'/api/action/dashboard_mark_all_new_activities_as_old',
params=params,
extra_environ={'Authorization': str(user['apikey'])})
assert response.json['success'] is True
self.post('dashboard_mark_all_new_activities_as_old',
apikey=user['apikey'])

def test_00_dashboard_activity_list_not_logged_in(self):
self.post('dashboard_activity_list', status=403)

def test_00_dashboard_new_activities_count_not_logged_in(self):
self.post('dashboard_new_activities_count', status=403)

def test_00_dashboard_mark_new_activities_not_logged_in(self):
self.post('dashboard_mark_all_new_activities_as_old', status=403)

def test_01_new_activities_count_for_new_user(self):
'''Test that a newly registered user's new activities count is 0.'''
Expand Down

0 comments on commit 611b87a

Please sign in to comment.