async def main(): port = 56153 base = URL("http://localhost").with_port(port) config = Config.withOverrides({ Setting.DRIVE_AUTHORIZE_URL: str(base.with_path("o/oauth2/v2/auth")), Setting.AUTHENTICATE_URL: str(base.with_path("drive/authorize")), Setting.DRIVE_TOKEN_URL: str(base.with_path("token")), Setting.DRIVE_REFRESH_URL: str(base.with_path("oauth2/v4/token")) }) injector = Injector(BaseModule(config, override_dns=False)) server = injector.get( ClassAssistedBuilder[SimulationServer]).build(port=port) await server.reset({ 'snapshot_min_size': 1024 * 1024 * 3, 'snapshot_max_size': 1024 * 1024 * 5, "drive_refresh_token": "test_refresh_token", "drive_upload_sleep": 0, "snapshot_wait_time": 0, "hassio_header": "test_header" }) # start the server runner = aiohttp.web.AppRunner(server.createApp()) await runner.setup() site = aiohttp.web.TCPSite(runner, "0.0.0.0", port=port) await site.start() print("Server started on port " + str(port))
async def test_bootstrap_requirements(cleandir): # This just verifies we're able to satisfy starter's injector requirements. injector = Injector([BaseModule(), MainModule()]) config = injector.get(Config) config.override(Setting.DATA_CACHE_FILE_PATH, os.path.join(cleandir, "data_cache.json")) injector.get(Starter)
async def injector(cleandir, ports, generate_config): drive_creds = Creds(FakeTime(), "test_client_id", None, "test_access_token", "test_refresh_token") with open(os.path.join(cleandir, "secrets.yaml"), "w") as f: f.write("for_unit_tests: \"password value\"\n") with open(os.path.join(cleandir, "credentials.dat"), "w") as f: f.write(json.dumps(drive_creds.serialize())) return Injector([BaseModule(), TestModule(generate_config, ports)])
async def injector(cleandir, server_url, ui_port, ingress_port): drive_creds = Creds(FakeTime(), "test_client_id", None, "test_access_token", "test_refresh_token") with open(os.path.join(cleandir, "secrets.yaml"), "w") as f: f.write("for_unit_tests: \"password value\"\n") with open(os.path.join(cleandir, "credentials.dat"), "w") as f: f.write(json.dumps(drive_creds.serialize())) config = Config.withOverrides({ Setting.DRIVE_URL: server_url, Setting.HASSIO_URL: server_url + "/", Setting.HOME_ASSISTANT_URL: server_url + "/homeassistant/api/", Setting.AUTHENTICATE_URL: server_url + "/drive/authorize", Setting.DRIVE_REFRESH_URL: server_url + "/oauth2/v4/token", Setting.DRIVE_AUTHORIZE_URL: server_url + "/o/oauth2/v2/auth", Setting.DRIVE_TOKEN_URL: server_url + "/token", Setting.REFRESH_URL: server_url + "/drive/refresh", Setting.ERROR_REPORT_URL: server_url + "/logerror", Setting.HASSIO_TOKEN: "test_header", Setting.SECRETS_FILE_PATH: "secrets.yaml", Setting.CREDENTIALS_FILE_PATH: "credentials.dat", Setting.FOLDER_FILE_PATH: "folder.dat", Setting.RETAINED_FILE_PATH: "retained.json", Setting.ID_FILE_PATH: "id.json", Setting.INGRESS_TOKEN_FILE_PATH: "ingress.dat", Setting.DEFAULT_DRIVE_CLIENT_ID: "test_client_id", Setting.DEFAULT_DRIVE_CLIENT_SECRET: "test_client_secret", Setting.BACKUP_DIRECTORY_PATH: cleandir, Setting.PORT: ui_port, Setting.INGRESS_PORT: ingress_port }) # PROBLEM: Something in uploading snapshot chunks hangs between the client and server, so his keeps tests from # taking waaaaaaaay too long. Remove this line and the @pytest.mark.flaky annotations once the problem is identified. config.override(Setting.GOOGLE_DRIVE_TIMEOUT_SECONDS, 5) # logging.getLogger('injector').setLevel(logging.DEBUG) return Injector([ BaseModule(config), TestModule(cleandir, server_url, ui_port, ingress_port) ])
async def main(config): await Injector([BaseModule(config), MainModule()]).get(Starter).startup() while True: await asyncio.sleep(1)
async def test_bootstarp_requirements(): # This just verifies we're able to satisfy starter's injector requirements. injector = Injector([BaseModule(Config()), MainModule()]) injector.get(Starter)
async def main(): config = Config.fromEnvironment() module = BaseModule(config, override_dns=False) injector = Injector(module) await injector.get(Server).start()