[DCAEGEN-2] Added Junit for nfFilter schema validation 41/118541/3
authorajay_dp001 <ajay.deep.singh@est.tech>
Thu, 25 Feb 2021 16:58:58 +0000 (22:28 +0530)
committerajay_dp001 <ajay.deep.singh@est.tech>
Fri, 12 Mar 2021 14:09:42 +0000 (19:39 +0530)
Issue-ID: DCAEGEN2-2637
Signed-off-by: ajay_dp001 <ajay.deep.singh@est.tech>
Change-Id: I52192460e4f68f6ef7661e81487dcdd9fc286562

components/pm-subscription-handler/pmsh_service/mod/pmsh_utils.py
components/pm-subscription-handler/tests/test_pmsh_utils.py

index 7b91a30..a5fc86e 100755 (executable)
@@ -128,10 +128,7 @@ class AppConfig:
         sub_data = self.subscription.__dict__
         validate(instance=sub_data, schema=self.sub_schema)
         nf_filter = sub_data["nfFilter"]
-        for filter_name in nf_filter:
-            if len(nf_filter[filter_name]) > 0:
-                break
-        else:
+        if not [filter_name for filter_name, val in nf_filter.items() if len(val) > 0]:
             raise ValidationError("At least one filter within nfFilter must not be empty")
         logger.debug("Subscription schema is valid.")
 
index 1711e01..53d4fe6 100644 (file)
@@ -165,6 +165,44 @@ class PmshUtilsTestCase(BaseClassSetup):
         with self.assertRaises(ValidationError):
             self.app_conf.validate_sub_schema()
 
+    def test_utils_validate_config_subscription_nfFilter_not_empty(self):
+        self.app_conf.subscription.nfFilter = {
+            "nfNames": [
+
+            ],
+            "modelInvariantIDs": [
+
+            ],
+            "modelVersionIDs": [
+
+            ],
+            "modelNames": [
+
+            ]
+        }
+        with self.assertRaises(ValidationError):
+            self.app_conf.validate_sub_schema()
+
+    @patch('mod.logger.debug')
+    def test_utils_validate_config_subscription_nfFilter_with_empty_property(self, mock_logger):
+        self.app_conf.subscription.nfFilter = {
+            "nfNames": [
+                "^pnf.*",
+                "^vnf.*"
+            ],
+            "modelInvariantIDs": [
+                "7129e420-d396-4efb-af02-6b83499b12f8"
+            ],
+            "modelVersionIDs": [
+
+            ],
+            "modelNames": [
+                "pnf102"
+            ]
+        }
+        self.app_conf.validate_sub_schema()
+        mock_logger.assert_called_with("Subscription schema is valid.")
+
     def test_utils_validate_config_subscription_where_measurementTypes_is_empty(self):
         self.app_conf.subscription.measurementGroups = [{
             "measurementGroup": {