<s> from mock import Mock <EOL> import pytest <EOL> from h . admin . views import badge as views <EOL> badge_index_fixtures = pytest . mark . usefixtures ( '<STR_LIT>' ) <EOL> @ badge_index_fixtures <EOL> def test_badge_index_returns_all_blocklisted_urls ( models ) : <EOL> assert views . badge_index ( Mock ( ) ) == { <EOL> "<STR_LIT>" : models . Blocklist . all . return_value } <EOL> badge_add_fixtures = pytest . mark . usefixtures ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> @ badge_add_fixtures <EOL> def test_badge_add_adds_uri_to_model ( models ) : <EOL> request = Mock ( params = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> views . badge_add ( request ) <EOL> models . Blocklist . assert_called_once_with ( uri = '<STR_LIT>' ) <EOL> request . db . add . assert_called_once_with ( models . Blocklist . return_value ) <EOL> @ badge_add_fixtures <EOL> def test_badge_add_returns_index ( badge_index ) : <EOL> request = Mock ( params = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> assert views . badge_add ( request ) == badge_index . return_value <EOL> @ badge_add_fixtures <EOL> def test_badge_add_flashes_error_if_uri_already_blocked ( models ) : <EOL> request = Mock ( params = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> models . Blocklist . side_effect = ValueError ( "<STR_LIT>" ) <EOL> views . badge_add ( request ) <EOL> assert not request . db . add . called <EOL> request . session . flash . assert_called_once_with ( <EOL> "<STR_LIT>" , "<STR_LIT:error>" ) <EOL> @ badge_add_fixtures <EOL> def test_badge_add_returns_index_if_uri_already_blocked ( models , badge_index ) : <EOL> request = Mock ( params = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> models . Blocklist . side_effect = ValueError ( "<STR_LIT>" ) <EOL> assert views . badge_add ( request ) == badge_index . return_value <EOL> badge_remove_fixtures = pytest . mark . usefixtures ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> @ badge_remove_fixtures <EOL> def test_badge_remove_deletes_model ( models ) : <EOL> request = Mock ( params = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> views . badge_remove ( request ) <EOL> models . Blocklist . get_by_uri . assert_called_once_with ( '<STR_LIT>' ) <EOL> request . db . delete . assert_called_once_with ( <EOL> models . Blocklist . get_by_uri . return_value ) <EOL> @ badge_remove_fixtures <EOL> def test_badge_remove_returns_index ( badge_index ) : <EOL> assert views . badge_remove ( Mock ( params = { '<STR_LIT>' : '<STR_LIT>' } ) ) == ( <EOL> badge_index . return_value ) <EOL> @ pytest . fixture <EOL> def badge_index ( patch ) : <EOL> return patch ( '<STR_LIT>' ) <EOL> @ pytest . fixture <EOL> def models ( patch ) : <EOL> return patch ( '<STR_LIT>' ) </s>
