def test_notify(self): l = Listener() reply = Succeeded(document) reply.notify(l) l.succeeded.assert_called_once_with(reply) f = Mock() reply.notify(f) f.assert_called_once_with(reply)
def test_init(self): reply = Succeeded(document) self.assertEqual(reply.sn, document.sn) self.assertEqual(reply.origin, document.routing[0]) self.assertEqual(reply.timestamp, document.timestamp) self.assertEqual(reply.data, document.data) self.assertFalse(reply.failed()) self.assertTrue(reply.succeeded())
def test_agent_succeeded(self, mock_task_objects, mock_date): dispatch_report = dict(succeeded=True) task_id = 'task_1' consumer_id = 'consumer_1' repo_id = 'repo_1' dist_id = 'dist_1' call_context = { 'task_id': task_id, 'consumer_id': consumer_id, 'repo_id': repo_id, 'distributor_id': dist_id } mock_return_tasks = Mock() mock_task_objects.return_value = mock_return_tasks test_date = '2014-12-16T20:03:10Z' mock_date.return_value = test_date result = dict(retval=dispatch_report) document = Document(routing=['A', 'B'], result=result, data=call_context) reply = Succeeded(document) handler = self.reply_handler() handler.succeeded(reply) # validate task updated mock_task_objects.assert_called_with(task_id=task_id) mock_return_tasks.update_one.assert_called_with( set__finish_time=test_date, set__state=constants.CALL_FINISHED_STATE, set__result=dispatch_report)
def test_unbind_succeeded_with_error_report(self, mock_task_succeeded, mock_unbind_failed): task_id = 'task_1' consumer_id = 'consumer_1' repo_id = 'repo_1' dist_id = 'dist_1' call_context = { 'action': 'unbind', 'task_id': task_id, 'consumer_id': consumer_id, 'repo_id': repo_id, 'distributor_id': dist_id } dispatch_report = dict(succeeded=False) result = Document(retval=dispatch_report) document = Document(routing=['A', 'B'], result=result, any=call_context) reply = Succeeded(document) handler = self.reply_handler() handler.succeeded(reply) # validate task updated mock_task_succeeded.assert_called_with(task_id, dispatch_report) # validate bind action updated mock_unbind_failed.assert_called_with(task_id, call_context)
def test_agent_succeeded(self, mock_task_succeeded): dispatch_report = dict(succeeded=True) task_id = 'task_1' consumer_id = 'consumer_1' repo_id = 'repo_1' dist_id = 'dist_1' call_context = { 'task_id': task_id, 'consumer_id': consumer_id, 'repo_id': repo_id, 'distributor_id': dist_id } result = dict(retval=dispatch_report) document = Document(routing=['A', 'B'], result=result, any=call_context) reply = Succeeded(document) handler = self.reply_handler() handler.succeeded(reply) # validate task updated mock_task_succeeded.assert_called_with(task_id, dispatch_report)
def test_str(self): reply = Succeeded(document) s = str(reply) self.assertTrue(isinstance(s, str))