Skip to content

Commit

Permalink
Merge branch '1767-send-email-notifications-with-paster'
Browse files Browse the repository at this point in the history
  • Loading branch information
joetsoi committed Jul 24, 2014
2 parents cd051d9 + 6cf1f71 commit 8418ff5
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 19 deletions.
1 change: 1 addition & 0 deletions ckan/logic/action/update.py
Expand Up @@ -1188,6 +1188,7 @@ def dashboard_mark_activities_old(context, data_dict):
model.repo.commit()


@logic.auth_audit_exempt
def send_email_notifications(context, data_dict):
'''Send any pending activity stream notification emails to users.
Expand Down
66 changes: 47 additions & 19 deletions ckan/new_tests/logic/action/test_update.py
Expand Up @@ -3,6 +3,7 @@

import nose.tools
import mock
import pylons.config as config

import ckan.logic as logic
import ckan.new_tests.helpers as helpers
Expand All @@ -12,6 +13,9 @@
assert_raises = nose.tools.assert_raises


assert_raises = nose.tools.assert_raises


def datetime_from_string(s):
'''Return a standard datetime.datetime object initialised from a string in
the same format used for timestamps in dictized activities (the format
Expand Down Expand Up @@ -117,14 +121,14 @@ def test_user_update_with_id_that_does_not_exist(self):
user_dict = factories.User.attributes()
user_dict['id'] = "there's no user with this id"

nose.tools.assert_raises(logic.NotFound, helpers.call_action,
'user_update', **user_dict)
assert_raises(logic.NotFound, helpers.call_action,
'user_update', **user_dict)

def test_user_update_with_no_id(self):
user_dict = factories.User.attributes()
assert 'id' not in user_dict
nose.tools.assert_raises(logic.ValidationError, helpers.call_action,
'user_update', **user_dict)
assert_raises(logic.ValidationError, helpers.call_action,
'user_update', **user_dict)

## START-FOR-LOOP-EXAMPLE

Expand All @@ -135,9 +139,9 @@ def test_user_update_with_invalid_name(self):
'a' * 200, 'Hi!', 'i++%')
for name in invalid_names:
user['name'] = name
nose.tools.assert_raises(logic.ValidationError,
helpers.call_action, 'user_update',
**user)
assert_raises(logic.ValidationError,
helpers.call_action, 'user_update',
**user)

## END-FOR-LOOP-EXAMPLE

Expand All @@ -148,8 +152,8 @@ def test_user_update_to_name_that_already_exists(self):
# Try to update fred and change his user name to bob, which is already
# bob's user name
fred['name'] = bob['name']
nose.tools.assert_raises(logic.ValidationError, helpers.call_action,
'user_update', **fred)
assert_raises(logic.ValidationError, helpers.call_action,
'user_update', **fred)

def test_user_update_password(self):
'''Test that updating a user's password works successfully.'''
Expand All @@ -173,8 +177,8 @@ def test_user_update_with_short_password(self):
user = factories.User()

user['password'] = 'xxx' # This password is too short.
nose.tools.assert_raises(logic.ValidationError, helpers.call_action,
'user_update', **user)
assert_raises(logic.ValidationError, helpers.call_action,
'user_update', **user)

def test_user_update_with_empty_password(self):
'''If an empty password is passed to user_update, nothing should
Expand All @@ -199,17 +203,17 @@ def test_user_update_with_null_password(self):
user = factories.User()

user['password'] = None
nose.tools.assert_raises(logic.ValidationError, helpers.call_action,
'user_update', **user)
assert_raises(logic.ValidationError, helpers.call_action,
'user_update', **user)

def test_user_update_with_invalid_password(self):
user = factories.User()

for password in (False, -1, 23, 30.7):
user['password'] = password
nose.tools.assert_raises(logic.ValidationError,
helpers.call_action, 'user_update',
**user)
assert_raises(logic.ValidationError,
helpers.call_action, 'user_update',
**user)

def test_user_update_without_email_address(self):
'''You have to pass an email address when you call user_update.
Expand All @@ -227,9 +231,9 @@ def test_user_update_without_email_address(self):
user = factories.User()
del user['email']

nose.tools.assert_raises(logic.ValidationError,
helpers.call_action, 'user_update',
**user)
assert_raises(logic.ValidationError,
helpers.call_action, 'user_update',
**user)

# TODO: Valid and invalid values for the rest of the user model's fields.

Expand Down Expand Up @@ -421,6 +425,30 @@ def test_resource_reorder(self):
"http://a.html"]


class TestUpdateSendEmailNotifications(object):
@classmethod
def setup_class(cls):
cls._original_config = dict(config)
config['ckan.activity_streams_email_notifications'] = True

@classmethod
def teardown_class(cls):
config.clear()
config.update(cls._original_config)

@mock.patch('ckan.logic.action.update.request')
def test_calling_through_paster_doesnt_validates_auth(self, mock_request):
mock_request.environ.get.return_value = True
helpers.call_action('send_email_notifications')

@mock.patch('ckan.logic.action.update.request')
def test_not_calling_through_paster_validates_auth(self, mock_request):
mock_request.environ.get.return_value = False
assert_raises(logic.NotAuthorized, helpers.call_action,
'send_email_notifications',
context={'ignore_auth': False})


class TestResourceViewUpdate(object):

@classmethod
Expand Down

0 comments on commit 8418ff5

Please sign in to comment.