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 test_activate(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)
        entry = RemoteControlManager.activate(UID, CID_SRC, CID_DEST)

        self.assertIsNotNone(entry, "Activation returned `None`")
        self.assertEqual(CID_DEST, entry.target_channel_oid,
                         "Target channel not match.")
        self.assertTimeDifferenceLessEqual(entry.expiry, expiry_expected, 0.05)
Exemplo n.º 3
0
    def test_get_current_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_unexpected = datetime.utcnow().replace(
            tzinfo=timezone.utc) + timedelta(seconds=EXPIRY_SEC)
        RemoteControlManager.activate(UID, CID_SRC, CID_DEST)

        self.sleep_lock()

        expiry_expected = datetime.utcnow().replace(
            tzinfo=timezone.utc) + timedelta(seconds=EXPIRY_SEC)
        get_current = exec_timing_result(RemoteControlManager.get_current, UID,
                                         CID_SRC)
        entry = get_current.return_

        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,
                                           get_current.execution_ms / 1000)
        self.assertTimeDifferenceGreaterEqual(expiry_unexpected, entry.expiry,
                                              SLEEP_SEC)
Exemplo n.º 4
0
def remote_control_activate(e: TextMessageEventObject,
                            target_channel: ObjectId):
    entry = RemoteControlManager.activate(
        e.user_model.id, e.channel_model_source.id, target_channel,
        e.user_model.config.get_locale_code())

    if entry.target_channel:
        return [
            HandledMessageEventText(content=_("Remote control activated."))
        ]
    else:
        RemoteControlManager.deactivate(e.user_model.id,
                                        e.channel_model_source.id)
        return [
            HandledMessageEventText(content=_(
                "Target channel not found. Failed to activate remote control.")
                                    )
        ]