diff options
-rw-r--r-- | catalog/packages/tests/const.py | 42 | ||||
-rw-r--r-- | catalog/packages/tests/test_vnf_pkg_subscription.py | 142 |
2 files changed, 116 insertions, 68 deletions
diff --git a/catalog/packages/tests/const.py b/catalog/packages/tests/const.py index 619b4a72..a98ccb69 100644 --- a/catalog/packages/tests/const.py +++ b/catalog/packages/tests/const.py @@ -552,3 +552,45 @@ sd_data = { "name": "Enhance_Service" } } + +vnf_subscription_data = { + "filters": { + "notificationTypes": [ + "VnfPackageOnboardingNotification" + ], + "vnfProductsFromProviders": { + "vnfProvider": "string", + "vnfProducts": { + "vnfProductName": "string", + "versions": { + "vnfSoftwareVersion": "string", + "vnfdVersions": [ + "string" + ] + } + } + }, + "vnfdId": [ + "3fa85f64-5717-4562-b3fc-2c963f66afa6" + ], + "vnfPkgId": [ + "3fa85f64-5717-4562-b3fc-2c963f66afa6" + ], + "operationalState": [ + "ENABLED" + ], + "usageState": [ + "IN_USE" + ] + }, + "callbackUri": "http://www.vnf1.com/notification", + "authentication": { + "authType": [ + "BASIC" + ], + "paramsBasic": { + "userName": "string", + "password": "string" + } + } +} diff --git a/catalog/packages/tests/test_vnf_pkg_subscription.py b/catalog/packages/tests/test_vnf_pkg_subscription.py index 9a21c1e3..635b1372 100644 --- a/catalog/packages/tests/test_vnf_pkg_subscription.py +++ b/catalog/packages/tests/test_vnf_pkg_subscription.py @@ -14,56 +14,19 @@ import uuid import mock + from rest_framework.test import APIClient from django.test import TestCase + from catalog.pub.database.models import VnfPkgSubscriptionModel +from .const import vnf_subscription_data class TestNfPackageSubscription(TestCase): def setUp(self): self.client = APIClient() VnfPkgSubscriptionModel.objects.filter().delete() - self.vnf_subscription_data = { - "filters": { - "notificationTypes": [ - "VnfPackageOnboardingNotification" - ], - "vnfProductsFromProviders": { - "vnfProvider": "string", - "vnfProducts": { - "vnfProductName": "string", - "versions": { - "vnfSoftwareVersion": "string", - "vnfdVersions": [ - "string" - ] - } - } - }, - "vnfdId": [ - "3fa85f64-5717-4562-b3fc-2c963f66afa6" - ], - "vnfPkgId": [ - "3fa85f64-5717-4562-b3fc-2c963f66afa6" - ], - "operationalState": [ - "ENABLED" - ], - "usageState": [ - "IN_USE" - ] - }, - "callbackUri": "http://www.vnf1.com/notification", - "authentication": { - "authType": [ - "BASIC" - ], - "paramsBasic": { - "userName": "string", - "password": "string" - } - } - } + self.vnf_subscription_data = vnf_subscription_data def tearDown(self): pass @@ -75,9 +38,16 @@ class TestNfPackageSubscription(TestCase): mock_requests.return_value.status_code = 204 mock_requests.get.status_code = 204 mock_uuid4.return_value = temp_uuid - response = self.client.post("/api/vnfpkgm/v1/subscriptions", data=self.vnf_subscription_data, format='json') + response = self.client.post( + "/api/vnfpkgm/v1/subscriptions", + data=self.vnf_subscription_data, + format='json' + ) self.assertEqual(201, response.status_code) - self.assertEqual(self.vnf_subscription_data["callbackUri"], response.data["callbackUri"]) + self.assertEqual( + self.vnf_subscription_data["callbackUri"], + response.data["callbackUri"] + ) self.assertEqual(temp_uuid, response.data["id"]) @mock.patch("requests.get") @@ -88,15 +58,26 @@ class TestNfPackageSubscription(TestCase): mock_requests.return_value.status_code = 204 mock_requests.get.status_code = 204 mock_uuid4.side_effect = [temp_uuid, temp1_uuid] - response = self.client.post("/api/vnfpkgm/v1/subscriptions", data=self.vnf_subscription_data, format='json') + response = self.client.post( + "/api/vnfpkgm/v1/subscriptions", + data=self.vnf_subscription_data, + format='json' + ) self.assertEqual(201, response.status_code) - self.assertEqual(self.vnf_subscription_data["callbackUri"], response.data["callbackUri"]) + self.assertEqual( + self.vnf_subscription_data["callbackUri"], + response.data["callbackUri"] + ) self.assertEqual(temp_uuid, response.data["id"]) temp_uuid = "00442b18-a5c7-11e8-998c-bf1755941f12" mock_requests.return_value.status_code = 204 mock_requests.get.status_code = 204 mock_uuid4.return_value = temp_uuid - response = self.client.post("/api/vnfpkgm/v1/subscriptions", data=self.vnf_subscription_data, format='json') + response = self.client.post( + "/api/vnfpkgm/v1/subscriptions", + data=self.vnf_subscription_data, + format='json' + ) self.assertEqual(303, response.status_code) @mock.patch("requests.get") @@ -106,10 +87,15 @@ class TestNfPackageSubscription(TestCase): 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') - response = self.client.get("/api/vnfpkgm/v1/subscriptions?usageState=IN_USE", - format='json') + self.client.post( + "/api/vnfpkgm/v1/subscriptions", + data=self.vnf_subscription_data, + format='json' + ) + response = self.client.get( + "/api/vnfpkgm/v1/subscriptions?usageState=IN_USE", + format='json' + ) self.assertEqual(200, response.status_code) self.assertEqual(1, len(response.data)) @@ -120,10 +106,15 @@ class TestNfPackageSubscription(TestCase): 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') - response = self.client.get("/api/vnfpkgm/v1/subscriptions?dummy=dummy", - format='json') + self.client.post( + "/api/vnfpkgm/v1/subscriptions", + data=self.vnf_subscription_data, + format='json' + ) + response = self.client.get( + "/api/vnfpkgm/v1/subscriptions?dummy=dummy", + format='json' + ) self.assertEqual(400, response.status_code) @mock.patch("requests.get") @@ -133,10 +124,15 @@ class TestNfPackageSubscription(TestCase): 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') - response = self.client.get("/api/vnfpkgm/v1/subscriptions/" + temp_uuid, - format='json') + self.client.post( + "/api/vnfpkgm/v1/subscriptions", + data=self.vnf_subscription_data, + format='json' + ) + response = self.client.get( + "/api/vnfpkgm/v1/subscriptions/%s" % temp_uuid, + format='json' + ) self.assertEqual(200, response.status_code) self.assertEqual(temp_uuid, response.data["id"]) @@ -148,10 +144,15 @@ class TestNfPackageSubscription(TestCase): 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') - response = self.client.get("/api/vnfpkgm/v1/subscriptions/" + dummy_uuid, - format='json') + self.client.post( + "/api/vnfpkgm/v1/subscriptions", + data=self.vnf_subscription_data, + format='json' + ) + response = self.client.get( + "/api/vnfpkgm/v1/subscriptions/%s" % dummy_uuid, + format='json' + ) self.assertEqual(404, response.status_code) @mock.patch("requests.get") @@ -162,16 +163,21 @@ class TestNfPackageSubscription(TestCase): 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.client.post( + "/api/vnfpkgm/v1/subscriptions", + data=self.vnf_subscription_data, + format='json' + ) + self.client.get( + "/api/vnfpkgm/v1/subscriptions/%s" % dummy_uuid, + format='json' + ) + response = self.client.delete("/api/vnfpkgm/v1/subscriptions/%s" % 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) + response = self.client.delete("/api/vnfpkgm/v1/subscriptions/%s" % dummy_uuid) self.assertEqual(404, response.status_code) |