Example #1
0
    def test_unbind_rejected(self, mock_task_objects, mock_unbind_failed,
                             mock_date):
        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
        }
        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
        document = Document(routing=['A', 'B'],
                            status='rejected',
                            data=call_context)
        reply = Rejected(document)
        handler = self.reply_handler()
        handler.rejected(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_ERROR_STATE)
        # validate bind action updated
        mock_unbind_failed.assert_called_with(task_id, call_context)
Example #2
0
 def test_notify(self):
     l = Listener()
     reply = Rejected(document)
     reply.notify(l)
     l.rejected.assert_called_once_with(reply)
     f = Mock()
     reply.notify(f)
     f.assert_called_once_with(reply)
Example #3
0
    def test_rejected(self, mock_task_failed):
        task_id = 'task_1'
        call_context = {
            'task_id': task_id,
        }
        document = Document(routing=['A', 'B'], any=call_context)
        reply = Rejected(document)
        handler = self.reply_handler()
        handler.rejected(reply)

        # validate task updated
        mock_task_failed.assert_called_with(task_id)
Example #4
0
    def test_rejected(self, mock_task_objects, mock_date):
        task_id = 'task_1'
        call_context = {
            'task_id': task_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
        document = Document(routing=['A', 'B'], data=call_context)
        reply = Rejected(document)
        handler = self.reply_handler()
        handler.rejected(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_ERROR_STATE)
Example #5
0
    def test_unbind_rejected(self, mock_task_failed, 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
        }
        document = Document(routing=['A', 'B'],
                            status='rejected',
                            any=call_context)
        reply = Rejected(document)
        handler = self.reply_handler()
        handler.rejected(reply)

        # validate task updated
        mock_task_failed.assert_called_with(task_id)
        # validate bind action updated
        mock_unbind_failed.assert_called_with(task_id, call_context)
Example #6
0
 def test_init(self):
     reply = Rejected(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)
Example #7
0
 def test_str(self):
     reply = Rejected(document)
     s = str(reply)
     self.assertTrue(isinstance(s, str))