Switch to SI95.
[ric-plt/lib/rmr.git] / src / bindings / rmr-python / rmr / rmr_mocks / rmr_mocks.py
index 6037e1f..b498511 100644 (file)
@@ -34,7 +34,7 @@ def rcv_mock_generator(msg_payload, msg_type, msg_state, jsonb, timeout=0):
         sbuf.contents.payload = payload
         sbuf.contents.len = len(payload)
         sbuf.contents.state = msg_state
-        if msg_state != 0:                # set something in transport state if 'error'
+        if msg_state != 0:  # set something in transport state if 'error'
             sbuf.contents.tp_state = 99
         else:
             sbuf.contents.tp_state = 0
@@ -52,7 +52,7 @@ def send_mock_generator(msg_state):
 
     def f(_unused, sbuf):
         sbuf.contents.state = msg_state
-        if msg_state != 0:                # set something in transport state if 'error'
+        if msg_state != 0:  # set something in transport state if 'error'
             sbuf.contents.tp_state = 99
         else:
             sbuf.contents.tp_state = 0
@@ -72,6 +72,7 @@ class _Sbuf_Contents:
         self.xaction = uuid.uuid1().hex.encode("utf-8")
         self.sub_id = 0
         self.tp_state = 0
+        self.meid = None
 
     def __str__(self):
         return str(
@@ -83,6 +84,7 @@ class _Sbuf_Contents:
                 "xaction": self.xaction,
                 "sub_id": self.sub_id,
                 "tp_state": self.tp_state,
+                "meid": self.meid,
             }
         )
 
@@ -99,8 +101,28 @@ def patch_rmr(monkeypatch):
     Patch rmr; requires a monkeypatch (pytest) object to be passed in
     """
 
-    def fake_alloc(_unused, _alsounused):
-        return Rmr_mbuf_t()
+    def fake_alloc(
+        _vctx, _sz, payload=None, gen_transaction_id=False, mtype=None, meid=None, sub_id=None, fixed_transaction_id=None
+    ):
+        sbuf = Rmr_mbuf_t()
+        if payload:
+            sbuf.contents.payload = payload
+
+        if fixed_transaction_id:
+            sbuf.contents.xaction = fixed_transaction_id
+        elif gen_transaction_id:
+            sbuf.contents.xaction = uuid.uuid1().hex.encode("utf-8")
+
+        if mtype:
+            sbuf.contents.mtype = mtype
+
+        if meid:
+            sbuf.contents.meid = meid
+
+        if sub_id:
+            sbuf.contents.sub_id = sub_id
+
+        return sbuf
 
     def fake_set_payload_and_length(payload, sbuf):
         sbuf.contents.payload = payload
@@ -112,8 +134,8 @@ def patch_rmr(monkeypatch):
     def fake_get_payload(sbuf):
         return sbuf.contents.payload
 
-    def fake_get_meid(_sbuf):
-        return None  # this is not a part of rmr_mbuf_t
+    def fake_get_meid(sbuf):
+        return sbuf.contents.meid
 
     def fake_get_src(_sbuf):
         return "localtest:80"  # this is not a part of rmr_mbuf_t
@@ -121,10 +143,14 @@ def patch_rmr(monkeypatch):
     def fake_rmr_payload_size(_sbuf):
         return 4096
 
+    def fake_free(_sbuf):
+        pass
+
+    monkeypatch.setattr("rmr.rmr.rmr_free_msg", fake_free)
     monkeypatch.setattr("rmr.rmr.rmr_alloc_msg", fake_alloc)
     monkeypatch.setattr("rmr.rmr.set_payload_and_length", fake_set_payload_and_length)
     monkeypatch.setattr("rmr.rmr.generate_and_set_transaction_id", fake_generate_and_set_transaction_id)
     monkeypatch.setattr("rmr.rmr.get_payload", fake_get_payload)
     monkeypatch.setattr("rmr.rmr.get_src", fake_get_src)
-    monkeypatch.setattr("rmr.rmr.get_meid", fake_get_meid)
+    monkeypatch.setattr("rmr.rmr.rmr_get_meid", fake_get_meid)
     monkeypatch.setattr("rmr.rmr.rmr_payload_size", fake_rmr_payload_size)