aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormaopengzhang <zhang.maopeng1@zte.com.cn>2019-03-29 09:44:17 +0800
committermaopeng zhang <zhang.maopeng1@zte.com.cn>2019-03-29 05:49:45 +0000
commit7064c8b619fc896d6dc4622273e74dc18e6389eb (patch)
tree61252c16d0a756905087501e678f19e127c411fe
parent97fff6ec3205326087001712421cae35afa82ef0 (diff)
Fix subscription problem error bug
Fix subscription problem error bug Change-Id: Idfaefefc64ecab6cf09b4b38898112f9a00097f7 Issue-ID: VFC-1059 Signed-off-by: maopengzhang <zhang.maopeng1@zte.com.cn>
-rw-r--r--lcm/ns/tests/test_subscribe_notification.py14
-rw-r--r--lcm/ns/views/sol/subscriptions_view.py16
2 files changed, 21 insertions, 9 deletions
diff --git a/lcm/ns/tests/test_subscribe_notification.py b/lcm/ns/tests/test_subscribe_notification.py
index 6e3f84cf..38354a25 100644
--- a/lcm/ns/tests/test_subscribe_notification.py
+++ b/lcm/ns/tests/test_subscribe_notification.py
@@ -30,7 +30,7 @@ class TestSubscription(TestCase):
def test_subscribe_notification_simple(self, mock_uuid4, mock_requests):
temp_uuid = "99442b18-a5c7-11e8-998c-bf1755941f13"
dummy_subscription = {
- "callbackUri": "http://aurl.com"
+ "callbackUri": "http://test.com"
}
mock_requests.return_value.status_code = 204
mock_requests.get.status_code = 204
@@ -94,8 +94,10 @@ class TestSubscription(TestCase):
}
mock_requests.return_value.status_code = 204
mock_requests.get.return_value.status_code = 204
+
expected_data = {
- 'error': 'Auth type should be BASIC'
+ 'status': 500,
+ 'detail': 'Auth type should be BASIC'
}
response = self.client.post("/api/nslcm/v1/subscriptions", data=dummy_subscription, format='json')
self.assertEqual(500, response.status_code)
@@ -118,8 +120,9 @@ class TestSubscription(TestCase):
mock_requests.return_value.status_code = 204
mock_requests.get.return_value.status_code = 204
expected_data = {
- 'error': 'If you are setting operationTypes,then notificationTypes must be '
- 'NsLcmOperationOccurrenceNotification'
+ 'status': 500,
+ 'detail': 'If you are setting operationTypes,then notificationTypes must be '
+ 'NsLcmOperationOccurrenceNotification'
}
response = self.client.post("/api/nslcm/v1/subscriptions", data=dummy_subscription, format='json')
self.assertEqual(500, response.status_code)
@@ -151,6 +154,7 @@ class TestSubscription(TestCase):
response = self.client.post("/api/nslcm/v1/subscriptions", data=dummy_subscription, format='json')
self.assertEqual(303, response.status_code)
expected_data = {
- "error": "Already Subscription exists with the same callbackUri and filter"
+ 'status': 303,
+ 'detail': 'Already Subscription exists with the same callbackUri and filter'
}
self.assertEqual(expected_data, response.data)
diff --git a/lcm/ns/views/sol/subscriptions_view.py b/lcm/ns/views/sol/subscriptions_view.py
index ae77ed0f..d962d1dc 100644
--- a/lcm/ns/views/sol/subscriptions_view.py
+++ b/lcm/ns/views/sol/subscriptions_view.py
@@ -29,6 +29,7 @@ from lcm.ns.biz.query_subscription import QuerySubscription
from lcm.ns.serializers.sol.lccn_subscription_request import LccnSubscriptionRequestSerializer
from lcm.ns.serializers.sol.pub_serializers import ProblemDetailsSerializer
from lcm.pub.exceptions import NSLCMException
+from lcm.pub.exceptions import BadRequestException
logger = logging.getLogger(__name__)
VALID_FILTERS = ["operationTypes", "operationStates", "notificationTypes", "nsInstanceId",
@@ -61,7 +62,7 @@ class SubscriptionsView(APIView):
lccn_subscription_request_serializer = LccnSubscriptionRequestSerializer(
data=request.data)
if not lccn_subscription_request_serializer.is_valid():
- raise NSLCMException(
+ raise BadRequestException(
lccn_subscription_request_serializer.errors)
subscription = CreateSubscription(
lccn_subscription_request_serializer.data).do_biz()
@@ -87,15 +88,22 @@ class SubscriptionsView(APIView):
if not sub_resp_serializer.is_valid():
raise NSLCMException(sub_resp_serializer.errors)
return Response(data=sub_resp_serializer.data, status=status.HTTP_201_CREATED)
+ except BadRequestException as e:
+ logger.error("Exception in InstantiateNsView: %s", e.message)
+ data = {'status': status.HTTP_400_BAD_REQUEST, 'detail': e.message}
+ return Response(data=data, status=status.HTTP_400_BAD_REQUEST)
except NSLCMException as e:
logger.error(e.message)
if "exists" in e.message:
- return Response(data={'error': '%s' % e.message}, status=status.HTTP_303_SEE_OTHER)
- return Response(data={'error': '%s' % e.message}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+ data = {'status': status.HTTP_303_SEE_OTHER, 'detail': e.message}
+ return Response(data=data, status=status.HTTP_303_SEE_OTHER)
+ data = {'status': status.HTTP_500_INTERNAL_SERVER_ERROR, 'detail': e.message}
+ return Response(data=data, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
except Exception as e:
logger.error(e.message)
logger.error(traceback.format_exc())
- return Response(data={'error': e.message}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
+ data = {'status': status.HTTP_500_INTERNAL_SERVER_ERROR, 'detail': e.message}
+ return Response(data=data, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
@swagger_auto_schema(
responses={