async def test_manual_creds(reader: ReaderHelper, ui_server: UiServer, config: Config, server, session, drive: DriveSource): # get the auth url req_path = "manualauth?client_id={}&client_secret={}".format(config.get( Setting.DEFAULT_DRIVE_CLIENT_ID), config.get(Setting.DEFAULT_DRIVE_CLIENT_SECRET)) data = await reader.getjson(req_path) assert "auth_url" in data # request the auth code from "google" async with session.get(data["auth_url"], allow_redirects=False) as resp: code = (await resp.json())["code"] drive.saveCreds(None) assert not drive.enabled() # Pass the auth code to generate creds req_path = "manualauth?code={}".format(code) assert await reader.getjson(req_path) == { 'auth_url': "index?fresh=true" } # verify creds are saved and drive is enabled assert drive.enabled() # Now verify that bad creds fail predictably req_path = "manualauth?code=bad_code" assert await reader.getjson(req_path) == { 'error': 'Your Google Drive credentials have expired. Please reauthorize with Google Drive through the Web UI.' }
async def test_existing_folder_already_exists(time, drive: DriveSource, config: Config, folder_finder: FolderFinder): await drive.get() drive.checkBeforeChanges() # Reset folder, try again folder_finder.reset() await drive.get() with pytest.raises(ExistingBackupFolderError): drive.checkBeforeChanges()
async def test_cred_refresh_no_secret(drive: DriveSource, server: SimulationServer, time: FakeTime, config: Config): drive.saveCreds(server.getCurrentCreds()) await drive.get() old_creds = drive.drivebackend.creds await drive.get() assert old_creds.access_token == drive.drivebackend.creds.access_token time.advanceDay() await drive.get() assert old_creds.access_token != drive.drivebackend.creds.access_token with open(config.get(Setting.CREDENTIALS_FILE_PATH)) as f: assert "client_secret" not in json.load(f)
async def test_working_through_upload(drive: DriveSource, server: SimulationServer, backup_helper: BackupHelper, interceptor: RequestInterceptor): assert not drive.isWorking() # Let a single chunk upload, then wait matcher = interceptor.setWaiter(URL_MATCH_UPLOAD_PROGRESS, attempts=1) from_backup, data = await backup_helper.createFile(size=1024 * 1024 * 10) save_task = asyncio.create_task(drive.save(from_backup, data)) await matcher.waitForCall() assert drive.isWorking() # let it complete matcher.clear() await save_task assert not drive.isWorking()
async def test_working_through_upload(drive: DriveSource, server: SimulationServer, snapshot_helper: SnapshotHelper): assert not drive.isWorking() # Let a single chunk upload, then wait server._upload_chunk_wait.clear() server._upload_chunk_trigger.clear() server.waitOnChunk = 2 from_snapshot, data = await snapshot_helper.createFile(size=1024 * 1024 * 10) save_task = asyncio.create_task(drive.save(from_snapshot, data)) await server._upload_chunk_trigger.wait() assert drive.isWorking() # let it complete server._upload_chunk_wait.set() await save_task assert not drive.isWorking()
async def test_change_specify_folder_setting_with_manual_creds( reader: ReaderHelper, google, session, coord: Coordinator, folder_finder: FolderFinder, drive: DriveSource, config): google.resetDriveAuth() # Generate manual credentials req_path = "manualauth?client_id={}&client_secret={}".format( google._custom_drive_client_id, google._custom_drive_client_secret) data = await reader.getjson(req_path) assert "auth_url" in data async with session.get(data["auth_url"], allow_redirects=False) as resp: code = (await resp.json())["code"] drive.saveCreds(None) assert not drive.enabled() req_path = "manualauth?code={}".format(code) await reader.getjson(req_path) assert drive.isCustomCreds() await coord.sync() assert folder_finder.getCachedFolder() is not None # Specify the snapshot folder, which should cache the new one update = { "config": { Setting.SPECIFY_SNAPSHOT_FOLDER.value: True }, "snapshot_folder": "12345" } assert await reader.postjson("saveconfig", json=update) == { 'message': 'Settings saved', "reload_page": False } assert folder_finder.getCachedFolder() == "12345" # Un change the folder, which should keep the existing folder update = { "config": { Setting.SPECIFY_SNAPSHOT_FOLDER.value: False }, "snapshot_folder": "" } assert await reader.postjson("saveconfig", json=update) == { 'message': 'Settings saved', "reload_page": False } assert folder_finder.getCachedFolder() == "12345"
async def test_existing_resolved_create_new(time, drive: DriveSource, config: Config, folder_finder: FolderFinder): await drive.get() drive.checkBeforeChanges() folder_id = await drive.getFolderId() # Reset folder, try again folder_finder.reset() await drive.get() with pytest.raises(ExistingBackupFolderError): drive.checkBeforeChanges() folder_finder.resolveExisting(False) await drive.get() drive.checkBeforeChanges() assert await drive.getFolderId() != folder_id
async def test_disable_upload(drive: DriveSource, config: Config): assert drive.upload() config.override(Setting.ENABLE_DRIVE_UPLOAD, False) assert not drive.upload()
async def test_check_time(drive: DriveSource, drive_creds: Creds): assert not drive.check() drive.saveCreds(drive_creds) assert drive.check()