def test_extra_kwargs(self): # create and connect a pre and post fake receiver to the desired signal pre_receiver = MagicMock(return_value=None) post_receiver = MagicMock(return_value=None) # set the return value of the pre_receiver to the uuid value # so we can use it in later test. def side_effect(*args, **kwargs): pre_receiver.return_value = kwargs['uuid'] return kwargs pre_receiver.side_effect = side_effect pre_transition_event.connect( pre_receiver, dispatch_uid='blah kwargs pre' ) post_transition_event.connect( post_receiver, dispatch_uid='blah kwargs post' ) # call the transition that will trigger the signal self.new_instance.test_some_event() # ensure the receiver was only called once with the correct args post_receiver.assert_called_once_with( instance=self.new_instance, from_state=FakeStates.NEW, to_state=FakeStates.WHATEVER, state='fake_state', transition_name='test_some_event', signal=post_transition_event, sender=self.new_instance.__class__, uuid=pre_receiver.return_value, some_event_name="Yes An Event" ) # cleanup pre_transition_event.disconnect(pre_receiver) post_transition_event.disconnect(post_receiver)
def test_transaction_atomic_works(self): # create and connect a post fake receiver to the desired signal post_receiver = MagicMock() post_receiver.side_effect = AttributeError('boo' + unichr(5000)) post_transition_event.connect( post_receiver, dispatch_uid='blah kwargs post asdfasf' ) self.new_instance.test_some_event() post_transition_event.disconnect(post_receiver)
def test_transition_events(self): # create and connect a pre and post fake receiver to the desired signal pre_receiver = MagicMock(return_value=None) post_receiver = MagicMock(return_value=None) # set the return value of the pre_receiver to the uuid value # so we can use it in later test. def side_effect(*args, **kwargs): pre_receiver.return_value = kwargs['uuid'] return kwargs pre_receiver.side_effect = side_effect pre_transition_event.connect( pre_receiver, dispatch_uid='blah blah blah pre' ) post_transition_event.connect( post_receiver, dispatch_uid='blah blah blah post' ) # call the transition that will trigger the signal self.new_instance.make_not_new() # ensure that the receiver was only called once self.assertTrue(post_receiver.called) self.assertEquals(post_receiver.call_count, 1) # ensure the receiver was only called once with the correct args post_receiver.assert_called_once_with( instance=self.new_instance, from_state=FakeStates.NEW, to_state=FakeStates.NOT_NEW, state='fake_state', transition_name='make_not_new', signal=post_transition_event, sender=self.new_instance.__class__, uuid=pre_receiver.return_value ) # cleanup pre_transition_event.disconnect(pre_receiver) post_transition_event.disconnect(post_receiver)
def ready(self): post_transition_event.connect( on_fakemodel_event, dispatch_uid='something random' )