Skip to content

Commit

Permalink
Sends back a group call report for summary of task group with 0 tasks
Browse files Browse the repository at this point in the history
Originally we wanted to return  a 404 when querying for a task group that has no tasks
associated with it. However, we always return a task group id when kicking off the
applicability regeneration task. User should be able to see that 0 tasks were dispatched
as part of that task group.

https://pulp.plan.io/issues/1582
closes #1582
  • Loading branch information
dkliban committed Jan 26, 2016
1 parent 1b126ba commit 9b1cd29
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 26 deletions.
4 changes: 0 additions & 4 deletions server/pulp/server/webservices/views/task_groups.py
Expand Up @@ -50,14 +50,10 @@ def get(self, request, group_id):
:return: Response containing a serialized dict of the task group summary
:rtype : django.http.HttpResponse
:raises MissingResource: if group id is not found
"""
tasks = TaskStatus.objects(group_id=group_id)
task_group_total = tasks.count()

if task_group_total == 0:
raise MissingResource(group_id)

summary = {'total': task_group_total}
for state in CALL_STATES:
summary[state] = tasks.filter(state=state).count()
Expand Down
51 changes: 29 additions & 22 deletions server/test/unit/server/webservices/views/test_task_groups.py
Expand Up @@ -6,27 +6,51 @@
from .base import assert_auth_READ
from pulp.common.compat import unittest

from pulp.server.exceptions import MissingResource
from pulp.server.webservices.views.task_groups import TaskGroupSummaryView


class MockQuerySet(object):

def __init__(self, list_of_objects):
self.items = list_of_objects
self.i = 0
self.n = len(self.items)

def count(self):
return len(self.items)

def filter(self, state=None):
filtered_list = []
for item in self.items:
if item['state'] == state:
filtered_list.append(item)
return MockQuerySet(filtered_list)


class TestTaskGroupSummary(unittest.TestCase):
"""
Tests for TaskGroupSummaryView
"""

@mock.patch('pulp.server.webservices.views.decorators._verify_auth',
new=assert_auth_READ())
@mock.patch('pulp.server.webservices.views.task_groups.TaskStatus.objects')
def test_get_task_group_summary_nonexistant(self, mock_objects):
@mock.patch(
'pulp.server.webservices.views.task_groups.generate_json_response_with_pulp_encoder')
def test_get_task_group_summary_nonexistant(self, mock_resp, mock_objects):
"""
Test get task_group_summary with no tasks
"""

mock_request = mock.MagicMock()
mock_objects.return_value.count.return_value = 0
mock_objects.return_value = MockQuerySet([])

task_group_summary = TaskGroupSummaryView()
self.assertRaises(MissingResource, task_group_summary.get, mock_request, 'mock_task')
response = task_group_summary.get(mock_request, 'mock_task')

expected_content = {'accepted': 0, 'finished': 0, 'running': 0, 'canceled': 0,
'waiting': 0, 'skipped': 0, 'suspended': 0, 'error': 0, 'total': 0}
mock_resp.assert_called_with(expected_content)
self.assertTrue(response is mock_resp.return_value)

@mock.patch('pulp.server.webservices.views.decorators._verify_auth',
new=assert_auth_READ())
Expand All @@ -37,23 +61,6 @@ def test_get_task_group_summary(self, mock_resp, mock_objects):
"""
Test get task_group_summary with multiple tasks
"""
class MockQuerySet(object):

def __init__(self, list_of_objects):
self.items = list_of_objects
self.i = 0
self.n = len(self.items)

def count(self):
return len(self.items)

def filter(self, state=None):
filtered_list = []
for item in self.items:
if item['state'] == state:
filtered_list.append(item)
return MockQuerySet(filtered_list)

mock_request = mock.MagicMock()
mock_objects.return_value = MockQuerySet([{'id': 'mock_task', 'worker_name': 'mock',
'state': 'running'},
Expand Down

0 comments on commit 9b1cd29

Please sign in to comment.