def test_badge_add_adds_uri_to_model(models): request = Mock(params={'add': 'test_uri'}) views.badge_add(request) models.Blocklist.assert_called_once_with(uri='test_uri') request.db.add.assert_called_once_with(models.Blocklist.return_value)
def test_add_flashes_error_if_uri_already_blocked(self, pyramid_request): pyramid_request.params = {'add': 'blocked1'} pyramid_request.session.flash = mock.Mock() views.badge_add(pyramid_request) assert pyramid_request.session.flash.call_count == 1
def test_add_flashes_error_if_uri_already_blocked(self, req): req.params = {'add': 'blocked1'} req.session.flash = mock.Mock() views.badge_add(req) assert req.session.flash.call_count == 1
def test_badge_add_adds_uri_to_model(models): request = Mock(params={'add': 'test_uri'}) views.badge_add(request) models.Blocklist.assert_called_once_with(uri='test_uri') request.db.add.assert_called_once_with(models.Blocklist.return_value)
def test_badge_add_flashes_error_if_uri_already_blocked(models): request = Mock(params={'add': 'test_uri'}) models.Blocklist.side_effect = ValueError("test_error_message") views.badge_add(request) assert not request.db.add.called request.session.flash.assert_called_once_with( "test_error_message", "error")
def test_badge_add_flashes_error_if_uri_already_blocked(models): request = Mock(params={'add': 'test_uri'}) models.Blocklist.side_effect = ValueError("test_error_message") views.badge_add(request) assert not request.db.add.called request.session.flash.assert_called_once_with("test_error_message", "error")
def test_add_redirects_to_index_if_uri_already_blocked(self, pyramid_request): pyramid_request.params = {'add': 'blocked1'} result = views.badge_add(pyramid_request) assert isinstance(result, httpexceptions.HTTPSeeOther) assert result.location == '/adm/badge'
def test_add_redirects_to_index_if_uri_already_blocked(self, req): req.params = {'add': 'blocked1'} result = views.badge_add(req) assert isinstance(result, httpexceptions.HTTPSeeOther) assert result.location == '/adm/badge'
def test_add_blocks_uri(self, pyramid_request): pyramid_request.params = {'add': 'test_uri'} views.badge_add(pyramid_request) assert models.Blocklist.is_blocked(pyramid_request.db, 'test_uri')
def test_badge_add_returns_index_if_uri_already_blocked(models, badge_index): request = Mock(params={'add': 'test_uri'}) models.Blocklist.side_effect = ValueError("test_error_message") assert views.badge_add(request) == badge_index.return_value
def test_badge_add_returns_index(badge_index): request = Mock(params={'add': 'test_uri'}) assert views.badge_add(request) == badge_index.return_value
def test_add_blocks_uri(self, req): req.params = {'add': 'test_uri'} views.badge_add(req) assert models.Blocklist.is_blocked(req.db, 'test_uri')
def test_badge_add_returns_index_if_uri_already_blocked(models, badge_index): request = Mock(params={'add': 'test_uri'}) models.Blocklist.side_effect = ValueError("test_error_message") assert views.badge_add(request) == badge_index.return_value
def test_badge_add_returns_index(badge_index): request = Mock(params={'add': 'test_uri'}) assert views.badge_add(request) == badge_index.return_value