Implemented Retrieval of Policy instance status
[ric-plt/a1.git] / tests / test_controller.py
index 0601bbc..9a73ea8 100644 (file)
@@ -19,7 +19,7 @@ tests for controller
 # ==================================================================================
 import time
 import json
-from rmr.rmr_mocks import rmr_mocks
+from ricxappframe.rmr.rmr_mocks import rmr_mocks
 from ricxappframe.xapp_sdl import SDLWrapper
 from ricsdl.exceptions import RejectedByBackend, NotConnected, BackendError
 from a1 import a1rmr, data
@@ -89,7 +89,7 @@ def _fake_dequeue_deleted():
 def _test_put_patch(monkeypatch):
     rmr_mocks.patch_rmr(monkeypatch)
     # assert that rmr bad states don't cause problems
-    monkeypatch.setattr("rmr.rmr.rmr_send_msg", rmr_mocks.send_mock_generator(10))
+    monkeypatch.setattr("ricxappframe.rmr.rmr.rmr_send_msg", rmr_mocks.send_mock_generator(10))
 
 
 def _no_ac(client):
@@ -363,20 +363,31 @@ def test_bad_instances(client, monkeypatch, adm_type_good):
 
     monkeypatch.setattr("a1.data.SDL.set", monkey_set)
 
-    res = client.put("/a1-p/policytypes/111", json=adm_type_good)
-    assert res.status_code == 503
-    res = client.put("/a1-p/policytypes/112", json=adm_type_good)
-    assert res.status_code == 503
-    res = client.put("/a1-p/policytypes/113", json=adm_type_good)
-    assert res.status_code == 503
+    def create_alt_id(json, id):
+        """
+        Overwrites the json's policy type ID, attempts create and tests for 503
+        """
+        json['policy_type_id'] = id
+        url = "/a1-p/policytypes/{0}".format(id)
+        res = client.put(url, json=json)
+        assert res.status_code == 503
+
+    create_alt_id(adm_type_good, 111)
+    create_alt_id(adm_type_good, 112)
+    create_alt_id(adm_type_good, 113)
 
 
 def test_illegal_types(client, adm_type_good):
     """
     Test illegal types
     """
+    # below valid range
     res = client.put("/a1-p/policytypes/0", json=adm_type_good)
     assert res.status_code == 400
+    # ID mismatch
+    res = client.put("/a1-p/policytypes/1", json=adm_type_good)
+    assert res.status_code == 400
+    # above valid range
     res = client.put("/a1-p/policytypes/2147483648", json=adm_type_good)
     assert res.status_code == 400
 
@@ -389,6 +400,14 @@ def test_healthcheck(client):
     assert res.status_code == 200
 
 
+def test_metrics(client):
+    """
+    test Prometheus metrics
+    """
+    res = client.get("/a1-p/metrics")
+    assert res.status_code == 200
+
+
 def teardown_module():
     """module teardown"""
     a1rmr.stop_rmr_thread()