diff options
author | Yan Yang <yangyanyj@chinamobile.com> | 2019-03-13 09:45:55 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2019-03-13 09:45:55 +0000 |
commit | fcba1c612c515d78fb3f8ff5eb7add34968ea3ff (patch) | |
tree | ade359b6af0eaa3105bbcffd318c7ffc99a63c9b | |
parent | 56047aeca8de9a326e21e611a04e82deff160194 (diff) | |
parent | fb294a09c7e57ea7ee5d84ef62d6b38ba5573550 (diff) |
Merge "Add VNFPKGM Terminate Subscription API"
-rwxr-xr-x | catalog/packages/biz/vnf_pkg_subscription.py | 14 | ||||
-rw-r--r-- | catalog/packages/tests/test_vnf_pkg_subscription.py | 22 | ||||
-rwxr-xr-x | catalog/packages/views/vnf_package_subscription_views.py | 27 |
3 files changed, 62 insertions, 1 deletions
diff --git a/catalog/packages/biz/vnf_pkg_subscription.py b/catalog/packages/biz/vnf_pkg_subscription.py index 9d4acb98..7e72311b 100755 --- a/catalog/packages/biz/vnf_pkg_subscription.py +++ b/catalog/packages/biz/vnf_pkg_subscription.py @@ -167,3 +167,17 @@ class QuerySubscription(object): raise SubscriptionDoesNotExistsException("Subscription with ID: %s " "does not exists" % subscription_id) return subscription[0].toDict() + + +class TerminateSubscription(object): + + def terminate(self, subscription_id): + logger.debug("TerminateSubscriptions--delete--biz::> " + "ID: %s" % subscription_id) + + subscription = VnfPkgSubscriptionModel.objects.filter( + subscription_id=subscription_id) + if not subscription.exists(): + raise SubscriptionDoesNotExistsException("Subscription with ID: %s " + "does not exists" % subscription_id) + subscription[0].delete() diff --git a/catalog/packages/tests/test_vnf_pkg_subscription.py b/catalog/packages/tests/test_vnf_pkg_subscription.py index 40eb2af3..9a21c1e3 100644 --- a/catalog/packages/tests/test_vnf_pkg_subscription.py +++ b/catalog/packages/tests/test_vnf_pkg_subscription.py @@ -153,3 +153,25 @@ class TestNfPackageSubscription(TestCase): response = self.client.get("/api/vnfpkgm/v1/subscriptions/" + dummy_uuid, format='json') self.assertEqual(404, response.status_code) + + @mock.patch("requests.get") + @mock.patch.object(uuid, 'uuid4') + def test_delete_subscription_with_id(self, mock_uuid4, mock_requests): + temp_uuid = "99442b18-a5c7-11e8-998c-bf1755941f13" + dummy_uuid = str(uuid.uuid4()) + mock_requests.return_value.status_code = 204 + mock_requests.get.status_code = 204 + mock_uuid4.return_value = temp_uuid + self.client.post("/api/vnfpkgm/v1/subscriptions", + data=self.vnf_subscription_data, format='json') + self.client.get("/api/vnfpkgm/v1/subscriptions/" + dummy_uuid, + format='json') + response = self.client.delete("/api/vnfpkgm/v1/subscriptions/" + temp_uuid) + self.assertEqual(204, response.status_code) + + @mock.patch("requests.get") + @mock.patch.object(uuid, 'uuid4') + def test_delete_subscription_with_id_not_exists(self, mock_uuid4, mock_requests): + dummy_uuid = str(uuid.uuid4()) + response = self.client.delete("/api/vnfpkgm/v1/subscriptions/" + dummy_uuid) + self.assertEqual(404, response.status_code) diff --git a/catalog/packages/views/vnf_package_subscription_views.py b/catalog/packages/views/vnf_package_subscription_views.py index 24bcd4e4..70c9abc6 100755 --- a/catalog/packages/views/vnf_package_subscription_views.py +++ b/catalog/packages/views/vnf_package_subscription_views.py @@ -24,7 +24,7 @@ from rest_framework.response import Response from catalog.packages.serializers.vnf_pkg_subscription import PkgmSubscriptionRequestSerializer, \ PkgmSubscriptionSerializer, PkgmSubscriptionsSerializer from catalog.packages.serializers.response import ProblemDetailsSerializer -from catalog.packages.biz.vnf_pkg_subscription import CreateSubscription, QuerySubscription +from catalog.packages.biz.vnf_pkg_subscription import CreateSubscription, QuerySubscription, TerminateSubscription from catalog.packages.views.common import validate_data from catalog.pub.exceptions import VnfPkgDuplicateSubscriptionException, VnfPkgSubscriptionException, \ SubscriptionDoesNotExistsException @@ -134,3 +134,28 @@ class QueryTerminateSubscriptionView(APIView): problem_details_serializer = get_problem_details_serializer(status.HTTP_500_INTERNAL_SERVER_ERROR, traceback.format_exc()) return Response(data=problem_details_serializer.data, status=status.HTTP_500_INTERNAL_SERVER_ERROR) + + @swagger_auto_schema( + responses={ + status.HTTP_204_NO_CONTENT: "", + status.HTTP_404_NOT_FOUND: ProblemDetailsSerializer(), + status.HTTP_500_INTERNAL_SERVER_ERROR: ProblemDetailsSerializer() + } + ) + def delete(self, request, subscriptionId): + logger.debug("SubscribeNotification--get::> %s" % subscriptionId) + try: + TerminateSubscription().terminate(subscriptionId) + return Response(status=status.HTTP_204_NO_CONTENT) + except SubscriptionDoesNotExistsException as e: + logger.error(e.message) + logger.error(traceback.format_exc()) + problem_details_serializer = get_problem_details_serializer(status.HTTP_404_NOT_FOUND, + traceback.format_exc()) + return Response(data=problem_details_serializer.data, status=status.HTTP_404_NOT_FOUND) + except Exception as e: + logger.error(e.message) + logger.error(traceback.format_exc()) + problem_details_serializer = get_problem_details_serializer(status.HTTP_500_INTERNAL_SERVER_ERROR, + traceback.format_exc()) + return Response(data=problem_details_serializer.data, status=status.HTTP_500_INTERNAL_SERVER_ERROR) |