Skip to content

Commit

Permalink
Add ability to access projects by name
Browse files Browse the repository at this point in the history
Now projects can also be accessed through urls by /projects/?name=<project_name>
  • Loading branch information
shubhamdotjain committed Aug 6, 2018
1 parent 5fe69c8 commit 547e9c3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions api/rest.py
Expand Up @@ -148,6 +148,12 @@ class ProjectsViewSet(viewsets.ModelViewSet):
permission_classes = (PatchewPermission,)
authentication_classes = (CsrfExemptSessionAuthentication, )

def get_queryset(self):
name = self.request.query_params.get('name', None)
if name is not None:
return Project.objects.filter(name=name).order_by('id')
return Project.objects.all().order_by('id')

@action(methods=['post'], detail=True, permission_classes=[ImportPermission])
def update_project_head(self, request, pk=None):
"""
Expand Down
6 changes: 6 additions & 0 deletions tests/test_rest.py
Expand Up @@ -441,6 +441,12 @@ def test_message_replies(self):
self.assertEqual(resp.data['results'][3]['resource_uri'], self.PROJECT_BASE + 'messages/e0858c00-ccb6-e533-ee3e-9ba84ca45a7b@redhat.com/')
self.assertEqual(resp.data['results'][3]['subject'], 'Re: [Qemu-devel] [PATCH v4 0/2] Report format specific info for LUKS block driver')

def test_project_filter(self):
resp = self.api_client.get(self.REST_BASE + 'projects/?name=QEMU')
project = resp.data['results'][0]
self.assertEquals(project['name'], "QEMU")
self.assertEquals(project['mailing_list'], "qemu-devel@nongnu.org")

def test_schema(self):
resp = self.api_client.get(self.REST_BASE + 'schema/')
self.assertEqual(resp.status_code, 200)
Expand Down

0 comments on commit 547e9c3

Please sign in to comment.