Skip to content

Commit

Permalink
Merge pull request #53 from 2gis/jira-issues-filter-method
Browse files Browse the repository at this point in the history
Add custom_list method to get filtered jira issues
  • Loading branch information
Vadim committed Sep 26, 2016
2 parents 420dc4b + dc33a0b commit 79904f9
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
36 changes: 34 additions & 2 deletions cdws_api/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -873,9 +873,9 @@ def issue_request(self, externalId):
return 'https://{}/rest/api/latest/issue/{}'.\
format(settings.BUG_TRACKING_SYSTEM_HOST, externalId)

def _create_bug(self):
def _create_bug(self, issue_name='ISSUE-1'):
data = {
'externalId': 'ISSUE-1',
'externalId': issue_name,
'regexp': 'Regexp'
}
return self._call_rest('post', 'bugs/', data)
Expand Down Expand Up @@ -965,6 +965,38 @@ def test_bug_expired(self, m):
response = self._get_bugs()
self.assertEqual(0, len(response['results']))

@requests_mock.Mocker()
def test_bug_custom_list(self, m):
m.get(self.issue_request('ISSUE-1'), text=self.issue_found)
m.get(self.issue_request('ISSUE-2'), text=self.issue_found)
m.get(self.issue_request('JIRA-1'), text=self.issue_found)
m.get(self.issue_request('TEST-1'), text=self.issue_found)
self._create_bug('ISSUE-1')
self._create_bug('ISSUE-2')
self._create_bug('JIRA-1')
self._create_bug('TEST-1')

# without filter
response = self._get_bugs()
self.assertEqual(4, len(response['results']))

# empty filter
response = self._call_rest(
'get', 'bugs/custom_list/?issue_names__in=')
self.assertEqual(4, len(response['results']))

# two values in filter
response = self._call_rest(
'get', 'bugs/custom_list/?issue_names__in=ISSUE,JIRA')
self.assertEqual(3, len(response['results']))

# one value in filter
response = self._call_rest(
'get', 'bugs/custom_list/?issue_names__in=TEST')
self.assertEqual(1, len(response['results']))
issue = response['results'][0]
self.assertEqual('TEST-1', issue['externalId'])


class StagesApiTestCase(AbstractEntityApiTestCase):
def setUp(self):
Expand Down
13 changes: 13 additions & 0 deletions cdws_api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@

from django.contrib.contenttypes.models import ContentType
from django.utils import timezone
from django.db.models import Q

from comments.models import Comment

Expand Down Expand Up @@ -490,6 +491,18 @@ def create(self, request, *args, **kwargs):
name=response['summary'])
return Response(status=status.HTTP_201_CREATED)

@list_route(methods=['get'])
def custom_list(self, request, *args, **kwargs):
if 'issue_names__in' in request.GET \
and request.GET['issue_names__in'] != '':
issue_names = request.GET['issue_names__in'].split(',')
query = Q()
for issue_name in issue_names:
query = query | Q(externalId__startswith=issue_name)
self.queryset = Bug.objects.filter(query)

return self.list(request, *args, **kwargs)


class StageViewSet(GetOrCreateViewSet):
queryset = Stage.objects.all()
Expand Down

0 comments on commit 79904f9

Please sign in to comment.