From 6fb3dc835105e199d0dde8fb5fa443ca214f4df8 Mon Sep 17 00:00:00 2001 From: Sean Hammond Date: Wed, 11 Jan 2012 13:04:23 +0100 Subject: [PATCH] Add tests for user activity stream API call 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. --- .../functional/api/model/test_activity.py | 20 ------------------- ckan/tests/models/test_activity.py | 19 ++++++++++++++++++ 2 files changed, 19 insertions(+), 20 deletions(-) delete mode 100644 ckan/tests/functional/api/model/test_activity.py diff --git a/ckan/tests/functional/api/model/test_activity.py b/ckan/tests/functional/api/model/test_activity.py deleted file mode 100644 index b588e7f4907..00000000000 --- a/ckan/tests/functional/api/model/test_activity.py +++ /dev/null @@ -1,20 +0,0 @@ -from ckan.tests.functional.api.base import BaseModelApiTestCase -from ckan.tests.functional.api.base import Api2TestCase -import ckan.model as model - -class TestActivity(Api2TestCase,BaseModelApiTestCase): - - def setup(self): - super(TestActivity, self).setup() - - def teardown(self): - super(TestActivity, self).teardown() - - def test_activity(self): - tester = model.Session.query(model.user.User).filter_by(name="tester").first() - result = self.app.get("/api/1/rest/activity/%s" % tester.id, status=self.STATUS_200_OK) - data = self.loads(result.body) - assert len(data) == 2 - for event in data: - assert event['user_id'] == tester.id - diff --git a/ckan/tests/models/test_activity.py b/ckan/tests/models/test_activity.py index 68dd47398c4..a6a75aa6109 100644 --- a/ckan/tests/models/test_activity.py +++ b/ckan/tests/models/test_activity.py @@ -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 @@ -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} @@ -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