def setUp(self): """Setup.""" yield super(TestWithDatabase, self).setUp() self.__root = None # Patch AQ's deferreds, to support these tests still being run # in Lucid, but while code calls .cancel() on them # Remove this code when filesync project is taken to Precise. defer.Deferred.cancel = lambda self: None defer.DeferredList.cancel = lambda self: None # Set up the main loop and bus connection self.loop = DBusGMainLoop(set_as_default=True) bus_address = os.environ.get('DBUS_SESSION_BUS_ADDRESS', None) self.bus = dbus.bus.BusConnection(address_or_type=bus_address, mainloop=self.loop) # Monkeypatch the dbus.SessionBus/SystemBus methods, to ensure we # always point at our own private bus instance. self.patch(dbus, 'SessionBus', lambda: self.bus) self.patch(dbus, 'SystemBus', lambda: self.bus) self.nm = FakeNetworkManager(self.bus) self.addCleanup(self.nm.shutdown) # start the ssl proxy self.ssl_service = ssl_proxy.ProxyService( self.ssl_cert, self.ssl_key, self.ssl_cert_chain, 0, # port "localhost", self.port, "ssl-proxy-test", 0) self.patch(config.ssl_proxy, "heartbeat_interval", self.ssl_proxy_heartbeat_interval) yield self.ssl_service.startService() # these tests require a "test" bucket to be avaialble, # but don't create it using the s3 api... self.s4_site.resource._add_bucket("test") if os.path.exists(self.tmpdir): self.rmtree(self.tmpdir) _user_data = [ (u'jack', u'jackpass', u'shard0'), (u'jane', u'janepass', u'shard1'), (u'john', u'johnpass', u'shard2'), ] self.access_tokens = {} self.storage_users = {} for username, password, shard in _user_data: self.access_tokens[username] = { 'username': username, 'password': password, } user = create_test_user(username=username, password=password, shard_id=shard) self.storage_users[username] = user self.dns_srv = None # override and cleanup user config self.old_get_config_files = main.config.get_config_files main.config.get_config_files = lambda: SD_CONFIGS main.config._user_config = None user_config = main.config.get_user_config() for section in user_config.sections(): user_config.remove_section(section) main.config.get_user_config().set_throttling_read_limit(-1) main.config.get_user_config().set_throttling_write_limit(-1) main.config.get_user_config().set_autoconnect(False) # logging can not be configured dinamically, touch the general logger # to get one big file and be able to get the logs if failure logger.init() logger.set_max_bytes(0) yield self.client_setup()
event_queue, filesystem_manager as fs_manager, interaction_interfaces, interfaces, volume_manager, main, local_rescan, tritcask, RECENT_TRANSFERS, UPLOADING, ) from ubuntuone.syncdaemon import logger from ubuntuone import platform from ubuntuone.platform import can_write, make_dir, path_exists, set_dir_readonly, set_dir_readwrite, stat_path logger.init() FAKED_CREDENTIALS = {"username": "******", "password": "******"} @contextlib.contextmanager def environ(env_var, new_value): """context manager to replace/add an environ value""" old_value = os.environ.get(env_var, None) os.environ[env_var] = new_value yield if old_value is None: os.environ.pop(env_var) else: os.environ[env_var] = old_value
def setUp(self): """Setup.""" yield super(TestWithDatabase, self).setUp() self.__root = None # Set up the main loop and bus connection self.loop = DBusGMainLoop(set_as_default=True) bus_address = os.environ.get('DBUS_SESSION_BUS_ADDRESS', None) self.bus = dbus.bus.BusConnection(address_or_type=bus_address, mainloop=self.loop) # Monkeypatch the dbus.SessionBus/SystemBus methods, to ensure we # always point at our own private bus instance. self.patch(dbus, 'SessionBus', lambda: self.bus) self.patch(dbus, 'SystemBus', lambda: self.bus) self.nm = FakeNetworkManager(self.bus) self.addCleanup(self.nm.shutdown) # start the ssl proxy self.ssl_service = ssl_proxy.ProxyService(self.ssl_cert, self.ssl_key, self.ssl_cert_chain, 0, # port "localhost", self.port, "ssl-proxy-test", 0) self.patch(settings.ssl_proxy, 'HEARTBEAT_INTERVAL', self.ssl_proxy_heartbeat_interval) yield self.ssl_service.startService() if os.path.exists(self.tmpdir): self.rmtree(self.tmpdir) _user_data = [ (u'jack', u'jackpass'), (u'jane', u'janepass'), (u'john', u'johnpass'), ] self.access_tokens = {} self.storage_users = {} for username, password in _user_data: self.access_tokens[username] = { 'username': username, 'password': password, } user = self.make_user(username=username, password=password) self.storage_users[username] = user self.dns_srv = None # override and cleanup user config self.old_get_config_files = main.config.get_config_files main.config.get_config_files = lambda: SD_CONFIGS main.config._user_config = None user_config = main.config.get_user_config() for section in user_config.sections(): user_config.remove_section(section) main.config.get_user_config().set_throttling_read_limit(-1) main.config.get_user_config().set_throttling_write_limit(-1) main.config.get_user_config().set_autoconnect(False) # logging can not be configured dinamically, touch the general logger # to get one big file and be able to get the logs if failure syncdaemon_logger.init() syncdaemon_logger.set_max_bytes(0) yield self.client_setup()
def setUp(self): """Setup.""" yield super(TestWithDatabase, self).setUp() self.__root = None # Patch AQ's deferreds, to support these tests still being run # in Lucid, but while code calls .cancel() on them # Remove this code when filesync project is taken to Precise. defer.Deferred.cancel = lambda self: None defer.DeferredList.cancel = lambda self: None # Set up the main loop and bus connection self.loop = DBusGMainLoop(set_as_default=True) bus_address = os.environ.get('DBUS_SESSION_BUS_ADDRESS', None) self.bus = dbus.bus.BusConnection(address_or_type=bus_address, mainloop=self.loop) # Monkeypatch the dbus.SessionBus/SystemBus methods, to ensure we # always point at our own private bus instance. self.patch(dbus, 'SessionBus', lambda: self.bus) self.patch(dbus, 'SystemBus', lambda: self.bus) self.nm = FakeNetworkManager(self.bus) self.addCleanup(self.nm.shutdown) # start the ssl proxy self.ssl_service = ssl_proxy.ProxyService(self.ssl_cert, self.ssl_key, self.ssl_cert_chain, 0, # port "localhost", self.port, "ssl-proxy-test", 0) self.patch(config.ssl_proxy, "heartbeat_interval", self.ssl_proxy_heartbeat_interval) yield self.ssl_service.startService() # these tests require a "test" bucket to be avaialble, # but don't create it using the s3 api... self.s4_site.resource._add_bucket("test") if os.path.exists(self.tmpdir): self.rmtree(self.tmpdir) _user_data = [ (u'jack', u'jackpass', u'shard0'), (u'jane', u'janepass', u'shard1'), (u'john', u'johnpass', u'shard2'), ] self.access_tokens = {} self.storage_users = {} for username, password, shard in _user_data: self.access_tokens[username] = { 'username': username, 'password': password, } user = create_test_user(username=username, password=password, shard_id=shard) self.storage_users[username] = user self.dns_srv = None # override and cleanup user config self.old_get_config_files = main.config.get_config_files main.config.get_config_files = lambda: SD_CONFIGS main.config._user_config = None user_config = main.config.get_user_config() for section in user_config.sections(): user_config.remove_section(section) main.config.get_user_config().set_throttling_read_limit(-1) main.config.get_user_config().set_throttling_write_limit(-1) main.config.get_user_config().set_autoconnect(False) # logging can not be configured dinamically, touch the general logger # to get one big file and be able to get the logs if failure logger.init() logger.set_max_bytes(0) yield self.client_setup()