def test_post_with_invalid_data_returns_form(self, config): request = DummyRequest(post={}) config.testing_securitypolicy('jerry') controller = views.NotificationsController(request) controller.form = invalid_form() result = controller.post() assert 'form' in result
def test_post_with_invalid_data_returns_form(self, authn_policy): request = DummyRequest(post={}) authn_policy.authenticated_userid.return_value = 'jerry' controller = views.NotificationsController(request) controller.form = invalid_form() result = controller.post() assert 'form' in result
def test_post_with_invalid_data_returns_form(self, invalid_form, pyramid_config, pyramid_request): pyramid_request.POST = {} pyramid_config.testing_securitypolicy('jerry') controller = views.NotificationsController(pyramid_request) controller.form = invalid_form() result = controller.post() assert 'form' in result
def test_post_with_valid_data_redirects(self, authn_policy, subscriptions_model): request = DummyRequest(post={}) authn_policy.authenticated_userid.return_value = 'fiona' subscriptions_model.get_subscriptions_for_uri.return_value = [] controller = views.NotificationsController(request) controller.form = form_validating_to({}) result = controller.post() assert isinstance(result, httpexceptions.HTTPFound)
def test_post_with_valid_data_redirects(self, form_validating_to, pyramid_config, pyramid_request, subscriptions_model): pyramid_request.POST = {} pyramid_config.testing_securitypolicy('fiona') subscriptions_model.get_subscriptions_for_uri.return_value = [] controller = views.NotificationsController(pyramid_request) controller.form = form_validating_to({}) result = controller.post() assert isinstance(result, httpexceptions.HTTPFound)
def test_post_with_valid_data_updates_subscriptions( self, authn_policy, subscriptions_model): request = DummyRequest(post={}) authn_policy.authenticated_userid.return_value = 'fiona' subs = [ FakeSubscription('reply', True), FakeSubscription('foo', False), ] subscriptions_model.get_subscriptions_for_uri.return_value = subs controller = views.NotificationsController(request) controller.form = form_validating_to({'notifications': set(['foo'])}) controller.post() assert subs[0].active is False assert subs[1].active is True
def test_post_with_valid_data_updates_subscriptions( self, form_validating_to, pyramid_config, pyramid_request, subscriptions_model): pyramid_request.POST = {} pyramid_config.testing_securitypolicy('fiona') subs = [ FakeSubscription('reply', True), FakeSubscription('foo', False), ] subscriptions_model.get_subscriptions_for_uri.return_value = subs controller = views.NotificationsController(pyramid_request) controller.form = form_validating_to({'notifications': set(['foo'])}) controller.post() assert subs[0].active is False assert subs[1].active is True
def test_get_sets_subscriptions_data_in_form(self, config, subscriptions_model): request = DummyRequest() config.testing_securitypolicy('fiona') subscriptions_model.get_subscriptions_for_uri.return_value = [ FakeSubscription('reply', True), FakeSubscription('foo', False), ] controller = views.NotificationsController(request) controller.form = form_validating_to({}) controller.get() controller.form.set_appstruct.assert_called_once_with({ 'notifications': set(['reply']), })