1 # Copyright 2020 Canonical Ltd.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 from unittest
import TestCase
17 from n2vc
.utils
import Dict
, EntityType
, JujuStatusToOSM
, N2VCDeploymentStatus
, DB_DATA
18 from juju
.machine
import Machine
19 from juju
.application
import Application
20 from juju
.action
import Action
21 from juju
.unit
import Unit
24 class UtilsTest(TestCase
):
26 example
= Dict({"key": "value"})
27 self
.assertEqual(example
["key"], example
.key
)
29 def test_entity_type(self
):
30 self
.assertFalse(EntityType
.has_value("machine2"))
31 values
= [Machine
, Application
, Action
, Unit
]
33 self
.assertTrue(EntityType
.has_value(value
))
35 self
.assertEqual(EntityType
.MACHINE
, EntityType
.get_entity(Machine
))
36 self
.assertEqual(EntityType
.APPLICATION
, EntityType
.get_entity(Application
))
37 self
.assertEqual(EntityType
.UNIT
, EntityType
.get_entity(Unit
))
38 self
.assertEqual(EntityType
.ACTION
, EntityType
.get_entity(Action
))
40 def test_juju_status_to_osm(self
):
43 "entity_type": "machine",
45 {"juju": "pending", "osm": N2VCDeploymentStatus
.PENDING
},
46 {"juju": "started", "osm": N2VCDeploymentStatus
.COMPLETED
},
50 "entity_type": "application",
52 {"juju": "waiting", "osm": N2VCDeploymentStatus
.RUNNING
},
53 {"juju": "maintenance", "osm": N2VCDeploymentStatus
.RUNNING
},
54 {"juju": "blocked", "osm": N2VCDeploymentStatus
.RUNNING
},
55 {"juju": "error", "osm": N2VCDeploymentStatus
.FAILED
},
56 {"juju": "active", "osm": N2VCDeploymentStatus
.COMPLETED
},
60 "entity_type": "unit",
62 {"juju": "waiting", "osm": N2VCDeploymentStatus
.RUNNING
},
63 {"juju": "maintenance", "osm": N2VCDeploymentStatus
.RUNNING
},
64 {"juju": "blocked", "osm": N2VCDeploymentStatus
.RUNNING
},
65 {"juju": "error", "osm": N2VCDeploymentStatus
.FAILED
},
66 {"juju": "active", "osm": N2VCDeploymentStatus
.COMPLETED
},
70 "entity_type": "action",
72 {"juju": "running", "osm": N2VCDeploymentStatus
.RUNNING
},
73 {"juju": "completed", "osm": N2VCDeploymentStatus
.COMPLETED
},
79 entity_type
= test
["entity_type"]
80 self
.assertTrue(entity_type
in JujuStatusToOSM
)
82 for status
in test
["status"]:
83 juju_status
= status
["juju"]
84 osm_status
= status
["osm"]
85 self
.assertTrue(juju_status
in JujuStatusToOSM
[entity_type
])
86 self
.assertEqual(osm_status
, JujuStatusToOSM
[entity_type
][juju_status
])
88 def test_db_data(self
):
89 self
.assertEqual(DB_DATA
.api_endpoints
.table
, "admin")
90 self
.assertEqual(DB_DATA
.api_endpoints
.filter, {"_id": "juju"})
91 self
.assertEqual(DB_DATA
.api_endpoints
.key
, "api_endpoints")