async def asyncSetUp(self) -> None: await super().asyncSetUp() self.seed.apply_settings({"enable_dht": True}) config = await services.get_config() config["session_dht_bootstrap_nodes"] = self.seed_endpoint_str config["session_enable_dht"] = True await asyncio.wait_for(services.set_config(config), 5)
async def test_set_invalid_config(self) -> None: async with self.start_stop_session(): self.config["torrent_default_storage_mode"] = "invalid" with self.assertRaises(config_lib.InvalidConfigError): await asyncio.wait_for(services.set_config(self.config), 5) config = await asyncio.wait_for(services.get_config(), 5) self.assertNotEqual(config.get_str("torrent_default_storage_mode"), "invalid")
async def test_save_path_loop(self) -> None: bad_link = pathlib.Path("bad_link") await concurrency.to_thread(bad_link.symlink_to, bad_link, target_is_directory=True) config = config_lib.Config(torrent_default_save_path=str(bad_link)) with self.assertRaises(config_lib.InvalidConfigError): await asyncio.wait_for(services.set_config(config), 5)
async def test_set_config(self) -> None: async with self.start_stop_session(): self.config["__test_key__"] = "value" await asyncio.wait_for(services.set_config(self.config), 5) # Test loaded into available config config = await asyncio.wait_for(services.get_config(), 5) self.assertEqual(config["__test_key__"], "value") # Test written to disk config = await config_lib.Config.from_disk(services.CONFIG_PATH) self.assertEqual(config, self.config)
async def test_set_non_defaults(self) -> None: # Set all non-default configs config = config_lib.Config( torrent_default_save_path=self.tempdir.name, torrent_default_flags_apply_ip_filter=False, torrent_default_storage_mode="allocate", ) await asyncio.wait_for(services.set_config(config), 5) atp = await asyncio.wait_for(atp_services.get_default(), 5) self.assertEqual( pathlib.Path(atp.save_path).resolve(), pathlib.Path(self.tempdir.name).resolve(), ) self.assertEqual( atp.flags, lt.torrent_flags.default_flags & ~lt.torrent_flags.apply_ip_filter, ) self.assertEqual(atp.storage_mode, lt.storage_mode_t.storage_mode_allocate)
async def test_disable(self) -> None: config = await services.get_config() config["public_enable"] = False await asyncio.wait_for(services.set_config(config), 5) r = await self.client.get(f"/d/btih/{self.torrent.sha1_hash}/i/0") self.assertEqual(r.status_code, 404)
async def test_storage_mode_invalid(self) -> None: config = config_lib.Config(torrent_default_storage_mode="invalid") with self.assertRaises(config_lib.InvalidConfigError): await asyncio.wait_for(services.set_config(config), 5)
async def test_flags_apply_ip_filter_null(self) -> None: config = config_lib.Config(torrent_default_flags_apply_ip_filter=None) with self.assertRaises(config_lib.InvalidConfigError): await asyncio.wait_for(services.set_config(config), 5)