X-Git-Url: http://git.maemo.org/git/?p=theonering;a=blobdiff_plain;f=hand_tests%2Fgeneric.py;h=3d83a79e7d1630b1fc38b47490bb7c0abd1ac918;hp=ebd7f47afe15ec05f3c36305fdd96dc467c7ac48;hb=d1950514e9b001961190ca888913509c9bb3d999;hpb=c648e446ed0d6bd49a6bcdbea37b6e1bcff5fe16 diff --git a/hand_tests/generic.py b/hand_tests/generic.py index ebd7f47..3d83a79 100755 --- a/hand_tests/generic.py +++ b/hand_tests/generic.py @@ -35,6 +35,10 @@ class Action(object): assert self._action is None self._action = action + def get_next_action(self): + assert self._action is not None + return self._action + def _on_done(self): if self._action is None: return @@ -96,10 +100,10 @@ class DisplayParams(Action): super(DisplayParams, self)._on_done() -class Connect(Action): +class RequestConnection(Action): def __init__(self, cm, username, password, forward): - super(Connect, self).__init__() + super(RequestConnection, self).__init__() self._cm = cm self._conn = None @@ -121,22 +125,32 @@ class Connect(Action): self._cm[telepathy.server.CONNECTION_MANAGER].RequestConnection( 'sip', { - 'username': self._username, + 'account': self._username, 'password': self._password, 'forward': self._forward, }, - reply_handler = self._on_connection_requested, + reply_handler = self._on_done, error_handler = self._on_error, ) - def _on_connection_requested(self, busName, objectPath): + def _on_done(self, busName, objectPath): self._serviceName = busName self._conn = telepathy.client.Connection(busName, objectPath) - self._conn[telepathy.server.CONNECTION].connect_to_signal( + super(RequestConnection, self)._on_done() + + +class Connect(Action): + + def __init__(self, connAction): + super(Connect, self).__init__() + self._connAction = connAction + + def queue_action(self): + self._connAction.conn[telepathy.server.CONNECTION].connect_to_signal( 'StatusChanged', self._on_change, ) - self._conn[telepathy.server.CONNECTION].Connect( + self._connAction.conn[telepathy.server.CONNECTION].Connect( reply_handler = self._on_generic_message, error_handler = self._on_error, ) @@ -274,6 +288,68 @@ class RequestChannel(Action): super(RequestChannel, self)._on_done() +class EnsureChannel(Action): + + def __init__(self, connAction, channelType, handleType, handleId): + super(EnsureChannel, self).__init__() + self._connAction = connAction + self._channel = None + self._channelType = channelType + self._handleType = handleType + self._handleId = handleId + self._handle = None + + @property + def channel(self): + return self._channel + + @property + def handle(self): + return self._handle + + @property + def handles(self): + return [self._handle] + + def queue_action(self): + properties = { + telepathy.server.CHANNEL_INTERFACE+".ChannelType": self._channelType, + telepathy.server.CHANNEL_INTERFACE+".TargetHandleType": self._handleType, + telepathy.server.CHANNEL_INTERFACE+".TargetID": self._handleId, + } + self._connAction.conn[telepathy.server.CONNECTION_INTERFACE_REQUESTS].EnsureChannel( + properties, + reply_handler = self._on_done, + error_handler = self._on_error, + ) + + def _on_done(self, yours, channelObjectPath, properties): + print "Create?", not not yours + print "Path:", channelObjectPath + print "Properties:", properties + self._channel = telepathy.client.Channel(self._connAction.serviceName, channelObjectPath) + self._handle = properties[telepathy.server.CHANNEL_INTERFACE+".TargetHandle"] + super(EnsureChannel, self)._on_done() + + +class CloseChannel(Action): + + def __init__(self, connAction, chanAction): + super(CloseChannel, self).__init__() + self._connAction = connAction + self._chanAction = chanAction + self._handles = [] + + def queue_action(self): + self._chanAction.channel[telepathy.server.CHANNEL].Close( + reply_handler = self._on_done, + error_handler = self._on_error, + ) + + def _on_done(self): + super(CloseChannel, self)._on_done() + + class ContactHandles(Action): def __init__(self, connAction, chanAction): @@ -356,8 +432,8 @@ class Aliases(Action): def _on_done(self, aliases): print "\tAliases:" - for alias in aliases: - print "\t\t", alias + for h, alias in zip(self._handleAction.handles, aliases): + print "\t\t", h, alias super(Aliases, self)._on_done() @@ -456,77 +532,101 @@ if __name__ == '__main__': if True: dp = DisplayParams(cm) lastAction.append_action(dp) - lastAction = dp + lastAction = lastAction.get_next_action() if True: username = sys.argv[1] password = sys.argv[2] forward = sys.argv[3] - con = Connect(cm, username, password, forward) + reqcon = RequestConnection(cm, username, password, forward) + lastAction.append_action(reqcon) + lastAction = lastAction.get_next_action() + + if False: + reqcon = RequestConnection(cm, username, password, forward) + lastAction.append_action(reqcon) + lastAction = lastAction.get_next_action() + + con = Connect(reqcon) lastAction.append_action(con) - lastAction = con + lastAction = lastAction.get_next_action() if True: - spo = SimplePresenceOptions(con) + spo = SimplePresenceOptions(reqcon) lastAction.append_action(spo) - lastAction = spo + lastAction = lastAction.get_next_action() if True: - uh = UserHandle(con) + uh = UserHandle(reqcon) lastAction.append_action(uh) - lastAction = uh + lastAction = lastAction.get_next_action() - ua = Aliases(con, uh) + ua = Aliases(reqcon, uh) lastAction.append_action(ua) - lastAction = ua + lastAction = lastAction.get_next_action() - sps = SimplePresenceStatus(con, uh) + sps = SimplePresenceStatus(reqcon, uh) lastAction.append_action(sps) - lastAction = sps + lastAction = lastAction.get_next_action() if False: - setdnd = SetSimplePresence(con, "dnd", "") + setdnd = SetSimplePresence(reqcon, "dnd", "") lastAction.append_action(setdnd) - lastAction = setdnd + lastAction = lastAction.get_next_action() - sps = SimplePresenceStatus(con, uh) + sps = SimplePresenceStatus(reqcon, uh) lastAction.append_action(sps) - lastAction = sps + lastAction = lastAction.get_next_action() - setdnd = SetSimplePresence(con, "available", "") + setdnd = SetSimplePresence(reqcon, "available", "") lastAction.append_action(setdnd) - lastAction = setdnd + lastAction = lastAction.get_next_action() - sps = SimplePresenceStatus(con, uh) + sps = SimplePresenceStatus(reqcon, uh) lastAction.append_action(sps) - lastAction = sps + lastAction = lastAction.get_next_action() - if True: - rclh = RequestHandle(con, telepathy.HANDLE_TYPE_LIST, ["subscribe"]) + if False: + sl = Sleep(10 * 1000) + lastAction.append_action(sl) + lastAction = lastAction.get_next_action() + + if False: + rclh = RequestHandle(reqcon, telepathy.HANDLE_TYPE_LIST, ["subscribe"]) lastAction.append_action(rclh) - lastAction = rclh + lastAction = lastAction.get_next_action() rclc = RequestChannel( - con, + reqcon, rclh, telepathy.CHANNEL_TYPE_CONTACT_LIST, telepathy.HANDLE_TYPE_LIST, ) lastAction.append_action(rclc) - lastAction = rclc + lastAction = lastAction.get_next_action() - ch = ContactHandles(con, rclc) + ch = ContactHandles(reqcon, rclc) lastAction.append_action(ch) - lastAction = ch + lastAction = lastAction.get_next_action() - ca = Aliases(con, ch) + ca = Aliases(reqcon, ch) lastAction.append_action(ca) - lastAction = ca + lastAction = lastAction.get_next_action() + + if True: + accountNumber = sys.argv[4] + enChan = EnsureChannel(reqcon, telepathy.CHANNEL_TYPE_TEXT, telepathy.HANDLE_TYPE_CONTACT, accountNumber) + lastAction.append_action(enChan) + lastAction = lastAction.get_next_action() + + sendDebugtext = SendText(reqcon, enChan, enChan, telepathy.CHANNEL_TEXT_MESSAGE_TYPE_NORMAL, "Boo!") + lastAction.append_action(sendDebugtext) + lastAction = lastAction.get_next_action() if False: - rch = RequestHandle(con, telepathy.HANDLE_TYPE_CONTACT, ["18005558355"]) #(1-800-555-TELL) + rch = RequestHandle(reqcon, telepathy.HANDLE_TYPE_CONTACT, ["18005558355"]) #(1-800-555-TELL) lastAction.append_action(rch) - lastAction = rch + lastAction = lastAction.get_next_action() # making a phone call if True: @@ -536,51 +636,65 @@ if __name__ == '__main__': smHandle = nullHandle smHandleType = telepathy.HANDLE_TYPE_NONE rsmc = RequestChannel( - con, + reqcon, smHandle, telepathy.CHANNEL_TYPE_STREAMED_MEDIA, smHandleType, ) lastAction.append_action(rsmc) - lastAction = rsmc + lastAction = lastAction.get_next_action() if False: - call = Call(con, rsmc, rch) + call = Call(reqcon, rsmc, rch) lastAction.append_action(call) - lastAction = call + lastAction = lastAction.get_next_action() # sending a text rtc = RequestChannel( - con, + reqcon, rch, telepathy.CHANNEL_TYPE_TEXT, smHandleType, ) lastAction.append_action(rtc) - lastAction = rtc + lastAction = lastAction.get_next_action() + + if True: + closechan = CloseChannel(reqcon, rtc) + lastAction.append_action(closechan) + lastAction = lastAction.get_next_action() + + rtc = RequestChannel( + reqcon, + rch, + telepathy.CHANNEL_TYPE_TEXT, + smHandleType, + ) + lastAction.append_action(rtc) + lastAction = lastAction.get_next_action() if False: - sendtext = SendText(con, rtc, rch, telepathy.CHANNEL_TEXT_MESSAGE_TYPE_NORMAL, "Boo!") + sendtext = SendText(reqcon, rtc, rch, telepathy.CHANNEL_TEXT_MESSAGE_TYPE_NORMAL, "Boo!") lastAction.append_action(sendtext) - lastAction = sendtext + lastAction = lastAction.get_next_action() if False: bl = Block() lastAction.append_action(bl) - lastAction = bl + lastAction = lastAction.get_next_action() - if True: + if False: sl = Sleep(30 * 1000) lastAction.append_action(sl) - lastAction = sl + lastAction = lastAction.get_next_action() - dis = Disconnect(con) + dis = Disconnect(reqcon) lastAction.append_action(dis) - lastAction = dis + lastAction = lastAction.get_next_action() quitter = QuitLoop(loop) lastAction.append_action(quitter) - lastAction = quitter + lastAction = lastAction.get_next_action() firstAction.queue_action() loop.run()