Skip to content

Commit

Permalink
Add tests for user activity stream API call
Browse files Browse the repository at this point in the history
ckan/tests/models/test_activity.py already tests the logic function for
getting a user's activity stream in detail. I just made it also retrieve
the user's activity stream from the API each time it retrieves it from
the logic function, and check that the API result (after JSON parsing)
is the same as the logic function result.

Removed ckan/tests/functional/api/model/test_activity.py, no longer
needed.
  • Loading branch information
Sean Hammond committed Jan 11, 2012
1 parent 0ec666b commit 6fb3dc8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 20 deletions.
20 changes: 0 additions & 20 deletions ckan/tests/functional/api/model/test_activity.py

This file was deleted.

19 changes: 19 additions & 0 deletions ckan/tests/models/test_activity.py
Expand Up @@ -9,6 +9,9 @@
from ckan.logic.action.delete import package_delete
from ckan.lib.dictization.model_dictize import resource_list_dictize
from ckan.logic.action.get import user_activity_list, activity_detail_list
from pylons.test import pylonsapp
import paste.fixture
from ckan.lib.helpers import json

def datetime_from_string(s):
'''Return a standard datetime.datetime object initialised from a string in
Expand Down Expand Up @@ -66,6 +69,16 @@ def get_user_activity_stream(user_id):
data_dict = {'id':user_id}
return user_activity_list(context, data_dict)

def get_user_activity_stream_from_api(user_id):
'''
Return the public activity stream for the given user, but get it via the
API instead of from the logic function directly.
'''
app = paste.fixture.TestApp(pylonsapp)
response = app.get("/api/1/rest/activity/%s" % user_id)
return json.loads(response.body)

def get_activity_details(activity):
'''Return the list of activity details for the given activity.'''
context = {'model': model}
Expand All @@ -75,6 +88,12 @@ def get_activity_details(activity):
def record_details(user_id):
details = {}
details['user activity stream'] = get_user_activity_stream(user_id)

# This tests the user activity stream API call, the result should be the
# same as from the controller function.
assert get_user_activity_stream_from_api(user_id) == \
details['user activity stream']

details['time'] = datetime.datetime.now()
return details

Expand Down

0 comments on commit 6fb3dc8

Please sign in to comment.