def test_execute_with_failure(self, load_function): # Setup the scenario target_function = 'fail' issue = G(Issue) r = G(ResponderAction, target_function=target_function, function_kwargs={'foo': 'bar'}) now = datetime(2014, 8, 11, 15, 0, 0) self.assertEqual(0, IssueAction.objects.count()) load_function.return_value.side_effect = Exception('what-an-exceptional-message') # Run the code with freeze_time(now): ia = r.execute(issue) ia.save() self.assertTrue(isinstance(ia, IssueAction)) # Verify expectations expected_issue_action_kwargs = { 'success': False, 'execution_time': now, 'responder_action': r, } load_function.assert_called_with(target_function) load_function.return_value.assert_called_with(issue, foo='bar') self.assertTrue(IssueAction.objects.filter(issue=issue, **expected_issue_action_kwargs).exists()) self.assertEqual(json.dumps(str(Exception('what-an-exceptional-message'))), IssueAction.objects.get().details)
def test_execute(self, load_function): # Setup the scenario target_function = 'do' issue = G(Issue) r = G(ResponderAction, target_function=target_function, function_kwargs={'foo': 'bar'}) now = datetime(2014, 8, 11, 15, 0, 0) self.assertEqual(0, IssueAction.objects.count()) load_function.return_value.return_value = None # Run the code with freeze_time(now): ia = r.execute(issue) ia.save() self.assertTrue(isinstance(ia, IssueAction)) # Verify expectations expected_issue_action_kwargs = { 'success': True, 'execution_time': now, 'responder_action': r, } load_function.assert_called_with(target_function) load_function.return_value.assert_called_with(issue, foo='bar') self.assertTrue(IssueAction.objects.filter(issue=issue, **expected_issue_action_kwargs).exists()) # The 'None' that is stored as the details is first json encoded self.assertEqual(json.dumps(None), IssueAction.objects.get().details)
def test_execute_with_failure(self, load_function): # Setup the scenario target_function = 'fail' issue = G(Issue) r = G(ResponderAction, target_function=target_function, function_kwargs={'foo': 'bar'}) now = datetime(2014, 8, 11, 15, 0, 0) self.assertEqual(0, IssueAction.objects.count()) load_function.return_value.side_effect = Exception( 'what-an-exceptional-message') # Run the code with freeze_time(now): ia = r.execute(issue) ia.save() self.assertTrue(isinstance(ia, IssueAction)) # Verify expectations expected_issue_action_kwargs = { 'success': False, 'execution_time': now, 'responder_action': r, } load_function.assert_called_with(target_function) load_function.return_value.assert_called_with(issue, foo='bar') self.assertTrue( IssueAction.objects.filter( action_issue_id=issue.id, **expected_issue_action_kwargs).exists()) self.assertEqual( json.dumps(str(Exception('what-an-exceptional-message'))), IssueAction.objects.get().details)
def test_execute(self, load_function): # Setup the scenario target_function = 'do' issue = G(Issue) r = G(ResponderAction, target_function=target_function, function_kwargs={'foo': 'bar'}) now = datetime(2014, 8, 11, 15, 0, 0) self.assertEqual(0, IssueAction.objects.count()) load_function.return_value.return_value = None # Run the code with freeze_time(now): ia = r.execute(issue) ia.save() self.assertTrue(isinstance(ia, IssueAction)) # Verify expectations expected_issue_action_kwargs = { 'success': True, 'execution_time': now, 'responder_action': r, } load_function.assert_called_with(target_function) load_function.return_value.assert_called_with(issue, foo='bar') self.assertTrue( IssueAction.objects.filter( action_issue_id=issue.id, **expected_issue_action_kwargs).exists()) # The 'None' that is stored as the details is first json encoded self.assertEqual(json.dumps(None), IssueAction.objects.get().details)
def test_respond(self, load_function): # Setup the scenario target_function = 'do' issue = G(Issue, name='error-42') responder = G(Responder, issue=issue, watch_pattern='error-\d+') G(ResponderAction, responder=responder, target_function=target_function, delay_sec=0) # Run the code r = responder.respond(issue) # Verify expectations self.assertTrue(r) load_function.assert_called_with(target_function)
def test_respond(self, load_function): # Setup the scenario target_function = 'do' issue = G(Issue, name='error-42') responder = G(Responder, issue=issue, watch_pattern=r'error-\d+') G(ResponderAction, responder=responder, target_function=target_function, delay_sec=0) # Run the code r = responder.respond(issue) # Verify expectations self.assertTrue(r) load_function.assert_called_with(target_function)