Fixes and enhancements:
[ric-plt/xapp-frame-py.git] / tests / test_xapp.py
index 97448af..def7904 100644 (file)
 #   See the License for the specific language governing permissions and
 #   limitations under the License.
 # ==================================================================================
+import pytest
+from rmr.exceptions import InitFailed
 from ricxappframe.xapp_frame import Xapp
 
 gen_xapp = None
 rmr_xapp = None
 
 
+def test_bad_gen_xapp():
+    """test that an xapp that does not implement entrypoint blows up"""
+
+    class MyXapp(Xapp):
+        def post_init(self):
+            pass
+
+    with pytest.raises(NotImplementedError):
+        # missing entrypoint
+        bad_xapp = MyXapp(rmr_wait_for_ready=False, use_fake_sdl=True)
+        bad_xapp.run()
+
+
+def test_bad_init():
+    """test that an xapp whose rmr fails to init blows up"""
+
+    class MyXapp(Xapp):
+        def entrypoint(self):
+            pass
+
+    with pytest.raises(InitFailed):
+        bad_xapp = MyXapp(rmr_port=-1)
+        bad_xapp.run()  # we wont get here
+
+
 def test_init_general_xapp():
     class MyXapp(Xapp):
-        # TODO: obviouslly a lot more is needed here. For now this tests that the class is instantiable.
-        def loop(self):
-            print("ok")
+        def post_init(self):
+            self.sdl_set("testns", "mykey", 6)
+
+        def entrypoint(self):
+            assert self.sdl_get("testns", "mykey") == 6
+            assert self.sdl_find_and_get("testns", "myk") == {"mykey": 6}
+            assert self.healthcheck()
+            # normally we would have some kind of loop here
+            print("bye")
 
     global gen_xapp
-    gen_xapp = MyXapp(rmr_wait_for_ready=False)
+    gen_xapp = MyXapp(rmr_wait_for_ready=False, use_fake_sdl=True)
     gen_xapp.run()