29
29
from twisted.internet import defer, reactor
30
30
from twisted.python import failure
32
from ubuntu_sso.main import SSOCredentials
34
32
from contrib.testing.testcase import (
35
33
BaseTwistedTestCase, FakeMain, FAKED_CREDENTIALS)
76
74
from ubuntuone.devtools.testcase import DBusTestCase
80
class FakeLoginProcessor(object):
81
"""Stub login processor."""
83
def __init__(self, dbus_object):
84
"""Initialize the login processor."""
85
self.next_login_cb = None
87
def login(self, realm, consumer_key, error_handler=None,
88
reply_handler=None, do_login=True):
89
"""Stub, call self.next_login_cb or send NewCredentials if
90
self.next_login_cb isn't defined.
92
self.realm = str(realm)
93
self.consumer_key = str(consumer_key)
94
if self.next_login_cb:
95
cb = self.next_login_cb[0]
96
args = self.next_login_cb[1]
97
self.next_login_cb = None
100
self.dbus_object.NewCredentials(realm, consumer_key)
102
def clear_token(self, realm, consumer_key):
103
"""Stub, do nothing"""
106
def next_login_with(self, callback, args=tuple()):
107
"""shortcircuit the next call to login and call the specified callback.
108
callback is usually one of: self.got_token, self.got_no_token,
109
self.got_denial or self.got_error.
111
self.next_login_cb = (callback, args)
114
77
class FakeDBusInterface(object):
115
78
"""A fake DBusInterface..."""
204
167
self.fail(str(error))
207
class FakeLogin(SSOCredentials):
208
"""Stub Object which listens for D-Bus OAuth requests"""
210
def __init__(self, bus):
211
"""Initiate the object."""
213
self.busName = dbus.service.BusName(DBUS_CREDENTIALS_IFACE,
215
# bypass the parent class __init__ as it has the path hardcoded
216
# and we can't use '/' as the path, as we are already using it
217
# for syncdaemon. pylint: disable-msg=W0233,W0231
218
dbus.service.Object.__init__(self, object_path="/oauthdesktop",
219
bus_name=self.busName)
220
self.processor = FakeLoginProcessor(self)
221
self.currently_authing = False
224
"""Shutdown and remove any trace from the bus"""
225
self.busName.get_bus().release_name(self.busName.get_name())
226
self.remove_from_connection()
229
170
class FakeNetworkManager(DBusExposedObject):
230
171
""" A fake NetworkManager that only emits StatusChanged signal. """