Skip to content

Commit

Permalink
[#1767] Fix bug with send_email_notifications not working with paster
Browse files Browse the repository at this point in the history
The problem is that our validators notice that .send_email_notifications()
didn't call its auth functions and raise an Exception. But it shouldn't call
it's auth functions when being called with paster anyway, so it's correct.

This fixes that.
  • Loading branch information
vitorbaptista committed Jun 16, 2014
1 parent baca61b commit 1245ff2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions ckan/logic/action/update.py
Expand Up @@ -1063,6 +1063,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
28 changes: 28 additions & 0 deletions ckan/new_tests/logic/action/test_update.py
Expand Up @@ -3,12 +3,16 @@

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

import ckan.logic as logic
import ckan.new_tests.helpers as helpers
import ckan.new_tests.factories as factories


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 @@ -385,3 +389,27 @@ def test_resource_reorder(self):
assert reordered_resource_urls == ["http://b.html",
"http://c.html",
"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})

0 comments on commit 1245ff2

Please sign in to comment.