blob: c2a5f1fb0285f575aa3e88c8c614f6408e09a483 [file] [log] [blame]
import dbus
import dbus.service
import dbus.mainloop.glib
import gobject
import logging
import threading
""" MockFlimflam provides a select few methods from the flimflam
DBus API so that we can track "dbus-send" invocations sent
by the shill init scripts. It could be used as a kernel for
a test of other facilities that use the shill/flimflam DBus
API and at that point it should be moved out of this specific
test. """
class MethodCall(object):
""" A logged method call to the DBus API. """
def __init__(self, method, argument):
self.method = method
self.argument = argument
class FlimflamManager(dbus.service.Object):
""" The flimflam DBus Manager object instance. Methods in this
object are called whenever a DBus RPC method is invoked. """
def __init__(self, bus, object_path):
dbus.service.Object.__init__(self, bus, object_path)
self.method_calls = []
in_signature='s', out_signature='o')
def CreateProfile(self, profile):
self.add_method_call('CreateProfile', profile)
return '/'
in_signature='s', out_signature='')
def RemoveProfile(self, profile):
self.add_method_call('RemoveProfile', profile)
in_signature='s', out_signature='o')
def PushProfile(self, profile):
self.add_method_call('PushProfile', profile)
return '/'
in_signature='s', out_signature='')
def PopProfile(self, profile):
self.add_method_call('PopProfile', profile)
def add_method_call(self, method, arg):
print "Called method %s" % method"Mock Flimflam method %s called with argument %s" %
(method, arg))
self.method_calls.append(MethodCall(method, arg))
def get_method_calls(self):
method_calls = self.method_calls
self.method_calls = []
return method_calls
class MockFlimflam(threading.Thread):
""" This thread object instantiates a mock flimflam manager and
runs a mainloop that receives DBus API messages. """
FLIMFLAM = "org.chromium.flimflam"
def __init__(self):
def run(self):
self.bus = dbus.SystemBus()
name = dbus.service.BusName(self.FLIMFLAM, self.bus)
self.manager = FlimflamManager(self.bus, '/')
self.mainloop = gobject.MainLoop()
def quit(self):
def get_method_calls(self):
return self.manager.get_method_calls()
if __name__ == '__main__':