示例#1
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
示例#2
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
示例#3
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)
示例#4
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)