Exemplo n.º 1
0
 def test_auto_deactivate(self):
     RemoteControlManager.activate(UID, CID_SRC, CID_DEST)
     self.wait_expiry_lock()
     self.assertIsNone(
         RemoteControlManager.get_current(UID, CID_SRC,
                                          update_expiry=False),
         "Entry still inside the holder.")
Exemplo n.º 2
0
def remote_control_status(e: TextMessageEventObject):
    current = RemoteControlManager.get_current(e.user_model.id,
                                               e.channel_model_source.id,
                                               update_expiry=False)

    if current:
        cnl = current.target_channel
        if not cnl:
            RemoteControlManager.deactivate(e.user_model.id,
                                            e.channel_model_source.id)
            return [
                HandledMessageEventText(content=_(
                    "Target channel data not found. Terminating remote control.\n"
                    "Target Channel ID: `{}`").format(
                        current.target_channel_oid))
            ]
        else:
            return [
                HandledMessageEventText(
                    content=_("Remote control is activated.\n"
                              "Target Channel ID: `{}`\n"
                              "Target Channel Platform & Name: *{} / {}*\n"
                              "Will be deactivated at `{}`.").format(
                                  cnl.id, cnl.platform.key,
                                  cnl.get_channel_name(e.user_model.id),
                                  current.expiry_str))
            ]
    else:
        return [
            HandledMessageEventText(
                content=_("Remote control is not activated."))
        ]
Exemplo n.º 3
0
    def __init__(
            self, raw: Any, content: Any, channel_model: ChannelModel = None,
            user_model: Optional[RootUserModel] = None,
            sys_ctype: SysChannelType = None, ch_parent_model: ChannelCollectionModel = None):
        src_ch = None

        rmc = None
        if user_model:
            rmc = RemoteControlManager.get_current(user_model.id, channel_model.id)

        if rmc:
            src_ch = channel_model
            channel_model = rmc.target_channel

        super().__init__(raw, channel_model, sys_ctype, source_channel=src_ch)
        self.content = content
        self.user_model = user_model
        self.chcoll_model = ch_parent_model
Exemplo n.º 4
0
def remote_control_deactivate(e: TextMessageEventObject):
    if RemoteControlManager.deactivate(e.user_model.id,
                                       e.channel_model_source.id):
        return [
            HandledMessageEventText(content=_("Remote control deactivated."))
        ]
    else:
        if RemoteControlManager.get_current(e.user_model.id,
                                            e.channel_model_source.id,
                                            update_expiry=False):
            return [
                HandledMessageEventText(
                    content=_("Remote control failed to delete."))
            ]
        else:
            return [
                HandledMessageEventText(
                    content=_("Remote control not activated."))
            ]
Exemplo n.º 5
0
    def test_get_current_not_update_expiry(self):
        # Storing the expiry timestamp before the actual one is created
        # to reduce the time offset caused ny db-app comm lag
        expiry_expected = datetime.utcnow().replace(
            tzinfo=timezone.utc) + timedelta(seconds=EXPIRY_SEC)
        activate_sec = exec_timing_result(RemoteControlManager.activate, UID,
                                          CID_SRC,
                                          CID_DEST).execution_ms / 1000

        self.sleep_lock()

        expiry_unexpected = datetime.utcnow().replace(
            tzinfo=timezone.utc) + timedelta(seconds=EXPIRY_SEC)
        entry = RemoteControlManager.get_current(UID,
                                                 CID_SRC,
                                                 update_expiry=False)

        self.assertIsNotNone(entry, "Entry not found in the holder.")
        self.assertEqual(CID_DEST, entry.target_channel_oid,
                         "Target channel not match.")
        self.assertTimeDifferenceLessEqual(expiry_expected, entry.expiry,
                                           activate_sec)
        self.assertTimeDifferenceGreaterEqual(expiry_unexpected, entry.expiry,
                                              SLEEP_SEC)