From 0b0ee151c524532cb0cbd7d1905e517c61f50d63 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Sat, 12 Dec 2009 18:27:12 -0600 Subject: [PATCH] Adding coverage and fixing bugs --- hand_tests/generic.py | 145 +++++++++++++++++++++++++++++++++++++++++---- src/channel/call.py | 7 ++- src/channel_manager.py | 5 +- src/connection.py | 2 +- src/gvoice/addressbook.py | 1 - src/gvoice/session.py | 5 +- 6 files changed, 145 insertions(+), 20 deletions(-) diff --git a/hand_tests/generic.py b/hand_tests/generic.py index 16ad610..2b73759 100755 --- a/hand_tests/generic.py +++ b/hand_tests/generic.py @@ -9,6 +9,9 @@ dbus.mainloop.glib.DBusGMainLoop(set_as_default = True) import telepathy +DBUS_PROPERTIES = 'org.freedesktop.DBus.Properties' + + def get_registry(): reg = telepathy.client.ManagerRegistry() reg.LoadManagers() @@ -146,6 +149,38 @@ class Connect(Action): print "Status: %r" % status +class SimplePresenceOptions(Action): + + def __init__(self, connAction): + super(SimplePresenceOptions, self).__init__() + self._connAction = connAction + + def queue_action(self): + self._connAction.conn[DBUS_PROPERTIES].Get( + telepathy.server.CONNECTION_INTERFACE_SIMPLE_PRESENCE, + 'Statuses', + reply_handler = self._on_done, + error_handler = self._on_error, + ) + + def _on_done(self, statuses): + print "\tAvailable Statuses" + for (key, value) in statuses.iteritems(): + print "\t\t - %s" % key + super(SimplePresenceOptions, self)._on_done() + + +class NullHandle(object): + + @property + def handle(self): + return 0 + + @property + def handles(self): + return [] + + class UserHandle(Action): def __init__(self, connAction): @@ -172,12 +207,14 @@ class UserHandle(Action): super(UserHandle, self)._on_done() -class RequestContactListHandle(Action): +class RequestHandle(Action): - def __init__(self, connAction): - super(RequestContactListHandle, self).__init__() + def __init__(self, connAction, handleType, handleNames): + super(RequestHandle, self).__init__() self._connAction = connAction self._handle = None + self._handleType = handleType + self._handleNames = handleNames @property def handle(self): @@ -188,31 +225,45 @@ class RequestContactListHandle(Action): return [self._handle] def queue_action(self): - pass + self._connAction.conn[telepathy.server.CONNECTION].RequestHandles( + self._handleType, + self._handleNames, + reply_handler = self._on_done, + error_handler = self._on_error, + ) def _on_done(self, handles): self._handle = handles[0] - super(RequestContactListHandle, self)._on_done() + super(RequestHandle, self)._on_done() -class RequestContactListChannel(Action): +class RequestChannel(Action): - def __init__(self, connAction, handleAction): - super(RequestContactListChannel, self).__init__() + def __init__(self, connAction, handleAction, channelType, handleType): + super(RequestChannel, self).__init__() self._connAction = connAction self._handleAction = handleAction self._channel = None + self._channelType = channelType + self._handleType = handleType @property def channel(self): return self._channel def queue_action(self): - pass + self._connAction.conn[telepathy.server.CONNECTION].RequestChannel( + self._channelType, + self._handleType, + self._handleAction.handle, + True, + reply_handler = self._on_done, + error_handler = self._on_error, + ) - def _on_done(self, channel): - self._channel = channel - super(RequestContactListChannel, self)._on_done() + def _on_done(self, channelObjectPath): + self._channel = channelObjectPath + super(RequestChannel, self)._on_done() class ContactHandles(Action): @@ -233,6 +284,27 @@ class ContactHandles(Action): super(UserHandle, self)._on_done() +class SimplePresenceStatus(Action): + + def __init__(self, connAction, handleAction): + super(SimplePresenceStatus, self).__init__() + self._connAction = connAction + self._handleAction = handleAction + + def queue_action(self): + self._connAction.conn[telepathy.server.CONNECTION_INTERFACE_SIMPLE_PRESENCE].GetPresences( + self._handleAction.handles, + reply_handler = self._on_done, + error_handler = self._on_error, + ) + + def _on_done(self, aliases): + print "\tPresences:" + for hid, (presenceType, presence, presenceMessage) in aliases.iteritems(): + print "\t\t%s:" % hid, presenceType, presence, presenceMessage + super(SimplePresenceStatus, self)._on_done() + + class Aliases(Action): def __init__(self, connAction, handleAction): @@ -273,6 +345,8 @@ if __name__ == '__main__': reg = get_registry() cm = get_connection_manager(reg) + nullHandle = NullHandle() + dummy = DummyAction() firstAction = dummy lastAction = dummy @@ -291,6 +365,11 @@ if __name__ == '__main__': lastAction = con if True: + spo = SimplePresenceOptions(con) + lastAction.append_action(spo) + lastAction = spo + + if True: uh = UserHandle(con) lastAction.append_action(uh) lastAction = uh @@ -299,6 +378,48 @@ if __name__ == '__main__': lastAction.append_action(ua) lastAction = ua + sps = SimplePresenceStatus(con, uh) + lastAction.append_action(sps) + lastAction = sps + + if True: + rclh = RequestHandle(con, telepathy.HANDLE_TYPE_LIST, ["subscribe"]) + lastAction.append_action(rclh) + lastAction = rclh + + rclc = RequestChannel( + con, + rclh, + telepathy.CHANNEL_TYPE_CONTACT_LIST, + telepathy.HANDLE_TYPE_LIST, + ) + lastAction.append_action(rclc) + lastAction = rclc + + # @todo get aliases for contacts + + if True: + rch = RequestHandle(con, telepathy.HANDLE_TYPE_CONTACT, ["18005558355"]) #(1-800-555-TELL) + lastAction.append_action(rch) + lastAction = rch + + if True: + smHandle = rch + smHandleType = telepathy.HANDLE_TYPE_CONTACT + else: + smHandle = nullHandle + smHandleType = telepathy.HANDLE_TYPE_NONE + rsmc = RequestChannel( + con, + smHandle, + telepathy.CHANNEL_TYPE_STREAMED_MEDIA, + smHandleType, + ) + lastAction.append_action(rsmc) + lastAction = rsmc + + # @todo call contact + dis = Disconnect(con) lastAction.append_action(dis) lastAction = dis diff --git a/src/channel/call.py b/src/channel/call.py index fd6cb94..0d3373f 100644 --- a/src/channel/call.py +++ b/src/channel/call.py @@ -15,10 +15,10 @@ class CallChannel( telepathy.server.ChannelInterfaceCallState, ): - def __init__(self, connection): + def __init__(self, connection, contactHandle): telepathy.server.ChannelTypeStreamedMedia.__init__(self, connection, None) - telepathy.server.ChannelInterfaceGroup.__init__(self) - telepathy.server.ChannelInterfaceChatState.__init__(self) + telepathy.server.ChannelInterfaceCallState.__init__(self) + self._contactHandle = contactHandle @gtk_toolbox.log_exception(_moduleLogger) def ListStreams(self): @@ -55,6 +55,7 @@ class CallChannel( if streamType != telepathy.constants.MEDIA_STREAM_TYPE_AUDIO: raise telepathy.errors.NotImplemented("Audio is the only stream type supported") + print self._contactHandle, contact contactId, contactNumber = handle.ContactHandle.from_handle_name(contact.name) self._conn.session.backend.call(contactNumber) diff --git a/src/channel_manager.py b/src/channel_manager.py index 2331063..906744a 100644 --- a/src/channel_manager.py +++ b/src/channel_manager.py @@ -55,8 +55,9 @@ class ChannelManager(object): try: chan = self._callChannels[handle] except KeyError, e: - if handle.get_type() != telepathy.HANDLE_TYPE_NONE: - raise telepathy.errors.NotImplemented("Using deprecated means to create a call") + if handle.get_type() != telepathy.HANDLE_TYPE_CONTACT: + _moduleLogger.warning("Using deprecated means to create a call") + raise telepathy.errors.NotImplemented("Not implementing depcrecated means") _moduleLogger.debug("Requesting new call channel") chan = channel.call.CallChannel(self._connRef(), handle) diff --git a/src/connection.py b/src/connection.py index 3e90f30..139e63d 100644 --- a/src/connection.py +++ b/src/connection.py @@ -125,8 +125,8 @@ class TheOneRingConnection( """ _moduleLogger.info("Disconnecting") try: - self.session.logout() self._channelManager.close() + self.session.logout() _moduleLogger.info("Disconnected") except Exception: _moduleLogger.exception("Disconnecting Failed") diff --git a/src/gvoice/addressbook.py b/src/gvoice/addressbook.py index a3f9bac..4684ed1 100644 --- a/src/gvoice/addressbook.py +++ b/src/gvoice/addressbook.py @@ -19,7 +19,6 @@ class Addressbook(object): self._changedContacts = set() self.updateSignalHandler = coroutines.CoTee() - self.update() def update(self, force=False): if not force and self._contacts: diff --git a/src/gvoice/session.py b/src/gvoice/session.py index df96546..35157d9 100644 --- a/src/gvoice/session.py +++ b/src/gvoice/session.py @@ -36,17 +36,20 @@ class Session(object): def is_logged_in(self): if self._backend is None: + _moduleLogger.info("No Backend") return False elif self._backend.is_authed(): return True else: try: loggedIn = self._backend.login(self._username, self._password) - except RuntimeError: + except RuntimeError, e: + _moduleLogger.exception("Re-authenticating and erroring") loggedIn = False if loggedIn: return True else: + _moduleLogger.info("Login failed") self.logout() return False -- 1.7.9.5