def testsignal_resp_handler_remote_action(self): """ Test to check the handling remote action method with a response of the signal class. """ sig_dict, signal = self.setup_vars_mocks() cbt = CBT() cbt.request.params = {"RecipientId": "1", "OverlayId": "A0FB389"} jid_cache = JidCache(signal, 5) jid_cache.add_entry("1", "2345") transport = XmppTransport.factory( "1", sig_dict["Signal"]["Overlays"]["A0FB389"], signal, signal._presence_publisher, None, None) transport.send_msg = MagicMock() signal._circles = { "A0FB389": { "JidCache": jid_cache, "Transport": transport } } cbt.tag = "1" signal.submit_cbt(cbt) resp = CBT.Response() cbt.response = resp rem_act = {"InitiatorId": "1", "OverlayId": "A0FB389"} signal._remote_acts["1"] = rem_act signal.submit_cbt(cbt) signal.transmit_remote_act = MagicMock() signal.free_cbt = MagicMock() signal.resp_handler_remote_action(cbt) signal.transmit_remote_act.assert_called_once() signal.free_cbt.assert_called_once() print("Passed : testsignal_resp_handler_remote_action")
def testsignal_scavenge_pending_cbts(self): """ Test to check if scavenge of pending CBT works with one above the request timeout. """ cfxObject = Mock() cfx_handle = CFxHandle(cfxObject) module = importlib.import_module("modules.{0}".format("Signal")) module_class = getattr(module, "Signal") sig_dict = { "Signal": { "Enabled": True, "Overlays": { "A0FB389": { "HostAddress": "1.1.1.1", "Port": "5222", "Username": "******", "Password": "******", "AuthenticationMethod": "PASSWORD" } } }, "NodeId": "1234434323" } signal = module_class(cfx_handle, sig_dict, "Signal") cfx_handle._cm_instance = signal cfx_handle._cm_config = sig_dict cbt1 = CBT() cbt1.tag = "1" cbt1.time_submit = time.time() - 5 signal.request_timeout = 5 cbt2 = CBT() cbt2.tag = "2" cbt2.time_submit = time.time() - 1 signal.complete_cbt = MagicMock() signal._cfx_handle._pending_cbts.update({"0": cbt1}) signal._cfx_handle._pending_cbts.update({"1": cbt2}) assert len(signal._cfx_handle._pending_cbts.items()) == 2 signal.scavenge_pending_cbts() assert len(signal._cfx_handle._pending_cbts.items()) == 1 items = {} items.update({"1": cbt2}) assert signal._cfx_handle._pending_cbts == items print("Passed : testsignal_scavenge_pending_cbts")
def testsignal_process_cbt_resp_tag_present(self): """ Test to check the process cbt method with a response with the cbt tag present. """ sig_dict, signal = self.setup_vars_mocks() signal._remote_acts = {"1"} signal.resp_handler_remote_action = MagicMock() cbt = CBT() cbt.op_type = "Response" cbt.tag = "1" signal.process_cbt(cbt) signal.resp_handler_remote_action.assert_called_once() print("Passed : testprocess_cbt_resp_tag_present")