<s> from itertools import cycle <EOL> from django . contrib . admin . models import CHANGE <EOL> from django . contrib . auth . models import User <EOL> from django . contrib . contenttypes . models import ContentType <EOL> from django . core . urlresolvers import reverse <EOL> from django . test import TestCase , Client <EOL> from django_fsm import TransitionNotAllowed <EOL> from mock import MagicMock , patch <EOL> from silver . tests . factories import ProformaFactory <EOL> class ProformaAdminTestCase ( TestCase ) : <EOL> def setUp ( self ) : <EOL> User . objects . create_superuser ( '<STR_LIT:user>' , '<STR_LIT>' , '<STR_LIT:password>' ) <EOL> self . admin = Client ( ) <EOL> self . admin . login ( username = '<STR_LIT:user>' , password = '<STR_LIT:password>' ) <EOL> def test_actions_log_entries ( self ) : <EOL> proforma = ProformaFactory . create ( ) <EOL> url = reverse ( '<STR_LIT>' ) <EOL> mock_log_entry = MagicMock ( ) <EOL> mock_log_action = MagicMock ( ) <EOL> mock_log_entry . objects . log_action = mock_log_action <EOL> mock_action = MagicMock ( return_value = MagicMock ( series_number = '<STR_LIT>' ) ) <EOL> mock_proforma = MagicMock ( ) <EOL> mock_proforma . issue = mock_action <EOL> mock_proforma . cancel = mock_action <EOL> mock_proforma . pay = mock_action <EOL> mock_proforma . clone_into_draft = mock_action <EOL> mock_proforma . create_invoice = mock_action <EOL> with patch . multiple ( '<STR_LIT>' , <EOL> LogEntry = mock_log_entry , <EOL> Proforma = mock_proforma ) : <EOL> actions = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> for action in actions : <EOL> self . admin . post ( url , { <EOL> '<STR_LIT:action>' : action , <EOL> '<STR_LIT>' : [ u'<STR_LIT:1>' ] <EOL> } ) <EOL> assert mock_action . call_count <EOL> mock_action . reset_mock ( ) <EOL> if action == '<STR_LIT>' : <EOL> action = '<STR_LIT>' <EOL> mock_log_action . assert_called_with ( <EOL> user_id = <NUM_LIT:1> , <EOL> content_type_id = ContentType . objects . get_for_model ( proforma ) . pk , <EOL> object_id = <NUM_LIT:1> , <EOL> object_repr = unicode ( proforma ) , <EOL> action_flag = CHANGE , <EOL> change_message = '<STR_LIT>' . format ( <EOL> action = action . capitalize ( ) . replace ( '<STR_LIT:_>' , '<STR_LIT:U+0020>' ) <EOL> ) <EOL> ) <EOL> def test_actions_failed_no_log_entries ( self ) : <EOL> ProformaFactory . create ( ) <EOL> url = reverse ( '<STR_LIT>' ) <EOL> mock_log_entry = MagicMock ( ) <EOL> mock_log_action = MagicMock ( ) <EOL> mock_log_entry . objects . log_action = mock_log_action <EOL> exceptions = cycle ( [ ValueError , TransitionNotAllowed ] ) <EOL> def _exception_thrower ( * args ) : <EOL> raise exceptions . next ( ) <EOL> mock_action = MagicMock ( side_effect = _exception_thrower ) <EOL> mock_proforma = MagicMock ( ) <EOL> mock_proforma . issue = mock_action <EOL> mock_proforma . cancel = mock_action <EOL> mock_proforma . pay = mock_action <EOL> mock_proforma . clone_into_draft = mock_action <EOL> mock_proforma . create_invoice = mock_action <EOL> with patch . multiple ( '<STR_LIT>' , <EOL> LogEntry = mock_log_entry , <EOL> Proforma = mock_proforma ) : <EOL> actions = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> for action in actions : <EOL> self . admin . post ( url , { <EOL> '<STR_LIT:action>' : action , <EOL> '<STR_LIT>' : [ u'<STR_LIT:1>' ] <EOL> } ) <EOL> assert not mock_log_action . call_count </s>
