def __init__(self, config: Config, ports: Ports, time: Time): self._config = config self._time = time self._ports = ports self._auth_token = "test_header" self._backups: Dict[str, Any] = {} self._backup_data: Dict[str, bytearray] = {} self._backup_lock = asyncio.Lock() self._backup_inner_lock = asyncio.Lock() self._entities = {} self._events = [] self._attributes = {} self._notification = None self._min_backup_size = 1024 * 1024 * 5 self._max_backup_size = 1024 * 1024 * 5 self._addon_slug = "self_slug" self._options = self.defaultOptions() self._username = "******" self._password = "******" self._addons = all_addons.copy() self._super_version = Version(2021, 8) self.installAddon(self._addon_slug, "Home Assistant Google drive Backup") self.installAddon("42", "The answer") self.installAddon("sgadg", "sdgsagsdgsggsd")
async def test_backup_supervisor_path(ha: HaSource, supervisor: SimulatedSupervisor, interceptor: RequestInterceptor): supervisor._super_version = Version(2021, 7) await ha.get() assert not interceptor.urlWasCalled(URL_MATCH_BACKUPS) assert interceptor.urlWasCalled(URL_MATCH_SNAPSHOT)
async def test_old_delete_path(ha: HaSource, supervisor: SimulatedSupervisor, interceptor: RequestInterceptor, time: FakeTime): supervisor._super_version = Version(2020, 8) await ha.get() backup: HABackup = await ha.create(CreateOptions(time.now(), "Test Name")) full = DummyBackup(backup.name(), backup.date(), backup.size(), backup.slug(), "dummy") full.addSource(backup) await ha.delete(full) assert interceptor.urlWasCalled("/snapshots/{0}/remove".format( backup.slug()))
import base64 from os.path import abspath, join from aiohttp.web import Application, json_response, Request, TCPSite, AppRunner, post, Response, static, get from aiohttp.client_exceptions import ClientResponseError, ClientConnectorError, ServerConnectionError, ServerDisconnectedError, ServerTimeoutError from aiohttp.web_exceptions import HTTPBadRequest, HTTPSeeOther from backup.creds import Exchanger from backup.config import Config, Setting, VERSION from backup.exceptions import GoogleCredentialsExpired, ensureKey, KnownError from injector import ClassAssistedBuilder, inject, singleton from .errorstore import ErrorStore from .cloudlogger import CloudLogger from yarl import URL from backup.config import Version from urllib.parse import unquote NEW_AUTH_MINIMUM = Version(0, 101, 3) @singleton class Server(): @inject def __init__(self, config: Config, exchanger_builder: ClassAssistedBuilder[Exchanger], logger: CloudLogger, error_store: ErrorStore): self.exchanger = exchanger_builder.build( client_id=config.get(Setting.DEFAULT_DRIVE_CLIENT_ID), client_secret=config.get(Setting.DEFAULT_DRIVE_CLIENT_SECRET), redirect=URL(config.get(Setting.AUTHORIZATION_HOST)).with_path("/drive/authorize")) self.logger = logger
def test_junk_strings(): assert Version.parse("1-.2.3.1") == Version(1, 2, 3, 1) assert Version.parse("ignore-1.2.3.1") == Version(1, 2, 3, 1) assert Version.parse( "1.2.ignore.this.text.3.and...andhere.too.1") == Version(1, 2, 3, 1)
def test_parse_staging(): assert Version.parse("1.0.staging.1") == Version(1, 0, 1) assert Version.parse("1.0.staging.1").staging assert Version.parse("1.0.staging.1") > Version(1.0) assert Version.parse("1.2.3") == Version(1, 2, 3)
def test_parse(): assert Version.parse("1.0") == Version(1, 0) assert Version.parse("1.2.3") == Version(1, 2, 3)
def test_version(): assert Version(1, 2, 3) == Version(1, 2, 3) assert Version(1, 2, 3) >= Version(1, 2, 3) assert Version(1, 2, 3) <= Version(1, 2, 3) assert Version(1, 2, 3) > Version(1, 2) assert Version(1) < Version(2) assert Version(2) > Version(1) assert Version(1) != Version(2) assert Version(1, 2) > Version(1) assert Version(1) < Version(1, 2)
from backup.logger import getLogger, getHistory, TraceLogger from backup.creds import Exchanger, MANUAL_CODE_REDIRECT_URI, Creds from backup.debugworker import DebugWorker from backup.drive import FolderFinder from backup.const import FOLDERS from .debug import Debug from yarl import URL logger = getLogger(__name__) # Used to Google's oauth verification SCOPE: str = 'https://www.googleapis.com/auth/drive.file' MIME_TEXT_HTML = "text/html" MIME_JSON = "application/json" VERSION_CREATION_TRACKING = Version(0, 104, 0) @singleton class UiServer(Trigger, Startable): @inject def __init__(self, debug: Debug, coord: Coordinator, ha_source: HaSource, harequests: HaRequests, time: Time, config: Config, global_info: GlobalInfo, estimator: Estimator, session: ClientSession, exchanger_builder: ClassAssistedBuilder[Exchanger], debug_worker: DebugWorker, folder_finder: FolderFinder, data_cache: DataCache, haupdater: HaUpdater): super().__init__() # Currently running server tasks self.runners = [] self.exchanger_builder = exchanger_builder self._coord = coord