def test_badge_add_adds_uri_to_model(models): request = Mock(params={'add': 'test_uri'}) admin.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") admin.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") admin.badge_add(request) assert not request.db.add.called request.session.flash.assert_called_once_with("test_error_message", "error")
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 admin.badge_add(request) == badge_index.return_value
def test_badge_add_returns_index(badge_index): request = Mock(params={'add': 'test_uri'}) assert admin.badge_add(request) == badge_index.return_value