Skip to content

Commit

Permalink
Add error info when input error para
Browse files Browse the repository at this point in the history
This patch will add error info when Source_release or Target_release
is not existed. And then, update the decription in webUI.

JIRA:PDC-1204
  • Loading branch information
bliuredhat committed Jan 11, 2016
1 parent 95c178a commit a811063
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
14 changes: 14 additions & 0 deletions pdc/apps/component/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1200,6 +1200,20 @@ def test_release_component_clone_whithout_component(self):
format='json')
self.assertEquals(response.status_code, status.HTTP_204_NO_CONTENT)

def test_release_component_clone_with_error_target_release(self):
response = self.client.post(reverse('releasecomponentclone-list'),
{'source_release_id': 'release-1.0',
'target_release_id': 'xxxx-1.0'},
format='json')
self.assertEquals(response.status_code, status.HTTP_404_NOT_FOUND)

def test_release_component_clone_with_error_source_release(self):
response = self.client.post(reverse('releasecomponentclone-list'),
{'source_release_id': 'xxxx-1.0',
'target_release_id': 'release-1.0'},
format='json')
self.assertEquals(response.status_code, status.HTTP_404_NOT_FOUND)


class BugzillaComponentRESTTestCase(TestCaseWithChangeSetMixin, APITestCase):
fixtures = [
Expand Down
16 changes: 12 additions & 4 deletions pdc/apps/release/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from rest_framework.reverse import reverse
from rest_framework import viewsets, mixins, status
from rest_framework.response import Response

from django.http import Http404
from . import filters
from . import signals
from . import models
Expand Down Expand Up @@ -658,7 +658,7 @@ def create(self, request):
"url": [the link for target release component]
}
If `component_dist_git_branch` is present, it will be set for all
If `component_dist_git_branch` is present, the value will be set for all
release components under the target release. If missing, release
components will be cloned without changes.
Expand All @@ -675,8 +675,16 @@ def create(self, request):
return Response({'detail': 'Missing target_release_id'},
status=status.HTTP_400_BAD_REQUEST)
target_release_id = data.pop('target_release_id')
source_release = get_object_or_404(models.Release, release_id=source_release_id)
target_release = get_object_or_404(models.Release, release_id=target_release_id)
try:
source_release = get_object_or_404(models.Release, release_id=source_release_id)
except Http404:
return Response({'detail': 'Source_release_id is not existed'},
status=status.HTTP_404_NOT_FOUND)
try:
target_release = get_object_or_404(models.Release, release_id=target_release_id)
except Http404:
return Response({'detail': 'Target_release_id is not existed'},
status=status.HTTP_404_NOT_FOUND)
if source_release.releasecomponent_set.count() == 0:
return Response({'detail': 'there is no component in source release'},
status=status.HTTP_204_NO_CONTENT)
Expand Down

0 comments on commit a811063

Please sign in to comment.