예제 #1
0
 def test_one_callback(self):
     action = Action('test', sources=['draft'], callbacks=[disable_invoice])
     self.assertTrue(self.invoice.is_available)
     state = State(self.invoice, 'status')
     action.change_state(state)
     self.assertEqual(self.invoice.status, 'draft')
     self.assertFalse(self.invoice.is_available)
     self.assertFalse(state.is_locked())
예제 #2
0
 def test_many_side_effects(self):
     action = Action('test',
                     sources=['draft'],
                     side_effects=[disable_invoice, enable_invoice])
     self.assertTrue(self.invoice.is_available)
     state = State(self.invoice, 'status')
     action.change_state(state)
     self.assertEqual(self.invoice.status, 'draft')
     self.assertTrue(self.invoice.is_available)
     self.assertFalse(state.is_locked())
예제 #3
0
 def test_failure_during_callbacks_with_failed_state(self):
     action = Action(
         'test',
         failed_state='failed',
         sources=['draft'],
         side_effects=[disable_invoice, fail_invoice, enable_invoice])
     self.assertTrue(self.invoice.is_available)
     state = State(self.invoice, 'status')
     action.change_state(state)
     self.assertEqual(self.invoice.status, 'failed')
     self.assertFalse(self.invoice.is_available)
     self.assertFalse(state.is_locked())
예제 #4
0
 def test_many_callback(self):
     action = Action('test',
                     side_effects=[fail_invoice],
                     sources=['draft'],
                     failure_callbacks=[disable_invoice, receive_invoice],
                     failed_state='failed')
     self.assertTrue(self.invoice.is_available)
     self.assertFalse(self.invoice.customer_received)
     state = State(self.invoice, 'status')
     action.change_state(state)
     self.assertEqual(self.invoice.status, 'failed')
     self.assertFalse(self.invoice.is_available)
     self.assertTrue(self.invoice.customer_received)
     self.assertFalse(state.is_locked())
예제 #5
0
 def test_callbacks_with_parameters(self):
     update_invoice(self.invoice, is_available=True, customer_received=True)
     action = Action('test',
                     failed_state='failed',
                     sources=['draft'],
                     callbacks=[update_invoice])
     self.invoice.refresh_from_db()
     self.assertTrue(self.invoice.is_available)
     self.assertTrue(self.invoice.customer_received)
     state = State(self.invoice, 'status')
     action.change_state(state, is_available=False, customer_received=False)
     self.invoice.refresh_from_db()
     self.assertFalse(self.invoice.is_available)
     self.assertFalse(self.invoice.customer_received)
     self.assertFalse(state.is_locked())
예제 #6
0
 def test_failure_callback_exception_passed(self, debug_mock):
     update_invoice(self.invoice, is_available=True, customer_received=True)
     action = Action('test',
                     failed_state='failed',
                     side_effects=[fail_invoice],
                     sources=['draft'],
                     failure_callbacks=[debug_action])
     self.invoice.refresh_from_db()
     state = State(self.invoice, 'status')
     action.change_state(state, foo="bar")
     self.assertTrue(debug_mock.called)
     self.assertEqual(debug_mock.call_count, 1)
     call_args = debug_mock.call_args[0]
     call_kwargs = debug_mock.call_args[1]
     self.assertEqual(call_args, (self.invoice, ))
     self.assertEqual(len(call_kwargs), 2)
     self.assertTrue(isinstance(call_kwargs['exception'], Exception))
     self.assertEqual(call_kwargs['foo'], 'bar')