diff options
author | hongyuzhao <zhao.hongyu@zte.com.cn> | 2019-06-14 16:15:04 +0800 |
---|---|---|
committer | Fu Jinhua <fu.jinhua@zte.com.cn> | 2019-06-14 08:48:57 +0000 |
commit | 6a15a10abf1ea0d90708c607a1bfc00dc50ca06f (patch) | |
tree | 2a767da2116a20a4c8861f1f1e9e42518fefb129 | |
parent | db895fab77265d947dedb657d77941020278400c (diff) |
Fix bug for status code when subscription post request body invalid what client inputs.
Issue-ID: VFC-1417
Signed-off-by: hongyuzhao <zhao.hongyu@zte.com.cn>
Change-Id: Id18312e77a6d93ac1afd8c5b8307f44f51a744cd
-rw-r--r-- | lcm/lcm/nf/tests/test_subscribe_notification.py | 25 | ||||
-rw-r--r-- | lcm/lcm/nf/views/subscriptions_view.py | 5 |
2 files changed, 28 insertions, 2 deletions
diff --git a/lcm/lcm/nf/tests/test_subscribe_notification.py b/lcm/lcm/nf/tests/test_subscribe_notification.py index 73463efa..94c2ff7c 100644 --- a/lcm/lcm/nf/tests/test_subscribe_notification.py +++ b/lcm/lcm/nf/tests/test_subscribe_notification.py @@ -152,3 +152,28 @@ class TestSubscription(TestCase): self.assertEqual(temp_uuid, response.data["id"]) response = self.client.post("/api/vnflcm/v1/subscriptions", data=dummy_subscription, format='json') self.assertEqual(303, response.status_code) + + @mock.patch("requests.get") + @mock.patch.object(uuid, 'uuid4') + def test_badreq_subscription(self, mock_uuid4, mock_requests): + temp_uuid = str(uuid.uuid4()) + miss_callbackUri_subscription = { + "filter": { + "notificationTypes": ["VnfLcmOperationOccurrenceNotification"], + "operationTypes": [ + "INSTANTIATE" + ], + "operationStates": [ + "STARTING" + ] + } + } + mock_requests.return_value.status_code = 204 + mock_requests.get.return_value.status_code = 204 + mock_uuid4.return_value = temp_uuid + response = self.client.post("/api/vnflcm/v1/subscriptions", data=miss_callbackUri_subscription, format='json') + self.assertEqual(400, response.status_code) + self.assertEqual({'callbackUri': ['This field is required.']}, response.data['detail']) + # self.assertEqual(temp_uuid, response.data["id"]) + # response = self.client.post("/api/vnflcm/v1/subscriptions", data=dummy_subscription, format='json') + # self.assertEqual(303, response.status_code) diff --git a/lcm/lcm/nf/views/subscriptions_view.py b/lcm/lcm/nf/views/subscriptions_view.py index a9ffed9b..c5496277 100644 --- a/lcm/lcm/nf/views/subscriptions_view.py +++ b/lcm/lcm/nf/views/subscriptions_view.py @@ -27,7 +27,7 @@ from lcm.nf.serializers.lccn_subscription_request import LccnSubscriptionRequest from lcm.nf.serializers.lccn_subscription import LccnSubscriptionSerializer
from lcm.nf.serializers.lccn_subscriptions import LccnSubscriptionsSerializer
from lcm.nf.serializers.response import ProblemDetailsSerializer
-from lcm.pub.exceptions import NFLCMException
+from lcm.pub.exceptions import NFLCMException, NFLCMExceptionBadRequest
from .common import view_safe_call_with_log
logger = logging.getLogger(__name__)
@@ -50,6 +50,7 @@ class SubscriptionsView(APIView): responses={
status.HTTP_201_CREATED: LccnSubscriptionSerializer(),
status.HTTP_303_SEE_OTHER: ProblemDetailsSerializer(),
+ status.HTTP_400_BAD_REQUEST: ProblemDetailsSerializer(),
status.HTTP_500_INTERNAL_SERVER_ERROR: ProblemDetailsSerializer()
}
)
@@ -59,7 +60,7 @@ class SubscriptionsView(APIView): lccn_subscription_request_serializer = LccnSubscriptionRequestSerializer(data=request.data)
if not lccn_subscription_request_serializer.is_valid():
- raise NFLCMException(lccn_subscription_request_serializer.errors)
+ raise NFLCMExceptionBadRequest(lccn_subscription_request_serializer.errors)
subscription = CreateSubscription(
lccn_subscription_request_serializer.data).do_biz()
lccn_notifications_filter = {
|