Get model names activity implementation

Change-Id: I4f80ad212b61ccc3f5d01e646cf74ecb7f31a5f2
Signed-off-by: Daniel Arndt <daniel.arndt@canonical.com>
diff --git a/osm_lcm/tests/test_vnf_activities.py b/osm_lcm/tests/test_vnf_activities.py
index 1f34563..374a648 100644
--- a/osm_lcm/tests/test_vnf_activities.py
+++ b/osm_lcm/tests/test_vnf_activities.py
@@ -24,6 +24,7 @@
 from osm_lcm.temporal.vnf_activities import (
     ChangeVnfInstantiationStateImpl,
     ChangeVnfStateImpl,
+    GetModelNamesImpl,
     GetTaskQueueImpl,
     GetVimCloudImpl,
     GetVnfDescriptorImpl,
@@ -42,7 +43,7 @@
 model_name = "my-model-name"
 set_vnf_model_input = SetVnfModelImpl.Input(vnfr_uuid=vnfr_uuid, model_name=model_name)
 cloud = "microk8s"
-nsr_uuid = "583726d4-957d-47f5-8df5-199456f7afd0"
+nsr_uuid = "dcf4c922-5a73-41bf-a6ca-870c22d6336c"
 sample_vim_record = {
     "_id": vim_uuid,
     "name": "juju",
@@ -64,7 +65,7 @@
 sample_vnfr = {
     "_id": vnfr_uuid,
     "id": vnfr_uuid,
-    "nsr-id-ref": "dcf4c922-5a73-41bf-a6ca-870c22d6336c",
+    "nsr-id-ref": nsr_uuid,
     "vnfd-ref": "jar_vnfd_scalable",
     "vnfd-id": "f1b38eac-190c-485d-9a74-c6e169c929d8",
     "vim-account-id": vim_account_id,
@@ -495,5 +496,38 @@
         self.assertEqual(result, {})
 
 
+class TestGetModelNames(asynctest.TestCase):
+    async def setUp(self):
+        self.db = Mock()
+        self.get_model_names = GetModelNamesImpl(self.db)
+        self.env = ActivityEnvironment()
+
+    async def test_activity__success(self):
+        # Two namespaces, one of them repeated
+        self.db.get_list.return_value = [
+            {
+                "nsr-id-ref": nsr_uuid,
+                "namespace": namespace,
+            }
+            for namespace in ["namespace1", "namespace1", "namespace2"]
+        ]
+
+        activity_result = await self.env.run(
+            self.get_model_names,
+            GetModelNamesImpl.Input(ns_uuid=nsr_uuid),
+        )
+
+        self.assertEqual(activity_result.model_names, {"namespace1", "namespace2"})
+
+    async def test_activity__raise_db_exception(self):
+        self.db.get_list.side_effect = DbException("Can not connect to Database.")
+
+        with self.assertRaises(DbException):
+            await self.env.run(
+                self.get_model_names,
+                GetModelNamesImpl.Input(ns_uuid=nsr_uuid),
+            )
+
+
 if __name__ == "__main__":
     asynctest.main()