Manual update of pip requirements
[osm/N2VC.git] / n2vc / tests / unit / test_utils.py
index 3bab705..3896b2f 100644 (file)
 
 from unittest import TestCase
 
 
 from unittest import TestCase
 
-from n2vc.utils import Dict, EntityType, JujuStatusToOSM, N2VCDeploymentStatus, DB_DATA
+from n2vc.utils import (
+    Dict,
+    EntityType,
+    JujuStatusToOSM,
+    N2VCDeploymentStatus,
+    get_ee_id_components,
+)
 from juju.machine import Machine
 from juju.application import Application
 from juju.action import Action
 from juju.machine import Machine
 from juju.application import Application
 from juju.action import Action
@@ -40,14 +46,14 @@ class UtilsTest(TestCase):
     def test_juju_status_to_osm(self):
         tests = [
             {
     def test_juju_status_to_osm(self):
         tests = [
             {
-                "entity_type": EntityType.MACHINE,
+                "entity_type": "machine",
                 "status": [
                     {"juju": "pending", "osm": N2VCDeploymentStatus.PENDING},
                     {"juju": "started", "osm": N2VCDeploymentStatus.COMPLETED},
                 ],
             },
             {
                 "status": [
                     {"juju": "pending", "osm": N2VCDeploymentStatus.PENDING},
                     {"juju": "started", "osm": N2VCDeploymentStatus.COMPLETED},
                 ],
             },
             {
-                "entity_type": EntityType.APPLICATION,
+                "entity_type": "application",
                 "status": [
                     {"juju": "waiting", "osm": N2VCDeploymentStatus.RUNNING},
                     {"juju": "maintenance", "osm": N2VCDeploymentStatus.RUNNING},
                 "status": [
                     {"juju": "waiting", "osm": N2VCDeploymentStatus.RUNNING},
                     {"juju": "maintenance", "osm": N2VCDeploymentStatus.RUNNING},
@@ -57,7 +63,7 @@ class UtilsTest(TestCase):
                 ],
             },
             {
                 ],
             },
             {
-                "entity_type": EntityType.UNIT,
+                "entity_type": "unit",
                 "status": [
                     {"juju": "waiting", "osm": N2VCDeploymentStatus.RUNNING},
                     {"juju": "maintenance", "osm": N2VCDeploymentStatus.RUNNING},
                 "status": [
                     {"juju": "waiting", "osm": N2VCDeploymentStatus.RUNNING},
                     {"juju": "maintenance", "osm": N2VCDeploymentStatus.RUNNING},
@@ -67,7 +73,7 @@ class UtilsTest(TestCase):
                 ],
             },
             {
                 ],
             },
             {
-                "entity_type": EntityType.ACTION,
+                "entity_type": "action",
                 "status": [
                     {"juju": "running", "osm": N2VCDeploymentStatus.RUNNING},
                     {"juju": "completed", "osm": N2VCDeploymentStatus.COMPLETED},
                 "status": [
                     {"juju": "running", "osm": N2VCDeploymentStatus.RUNNING},
                     {"juju": "completed", "osm": N2VCDeploymentStatus.COMPLETED},
@@ -85,7 +91,16 @@ class UtilsTest(TestCase):
                 self.assertTrue(juju_status in JujuStatusToOSM[entity_type])
                 self.assertEqual(osm_status, JujuStatusToOSM[entity_type][juju_status])
 
                 self.assertTrue(juju_status in JujuStatusToOSM[entity_type])
                 self.assertEqual(osm_status, JujuStatusToOSM[entity_type][juju_status])
 
-    def test_db_data(self):
-        self.assertEqual(DB_DATA.api_endpoints.table, "admin")
-        self.assertEqual(DB_DATA.api_endpoints.filter, {"_id": "juju"})
-        self.assertEqual(DB_DATA.api_endpoints.key, "api_endpoints")
+
+class GetEEComponentTest(TestCase):
+    def test_valid(self):
+        model, application, machine = get_ee_id_components("model.application.machine")
+        self.assertEqual(model, "model")
+        self.assertEqual(application, "application")
+        self.assertEqual(machine, "machine")
+
+    def test_invalid(self):
+        with self.assertRaises(Exception):
+            get_ee_id_components("model.application.machine.1")
+        with self.assertRaises(Exception):
+            get_ee_id_components("model.application")