def setUp(self): self.account_info = InMemoryAccountInfo() self.cache = DummyCache() self.raw_api = RawSimulator() self.api = B2Api(self.account_info, self.cache, self.raw_api) (self.application_key_id, self.master_key) = self.raw_api.create_account()
def __init__(self, account_info=None, cache=None, raw_api=None): """ Initialize Session using given account info. :param account_info: an instance of :class:`~b2sdk.v1.UrlPoolAccountInfo`, or any custom class derived from :class:`~b2sdk.v1.AbstractAccountInfo` To learn more about Account Info objects, see here :class:`~b2sdk.v1.SqliteAccountInfo` :param cache: an instance of the one of the following classes: :class:`~b2sdk.cache.DummyCache`, :class:`~b2sdk.cache.InMemoryCache`, :class:`~b2sdk.cache.AuthInfoCache`, or any custom class derived from :class:`~b2sdk.cache.AbstractCache` It is used by B2Api to cache the mapping between bucket name and bucket ids. default is :class:`~b2sdk.cache.DummyCache` :param raw_api: an instance of one of the following classes: :class:`~b2sdk.raw_api.B2RawApi`, :class:`~b2sdk.raw_simulator.RawSimulator`, or any custom class derived from :class:`~b2sdk.raw_api.AbstractRawApi` It makes network-less unit testing simple by using :class:`~b2sdk.raw_simulator.RawSimulator`, in tests and :class:`~b2sdk.raw_api.B2RawApi` in production. default is :class:`~b2sdk.raw_api.B2RawApi` """ self.raw_api = raw_api or B2RawApi(B2Http()) if account_info is None: account_info = SqliteAccountInfo() if cache is None: cache = AuthInfoCache(account_info) if cache is None: cache = DummyCache() self.account_info = account_info self.cache = cache self._token_callbacks = { TokenType.API: self._api_token_callback, TokenType.API_TOKEN_ONLY: self._api_token_only_callback, TokenType.UPLOAD_SMALL: self._upload_small, TokenType.UPLOAD_PART: self._upload_part, }
def __init__(self, account_info: Optional[AbstractAccountInfo] = None, cache: Optional[AbstractCache] = None, api_config: B2HttpApiConfig = DEFAULT_HTTP_API_CONFIG): """ Initialize Session using given account info. :param account_info: an instance of :class:`~b2sdk.v2.UrlPoolAccountInfo`, or any custom class derived from :class:`~b2sdk.v2.AbstractAccountInfo` To learn more about Account Info objects, see here :class:`~b2sdk.v2.SqliteAccountInfo` :param cache: an instance of the one of the following classes: :class:`~b2sdk.cache.DummyCache`, :class:`~b2sdk.cache.InMemoryCache`, :class:`~b2sdk.cache.AuthInfoCache`, or any custom class derived from :class:`~b2sdk.cache.AbstractCache` It is used by B2Api to cache the mapping between bucket name and bucket ids. default is :class:`~b2sdk.cache.DummyCache` :param api_config """ self.raw_api = api_config.raw_api_class(self.B2HTTP_CLASS(api_config)) if account_info is None: account_info = self.SQLITE_ACCOUNT_INFO_CLASS() if cache is None: cache = AuthInfoCache(account_info) if cache is None: cache = DummyCache() self.account_info = account_info self.cache = cache self._token_callbacks = { TokenType.API: self._api_token_callback, TokenType.API_TOKEN_ONLY: self._api_token_only_callback, TokenType.UPLOAD_SMALL: self._upload_small, TokenType.UPLOAD_PART: self._upload_part, }