summaryrefslogtreecommitdiffstats
path: root/lcm
diff options
context:
space:
mode:
Diffstat (limited to 'lcm')
-rw-r--r--lcm/lcm/nf/tests/test_subscribe_notification.py25
-rw-r--r--lcm/lcm/nf/views/subscriptions_view.py5
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 = {