Exemplo n.º 1
0
    def test_get_task_resource(self, mock_resp, mock_task_status,
                               mock_task_serial, mock_worker):
        """
        Test get task_resource with an existing task.
        """
        def mock_serializer(arg):
            return arg

        mock_request = mock.MagicMock()
        mock_task_status.objects.get.return_value = {
            'id': 'mock_task',
            'worker_name': 'mock'
        }
        mock_task_serial.side_effect = mock_serializer
        mock_worker_inst = mock.MagicMock()
        mock_worker_inst.queue_name = 'mock_q_name'
        mock_worker.return_value = mock_worker_inst

        task_resource = TaskResourceView()
        response = task_resource.get(mock_request, 'mock_task')

        expected_content = {
            'id': 'mock_task',
            'worker_name': 'mock',
            'queue': 'mock_q_name'
        }
        mock_resp.assert_called_once_with(expected_content)
        self.assertTrue(response is mock_resp.return_value)
Exemplo n.º 2
0
    def test_delete_task_resource(self, mock_resp, mock_task):
        """
        View should dispatch a task.cancel with the task id.
        """
        mock_request = mock.MagicMock()
        task_resource = TaskResourceView()

        response = task_resource.delete(mock_request, 'mock_task_id')
        mock_task.cancel.assert_called_once_with('mock_task_id')
        mock_resp.assert_called_once_with(None)
        self.assertTrue(response is mock_resp.return_value)
Exemplo n.º 3
0
    def test_delete_task_resource(self, mock_resp, mock_task):
        """
        View should dispatch a task.cancel with the task id.
        """
        mock_request = mock.MagicMock()
        task_resource = TaskResourceView()

        response = task_resource.delete(mock_request, 'mock_task_id')
        mock_task.cancel.assert_called_once_with('mock_task_id')
        mock_resp.assert_called_once_with(None)
        self.assertTrue(response is mock_resp.return_value)
Exemplo n.º 4
0
    def test_get_task_resource_invalid_task(self, mock_task_status):
        """
        Test get task_resource with an non-existing task.
        """

        mock_request = mock.MagicMock()
        mock_task_status.objects.get.side_effect = DoesNotExist()

        task_resource = TaskResourceView()
        try:
            task_resource.get(mock_request, 'mock_task')
        except MissingResource, response:
            pass
Exemplo n.º 5
0
    def test_get_task_resource_invalid_task(self, mock_task_status):
        """
        Test get task_resource with an non-existing task.
        """

        mock_request = mock.MagicMock()
        mock_task_status.objects.get.side_effect = DoesNotExist()

        task_resource = TaskResourceView()
        try:
            task_resource.get(mock_request, 'mock_task')
        except MissingResource, response:
            pass
Exemplo n.º 6
0
    def test_get_task_resource(self, mock_resp, mock_task_status, mock_task_serial, mock_worker):
        """
        Test get task_resource with an existing task.
        """
        def mock_serializer(arg):
            return arg

        mock_request = mock.MagicMock()
        mock_task_status.objects.get.return_value = {'id': 'mock_task', 'worker_name': 'mock'}
        mock_task_serial.side_effect = mock_serializer
        mock_worker_inst = mock.MagicMock()
        mock_worker_inst.queue_name = 'mock_q_name'
        mock_worker.return_value = mock_worker_inst

        task_resource = TaskResourceView()
        response = task_resource.get(mock_request, 'mock_task')

        expected_content = {'id': 'mock_task', 'worker_name': 'mock', 'queue': 'mock_q_name'}
        mock_resp.assert_called_once_with(expected_content)
        self.assertTrue(response is mock_resp.return_value)