Skip to content

Commit

Permalink
[#1625] Add test for 'new user' activity type
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean Hammond committed Jan 11, 2012
1 parent 6fb3dc8 commit 0967960
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 4 deletions.
3 changes: 1 addition & 2 deletions ckan/logic/action/create.py
Expand Up @@ -218,7 +218,6 @@ def user_create(context, data_dict):
'''Creates a new user'''

model = context['model']
user = context['user']
schema = context.get('schema') or default_user_schema()

check_access('user_create', context, data_dict)
Expand Down Expand Up @@ -308,7 +307,7 @@ def activity_create(context, activity_dict):
model = context['model']

revision = model.repo.new_revision()
revision.author = activity_dict['user']
revision.author = activity_dict['user_id']
if 'message' in context:
revision.message = context['message']
else:
Expand Down
48 changes: 46 additions & 2 deletions ckan/tests/models/test_activity.py
Expand Up @@ -4,7 +4,7 @@

import ckan
import ckan.model as model
from ckan.logic.action.create import package_create
from ckan.logic.action.create import package_create, user_create
from ckan.logic.action.update import package_update, resource_update
from ckan.logic.action.delete import package_delete
from ckan.lib.dictization.model_dictize import resource_list_dictize
Expand Down Expand Up @@ -112,7 +112,6 @@ def setUp(self):
self.normal_user = model.User.get('annafan')

def tearDown(self):
ckan.tests.CreateTestData.delete()
model.repo.rebuild_db()

def _create_package(self, user):
Expand Down Expand Up @@ -584,3 +583,48 @@ def test_delete_resources(self):
"""
for package in model.Session.query(model.Package).all():
self._delete_resources(package)

def test_create_user(self):
"""
Test new user activity stream.
Test that correct activity stream item and detail item are created when
a new user is created.
"""
before = datetime.datetime.now()

# Create a new user.
user_dict = {'name': 'testuser',
'about': 'Just a test user', 'email': 'me@test.org',
'password': 'testpass'}
context = {'model': model, 'session': model.Session,
'user': self.sysadmin_user.name}
user_created = user_create(context, user_dict)

after = record_details(user_created['id'])

user_activities = after['user activity stream']
assert len(user_activities) == 1, ("There should be 1 activity in "
"the user's activity stream, but found %i" % len(user_activities))
activity = user_activities[0]

# Check that the new activity has the right attributes.
assert activity['object_id'] == user_created['id'], \
str(activity['object_id'])
assert activity['user_id'] == user_created['id'], \
str(activity['user_id'])
assert activity['activity_type'] == 'new user', \
str(activity['activity_type'])
if not activity.has_key('id'):
assert False, "activity object should have an id value"
# TODO: Test for the _correct_ revision_id value.
if not activity.has_key('revision_id'):
assert False, "activity object should have a revision_id value"
timestamp = datetime_from_string(activity['timestamp'])
assert timestamp >= before and timestamp <= after['time'], \
str(activity['timestamp'])

details = get_activity_details(activity)
assert len(details) == 0, ("There shouldn't be any activity details"
" for a 'new user' activity")

0 comments on commit 0967960

Please sign in to comment.