diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..aaa2bdd1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,26 @@ +# Virtual environments +.venv/ +venv/ +env/ + +# Python bytecode +__pycache__/ +*.py[cod] + +# Packaging / build artifacts +build/ +dist/ +*.egg-info/ +.eggs/ + +# Test and tooling caches +.pytest_cache/ +.mypy_cache/ +.ruff_cache/ +.coverage +htmlcov/ + +# Editor and OS files +.idea/ +.vscode/ +.DS_Store diff --git a/README.md b/README.md index be1d4ed8..4ab041c5 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Appwrite is an open-source backend as a service server that abstracts and simpli ## Installation -Requires Python 3.9 or later. Install the [`appwrite`](https://pypi.org/project/appwrite/) package from PyPI: +Requires Python 3.11 or later. Install the [`appwrite`](https://pypi.org/project/appwrite/) package from PyPI: ```bash pip install appwrite @@ -27,6 +27,8 @@ uv add appwrite ## Getting started +Every API call is asynchronous, so every service method returns a coroutine you `await`. + ### Initialize the client Create a client with your Appwrite endpoint, project ID and an [API key](https://appwrite.io/docs/partners/project/api-keys). Find the endpoint and project ID in your project's **Settings** page, and create an API key with only the scopes you need under **API keys** in the project sidebar. @@ -44,24 +46,31 @@ API keys grant server-level access to your project. Keep them out of client-side ### Make a request -Create a service object with the client and call any of its methods. Every method returns a typed Pydantic model, so response fields are available as attributes. +Create a service object with the client and await any of its methods. Every method returns a typed Pydantic model, so response fields are available as attributes. ```python +import asyncio + from appwrite.id import ID from appwrite.services.users import Users -users = Users(client) -user = users.create( - user_id=ID.unique(), - email='email@example.com', - password='password', - name="Walter O'Brien", -) +async def main(): + users = Users(client) + + user = await users.create( + user_id=ID.unique(), + email='email@example.com', + password='password', + name="Walter O'Brien", + ) + + print(user.id) + print(user.name) + print(user.to_dict()) + -print(user.id) -print(user.name) -print(user.to_dict()) +asyncio.run(main()) ``` See the [API reference](https://appwrite.io/docs/references/cloud/server-python/users) for every service and method. @@ -71,6 +80,7 @@ See the [API reference](https://appwrite.io/docs/references/cloud/server-python/ Use `TablesDB` to read and write rows. Pass a Pydantic model as `model_type` to get typed row data back; without it, `row.data` is a `dict`. ```python +import asyncio from typing import Optional from pydantic import BaseModel @@ -86,28 +96,32 @@ class Post(BaseModel): excerpt: Optional[str] = None -tables_db = TablesDB(client) +async def main(): + tables_db = TablesDB(client) -row = tables_db.create_row( - database_id='', - table_id='', - row_id=ID.unique(), - data={'title': 'Hello, world', 'published': True}, - model_type=Post, -) + row = await tables_db.create_row( + database_id='', + table_id='', + row_id=ID.unique(), + data={'title': 'Hello, world', 'published': True}, + model_type=Post, + ) -print(row.id) -print(row.data.title) + print(row.id) + print(row.data.title) -result = tables_db.list_rows( - database_id='', - table_id='', - queries=[Query.equal('published', True), Query.limit(25)], - model_type=Post, -) + result = await tables_db.list_rows( + database_id='', + table_id='', + queries=[Query.equal('published', True), Query.limit(25)], + model_type=Post, + ) -for row in result.rows: - print(row.data.title) + for row in result.rows: + print(row.data.title) + + +asyncio.run(main()) ``` ### Handle errors @@ -118,11 +132,24 @@ Failed requests raise `AppwriteException`, which carries `message`, `code`, `typ from appwrite.exception import AppwriteException try: - user = users.get(user_id='') + user = await users.get(user_id='') except AppwriteException as error: print(error.code, error.type, error.message) ``` +### Close the client + +The client keeps a pooled HTTP connection open. Close it when you are done, or use it as an async context manager. + +```python +await client.aclose() +``` + +```python +async with Client() as client: + ... +``` + ### Self-hosted Appwrite Point the client at your own instance instead of Appwrite Cloud. Call `set_self_signed()` only in development, when the server uses a self-signed TLS certificate. diff --git a/appwrite/client.py b/appwrite/client.py index 4b4a5a0f..6e2d748e 100644 --- a/appwrite/client.py +++ b/appwrite/client.py @@ -1,16 +1,25 @@ -import io +import anyio +import inspect import json import os import platform import sys -import requests -from concurrent.futures import ThreadPoolExecutor, as_completed -from threading import Lock +import httpx2 from .input_file import InputFile from .exception import AppwriteException from .encoders.value_class_encoder import ValueClassEncoder from .query import Query +_ssl_context = None + + +def _default_ssl_context(): + """Build the TLS context once and reuse it across clients.""" + global _ssl_context + if _ssl_context is None: + _ssl_context = httpx2.create_ssl_context() + return _ssl_context + class Client: def __init__(self): @@ -27,9 +36,34 @@ def __init__(self): 'X-Appwrite-Response-Format': '2.5.0', } self._config = {} + self._http = self._new_http_client(verify=True) + self._retired_http = [] + + def _new_http_client(self, verify): + context = _default_ssl_context() if verify else False + return httpx2.AsyncClient(verify=context, timeout=None) + + async def __aenter__(self): + return self + + async def __aexit__(self, exc_type, exc_value, traceback): + await self.aclose() + + async def aclose(self): + """Close the underlying HTTP connection pool.""" + for client in self._retired_http: + await client.aclose() + self._retired_http = [] + await self._http.aclose() def set_self_signed(self, status=True): + """Accept self-signed TLS certificates.""" self._self_signed = status + previous = self._http + self._http = self._new_http_client(verify=not status) + # anyio has no fire-and-forget tasks, so the replaced client is parked here + # and closed together with the active one once aclose() runs. + self._retired_http.append(previous) return self def set_endpoint(self, endpoint): @@ -130,7 +164,8 @@ def set_impersonate_user_phone(self, value): self._config['impersonateuserphone'] = value return self - def call(self, method, path='', headers=None, params=None, response_type='json'): + async def call(self, method, path='', headers=None, params=None, response_type='json'): + """Perform a single API request.""" if headers is None: headers = {} @@ -141,6 +176,7 @@ def call(self, method, path='', headers=None, params=None, response_type='json') data = {} files = {} + content = None stringify = False headers = {**self._global_headers, **headers} @@ -150,47 +186,56 @@ def call(self, method, path='', headers=None, params=None, response_type='json') params = {} if headers['content-type'].startswith('application/json'): - data = json.dumps(data, cls=ValueClassEncoder) + content = json.dumps(data, cls=ValueClassEncoder) + data = {} if headers['content-type'].startswith('multipart/form-data'): del headers['content-type'] stringify = True for key in data.copy(): if isinstance(data[key], InputFile): - files[key] = (data[key].filename, data[key].data) + payload = data[key].data + if isinstance(payload, str): + payload = payload.encode('utf-8') + elif not isinstance(payload, bytes): + payload = bytes(payload) + files[key] = (data[key].filename, payload) del data[key] data = self.flatten(data, stringify=stringify) if not files and data: - # Without a file, requests would fall back to a URL-encoded body. + # Without a file, httpx2 would fall back to a URL-encoded body. files = {key: (None, value) for key, value in data.items()} data = {} elif not files: - # With no parts at all, requests would send a bare body, so close an empty multipart one. + # With no parts at all, httpx2 would send a bare body, so close an empty multipart one. boundary = os.urandom(16).hex() headers['content-type'] = f'multipart/form-data; boundary={boundary}' - data = f'--{boundary}--\r\n' + content = f'--{boundary}--\r\n' response = None try: - response = requests.request( # call method dynamically https://stackoverflow.com/a/4246075/2299554 + response = await self._http.request( # call method dynamically https://stackoverflow.com/a/4246075/2299554 method=method, url=self._endpoint + path, params=self.flatten(params, stringify=stringify), - data=data, - files=files, + data=data or None, + files=files or None, + content=content, headers=headers, - verify=(not self._self_signed), - allow_redirects=False if response_type == 'location' else True, + follow_redirects=False if response_type == 'location' else True, ) - response.raise_for_status() + # httpx raises on 3xx, unlike requests; a redirect is the expected + # outcome for response_type='location', so only 4xx/5xx are errors. + if response.status_code >= 400: + response.raise_for_status() warnings = response.headers.get('x-appwrite-warning') if warnings: for warning in warnings.split(';'): print(f'Warning: {warning}', file=sys.stderr) - content_type = response.headers['Content-Type'] + content_type = response.headers.get('Content-Type', '') if response_type == 'location': return response.headers.get('Location') @@ -201,10 +246,10 @@ def call(self, method, path='', headers=None, params=None, response_type='json') if content_type.startswith('application/json'): return response.json() - return response._content + return response.content except Exception as e: if response != None: - content_type = response.headers['Content-Type'] + content_type = response.headers.get('Content-Type', '') if content_type.startswith('application/json'): raise AppwriteException( response.json()['message'], response.status_code, response.json().get('type'), response.text @@ -214,7 +259,7 @@ def call(self, method, path='', headers=None, params=None, response_type='json') else: raise AppwriteException(e) - def chunked_upload( + async def chunked_upload( self, path, headers=None, @@ -225,8 +270,9 @@ def chunked_upload( response_type='json', method='post', ): + """Upload a file in chunks, reporting progress as it goes.""" if params.get(param_name) is None: - return self.call(method, path, headers, params, response_type=response_type) + return await self.call(method, path, headers, params, response_type=response_type) input_file = params[param_name] @@ -243,14 +289,14 @@ def chunked_upload( input_file.data = input.read() params[param_name] = input_file - return self.call(method, path, headers, params, response_type=response_type) + return await self.call(method, path, headers, params, response_type=response_type) offset = 0 counter = 0 if upload_id: try: - result = self.call('get', path + '/' + upload_id, headers) + result = await self.call('get', path + '/' + upload_id, headers) counter = result['chunksUploaded'] except: pass @@ -285,7 +331,6 @@ def read_chunk(start, end): upload_id_header = upload_id completed_count = chunks[0]['index'] uploaded_size = chunks[0]['start'] - progress_lock = Lock() last_result = None final_result = None @@ -298,9 +343,9 @@ def is_upload_complete(chunk_result): chunks_total = chunk_result.get('chunksTotal', total_chunks) return int(chunks_uploaded) >= int(chunks_total) - def upload_chunk(chunk, current_upload_id): + async def upload_chunk(chunk, current_upload_id): chunk_input = InputFile.from_bytes( - read_chunk(chunk['start'], chunk['end']), + await anyio.to_thread.run_sync(read_chunk, chunk['start'], chunk['end']), input_file.filename, getattr(input_file, 'mime_type', None), ) @@ -310,7 +355,7 @@ def upload_chunk(chunk, current_upload_id): if current_upload_id: chunk_headers["x-appwrite-id"] = current_upload_id - return self.call( + return await self.call( method, path, chunk_headers, @@ -318,7 +363,7 @@ def upload_chunk(chunk, current_upload_id): response_type=response_type, ) - result = upload_chunk(chunks[0], upload_id_header) + result = await upload_chunk(chunks[0], upload_id_header) last_result = result if isinstance(result, dict) and "$id" in result: upload_id_header = result["$id"] @@ -326,44 +371,67 @@ def upload_chunk(chunk, current_upload_id): completed_count = chunks[0]['index'] + 1 uploaded_size = chunks[0]['end'] - if on_progress is not None: - on_progress( + await self._report_progress( + on_progress, + { + "$id": result.get("$id") if isinstance(result, dict) else None, + "progress": uploaded_size / size * 100, + "sizeUploaded": uploaded_size, + "chunksTotal": total_chunks, + "chunksUploaded": completed_count, + }, + ) + + semaphore = anyio.Semaphore(8) + + failures = [] + + async def upload_remaining_chunk(chunk): + nonlocal completed_count, uploaded_size, last_result, final_result + # a task group cancels siblings on the first raise, so failures are + # captured here to keep gather(return_exceptions=True) semantics. + try: + async with semaphore: + chunk_result = await upload_chunk(chunk, upload_id_header) + except BaseException as exc: + failures.append(exc) + return + completed_count = completed_count + 1 + uploaded_size = uploaded_size + (chunk['end'] - chunk['start']) + last_result = chunk_result + if is_upload_complete(chunk_result): + final_result = chunk_result + await self._report_progress( + on_progress, { - "$id": result.get("$id") if isinstance(result, dict) else None, + "$id": upload_id_header, "progress": uploaded_size / size * 100, "sizeUploaded": uploaded_size, "chunksTotal": total_chunks, "chunksUploaded": completed_count, - } + }, ) - def upload_remaining_chunk(chunk): - nonlocal completed_count, uploaded_size, last_result, final_result - chunk_result = upload_chunk(chunk, upload_id_header) - with progress_lock: - completed_count = completed_count + 1 - uploaded_size = uploaded_size + (chunk['end'] - chunk['start']) - last_result = chunk_result - if is_upload_complete(chunk_result): - final_result = chunk_result - if on_progress is not None: - on_progress( - { - "$id": upload_id_header, - "progress": uploaded_size / size * 100, - "sizeUploaded": uploaded_size, - "chunksTotal": total_chunks, - "chunksUploaded": completed_count, - } - ) + # Wait for every sibling chunk to settle before surfacing a failure, so the + # caller never observes an error while other chunks are still being written. + async with anyio.create_task_group() as tg: + for chunk in chunks[1:]: + tg.start_soon(upload_remaining_chunk, chunk) - with ThreadPoolExecutor(max_workers=8) as executor: - futures = [executor.submit(upload_remaining_chunk, chunk) for chunk in chunks[1:]] - for future in as_completed(futures): - future.result() + if failures: + raise failures[0] return final_result or last_result + @staticmethod + async def _report_progress(on_progress, payload): + """Invoke the progress callback, awaiting it when it is a coroutine.""" + if on_progress is None: + return + result = on_progress(payload) + if inspect.isawaitable(result): + await result + def flatten(self, data, prefix='', stringify=False): output = {} entries = data.items() if isinstance(data, dict) else enumerate(data) diff --git a/appwrite/services/account.py b/appwrite/services/account.py index 9788e53c..f3cb5611 100644 --- a/appwrite/services/account.py +++ b/appwrite/services/account.py @@ -35,7 +35,7 @@ class Account(Service): def __init__(self, client) -> None: super(Account, self).__init__(client) - def get( + async def get( self, model_type: Type[T] = dict, ) -> User[T]: @@ -61,7 +61,7 @@ def get( api_path = '/account' api_params = {} - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -73,7 +73,7 @@ def get( return User.with_data(response, model_type) - def create( + async def create( self, user_id: str, email: str, @@ -122,7 +122,7 @@ def create( if name is not None: api_params['name'] = self._normalize_value(name) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -135,7 +135,7 @@ def create( return User.with_data(response, model_type) - def list_consents( + async def list_consents( self, queries: Optional[List[str]] = None, total: Optional[bool] = None, @@ -167,7 +167,7 @@ def list_consents( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -179,7 +179,7 @@ def list_consents( return self._parse_response(response, model=Oauth2ConsentList) - def get_consent( + async def get_consent( self, consent_id: str, ) -> Oauth2Consent: @@ -207,7 +207,7 @@ def get_consent( raise AppwriteException('Missing required parameter: "consent_id"') api_path = api_path.replace('{consentId}', str(self._normalize_value(consent_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -219,7 +219,7 @@ def get_consent( return self._parse_response(response, model=Oauth2Consent) - def delete_consent( + async def delete_consent( self, consent_id: str, ) -> Dict[str, Any]: @@ -247,7 +247,7 @@ def delete_consent( raise AppwriteException('Missing required parameter: "consent_id"') api_path = api_path.replace('{consentId}', str(self._normalize_value(consent_id))) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -260,7 +260,7 @@ def delete_consent( return response - def list_consent_tokens( + async def list_consent_tokens( self, consent_id: str, queries: Optional[List[str]] = None, @@ -298,7 +298,7 @@ def list_consent_tokens( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -310,7 +310,7 @@ def list_consent_tokens( return self._parse_response(response, model=Oauth2ConsentTokenList) - def get_consent_token( + async def get_consent_token( self, consent_id: str, token_id: str, @@ -344,7 +344,7 @@ def get_consent_token( api_path = api_path.replace('{consentId}', str(self._normalize_value(consent_id))) api_path = api_path.replace('{tokenId}', str(self._normalize_value(token_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -356,7 +356,7 @@ def get_consent_token( return self._parse_response(response, model=Oauth2ConsentToken) - def delete_consent_token( + async def delete_consent_token( self, consent_id: str, token_id: str, @@ -390,7 +390,7 @@ def delete_consent_token( api_path = api_path.replace('{consentId}', str(self._normalize_value(consent_id))) api_path = api_path.replace('{tokenId}', str(self._normalize_value(token_id))) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -403,7 +403,7 @@ def delete_consent_token( return response - def update_email( + async def update_email( self, email: str, password: str, @@ -442,7 +442,7 @@ def update_email( api_params['email'] = self._normalize_value(email) api_params['password'] = self._normalize_value(password) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -455,7 +455,7 @@ def update_email( return User.with_data(response, model_type) - def list_identities( + async def list_identities( self, queries: Optional[List[str]] = None, total: Optional[bool] = None, @@ -487,7 +487,7 @@ def list_identities( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -499,7 +499,7 @@ def list_identities( return self._parse_response(response, model=IdentityList) - def delete_identity( + async def delete_identity( self, identity_id: str, ) -> Dict[str, Any]: @@ -527,7 +527,7 @@ def delete_identity( raise AppwriteException('Missing required parameter: "identity_id"') api_path = api_path.replace('{identityId}', str(self._normalize_value(identity_id))) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -540,7 +540,7 @@ def delete_identity( return response - def list_memberships( + async def list_memberships( self, queries: Optional[List[str]] = None, total: Optional[bool] = None, @@ -572,7 +572,7 @@ def list_memberships( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -584,7 +584,7 @@ def list_memberships( return self._parse_response(response, model=MembershipList) - def update_mfa( + async def update_mfa( self, mfa: bool, model_type: Type[T] = dict, @@ -616,7 +616,7 @@ def update_mfa( raise AppwriteException('Missing required parameter: "mfa"') api_params['mfa'] = self._normalize_value(mfa) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -629,7 +629,7 @@ def update_mfa( return User.with_data(response, model_type) - def create_mfa_authenticator( + async def create_mfa_authenticator( self, type: AuthenticatorType, ) -> MfaType: @@ -657,7 +657,7 @@ def create_mfa_authenticator( raise AppwriteException('Missing required parameter: "type"') api_path = api_path.replace('{type}', str(self._normalize_value(type))) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -670,7 +670,7 @@ def create_mfa_authenticator( return self._parse_response(response, model=MfaType) - def update_mfa_authenticator( + async def update_mfa_authenticator( self, type: AuthenticatorType, otp: str, @@ -708,7 +708,7 @@ def update_mfa_authenticator( api_path = api_path.replace('{type}', str(self._normalize_value(type))) api_params['otp'] = self._normalize_value(otp) - response = self.client.call( + response = await self.client.call( 'put', api_path, { @@ -721,7 +721,7 @@ def update_mfa_authenticator( return User.with_data(response, model_type) - def delete_mfa_authenticator( + async def delete_mfa_authenticator( self, type: AuthenticatorType, ) -> Dict[str, Any]: @@ -749,7 +749,7 @@ def delete_mfa_authenticator( raise AppwriteException('Missing required parameter: "type"') api_path = api_path.replace('{type}', str(self._normalize_value(type))) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -762,7 +762,7 @@ def delete_mfa_authenticator( return response - def create_mfa_challenge( + async def create_mfa_challenge( self, factor: AuthenticationFactor, ) -> MfaChallenge: @@ -790,7 +790,7 @@ def create_mfa_challenge( raise AppwriteException('Missing required parameter: "factor"') api_params['factor'] = self._normalize_value(factor) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -803,7 +803,7 @@ def create_mfa_challenge( return self._parse_response(response, model=MfaChallenge) - def update_mfa_challenge( + async def update_mfa_challenge( self, challenge_id: str, otp: str, @@ -837,7 +837,7 @@ def update_mfa_challenge( api_params['challengeId'] = self._normalize_value(challenge_id) api_params['otp'] = self._normalize_value(otp) - response = self.client.call( + response = await self.client.call( 'put', api_path, { @@ -850,7 +850,7 @@ def update_mfa_challenge( return self._parse_response(response, model=Session) - def list_mfa_factors( + async def list_mfa_factors( self, ) -> MfaFactors: """ @@ -869,7 +869,7 @@ def list_mfa_factors( api_path = '/account/mfa/factors' api_params = {} - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -881,7 +881,7 @@ def list_mfa_factors( return self._parse_response(response, model=MfaFactors) - def get_mfa_recovery_codes( + async def get_mfa_recovery_codes( self, ) -> MfaRecoveryCodes: """ @@ -900,7 +900,7 @@ def get_mfa_recovery_codes( api_path = '/account/mfa/recovery-codes' api_params = {} - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -912,7 +912,7 @@ def get_mfa_recovery_codes( return self._parse_response(response, model=MfaRecoveryCodes) - def create_mfa_recovery_codes( + async def create_mfa_recovery_codes( self, ) -> MfaRecoveryCodes: """ @@ -931,7 +931,7 @@ def create_mfa_recovery_codes( api_path = '/account/mfa/recovery-codes' api_params = {} - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -944,7 +944,7 @@ def create_mfa_recovery_codes( return self._parse_response(response, model=MfaRecoveryCodes) - def update_mfa_recovery_codes( + async def update_mfa_recovery_codes( self, ) -> MfaRecoveryCodes: """ @@ -963,7 +963,7 @@ def update_mfa_recovery_codes( api_path = '/account/mfa/recovery-codes' api_params = {} - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -976,7 +976,7 @@ def update_mfa_recovery_codes( return self._parse_response(response, model=MfaRecoveryCodes) - def update_name( + async def update_name( self, name: str, model_type: Type[T] = dict, @@ -1008,7 +1008,7 @@ def update_name( raise AppwriteException('Missing required parameter: "name"') api_params['name'] = self._normalize_value(name) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -1021,7 +1021,7 @@ def update_name( return User.with_data(response, model_type) - def list_passkeys( + async def list_passkeys( self, queries: Optional[List[str]] = None, total: Optional[bool] = None, @@ -1053,7 +1053,7 @@ def list_passkeys( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -1065,7 +1065,7 @@ def list_passkeys( return self._parse_response(response, model=PasskeyList) - def create_passkey( + async def create_passkey( self, passkey_id: Optional[str] = None, name: Optional[str] = None, @@ -1097,7 +1097,7 @@ def create_passkey( if name is not None: api_params['name'] = self._normalize_value(name) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -1110,7 +1110,7 @@ def create_passkey( return self._parse_response(response, model=PasskeyChallenge) - def get_passkey( + async def get_passkey( self, passkey_id: str, ) -> Passkey: @@ -1138,7 +1138,7 @@ def get_passkey( raise AppwriteException('Missing required parameter: "passkey_id"') api_path = api_path.replace('{passkeyId}', str(self._normalize_value(passkey_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -1150,7 +1150,7 @@ def get_passkey( return self._parse_response(response, model=Passkey) - def update_passkey( + async def update_passkey( self, passkey_id: str, name: str, @@ -1184,7 +1184,7 @@ def update_passkey( api_path = api_path.replace('{passkeyId}', str(self._normalize_value(passkey_id))) api_params['name'] = self._normalize_value(name) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -1197,7 +1197,7 @@ def update_passkey( return self._parse_response(response, model=Passkey) - def delete_passkey( + async def delete_passkey( self, passkey_id: str, ) -> Dict[str, Any]: @@ -1225,7 +1225,7 @@ def delete_passkey( raise AppwriteException('Missing required parameter: "passkey_id"') api_path = api_path.replace('{passkeyId}', str(self._normalize_value(passkey_id))) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -1238,7 +1238,7 @@ def delete_passkey( return response - def update_passkey_verification( + async def update_passkey_verification( self, passkey_id: str, credential: Dict[str, Any], @@ -1272,7 +1272,7 @@ def update_passkey_verification( api_path = api_path.replace('{passkeyId}', str(self._normalize_value(passkey_id))) api_params['credential'] = self._normalize_value(credential) - response = self.client.call( + response = await self.client.call( 'put', api_path, { @@ -1285,7 +1285,7 @@ def update_passkey_verification( return self._parse_response(response, model=Passkey) - def update_password( + async def update_password( self, password: str, old_password: Optional[str] = None, @@ -1322,7 +1322,7 @@ def update_password( if old_password is not None: api_params['oldPassword'] = self._normalize_value(old_password) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -1335,7 +1335,7 @@ def update_password( return User.with_data(response, model_type) - def update_phone( + async def update_phone( self, phone: str, password: str, @@ -1373,7 +1373,7 @@ def update_phone( api_params['phone'] = self._normalize_value(phone) api_params['password'] = self._normalize_value(password) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -1386,7 +1386,7 @@ def update_phone( return User.with_data(response, model_type) - def get_prefs( + async def get_prefs( self, model_type: Type[T] = dict, ) -> Preferences[T]: @@ -1412,7 +1412,7 @@ def get_prefs( api_path = '/account/prefs' api_params = {} - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -1424,7 +1424,7 @@ def get_prefs( return Preferences.with_data(response, model_type) - def update_prefs( + async def update_prefs( self, prefs: Dict[str, Any], model_type: Type[T] = dict, @@ -1456,7 +1456,7 @@ def update_prefs( raise AppwriteException('Missing required parameter: "prefs"') api_params['prefs'] = self._normalize_value(prefs) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -1469,7 +1469,7 @@ def update_prefs( return User.with_data(response, model_type) - def create_recovery( + async def create_recovery( self, email: str, url: str, @@ -1503,7 +1503,7 @@ def create_recovery( api_params['email'] = self._normalize_value(email) api_params['url'] = self._normalize_value(url) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -1516,7 +1516,7 @@ def create_recovery( return self._parse_response(response, model=Token) - def update_recovery( + async def update_recovery( self, user_id: str, secret: str, @@ -1560,7 +1560,7 @@ def update_recovery( api_params['secret'] = self._normalize_value(secret) api_params['password'] = self._normalize_value(password) - response = self.client.call( + response = await self.client.call( 'put', api_path, { @@ -1573,7 +1573,7 @@ def update_recovery( return self._parse_response(response, model=Token) - def create_recovery_otp( + async def create_recovery_otp( self, email: str, phrase: Optional[bool] = None, @@ -1608,7 +1608,7 @@ def create_recovery_otp( if phrase is not None: api_params['phrase'] = self._normalize_value(phrase) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -1621,7 +1621,7 @@ def create_recovery_otp( return self._parse_response(response, model=Token) - def update_recovery_otp( + async def update_recovery_otp( self, user_id: str, secret: str, @@ -1663,7 +1663,7 @@ def update_recovery_otp( api_params['secret'] = self._normalize_value(secret) api_params['password'] = self._normalize_value(password) - response = self.client.call( + response = await self.client.call( 'put', api_path, { @@ -1676,7 +1676,7 @@ def update_recovery_otp( return self._parse_response(response, model=Token) - def list_sessions( + async def list_sessions( self, total: Optional[bool] = None, ) -> SessionList: @@ -1703,7 +1703,7 @@ def list_sessions( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -1715,7 +1715,7 @@ def list_sessions( return self._parse_response(response, model=SessionList) - def delete_sessions( + async def delete_sessions( self, current: Optional[bool] = None, ) -> Dict[str, Any]: @@ -1742,7 +1742,7 @@ def delete_sessions( if current is not None: api_params['current'] = self._normalize_value(current) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -1755,7 +1755,7 @@ def delete_sessions( return response - def create_anonymous_session( + async def create_anonymous_session( self, ) -> Session: """ @@ -1774,7 +1774,7 @@ def create_anonymous_session( api_path = '/account/sessions/anonymous' api_params = {} - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -1787,7 +1787,7 @@ def create_anonymous_session( return self._parse_response(response, model=Session) - def create_email_password_session( + async def create_email_password_session( self, email: str, password: str, @@ -1828,7 +1828,7 @@ def create_email_password_session( if duration is not None: api_params['duration'] = self._normalize_value(duration) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -1841,7 +1841,7 @@ def create_email_password_session( return self._parse_response(response, model=Session) - def create_id_token_session( + async def create_id_token_session( self, provider: IdTokenProvider, id_token: str, @@ -1905,7 +1905,7 @@ def create_id_token_session( if name is not None: api_params['name'] = self._normalize_value(name) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -1919,7 +1919,7 @@ def create_id_token_session( return self._parse_response(response, model=Session) @deprecated("This API has been deprecated since 1.6.0. Please use `account.create_session` instead.") - def update_magic_url_session( + async def update_magic_url_session( self, user_id: str, secret: str, @@ -1955,7 +1955,7 @@ def update_magic_url_session( api_params['userId'] = self._normalize_value(user_id) api_params['secret'] = self._normalize_value(secret) - response = self.client.call( + response = await self.client.call( 'put', api_path, { @@ -1969,7 +1969,7 @@ def update_magic_url_session( return self._parse_response(response, model=Session) @deprecated("This API has been deprecated since 1.6.0. Please use `account.create_session` instead.") - def update_phone_session( + async def update_phone_session( self, user_id: str, secret: str, @@ -2005,7 +2005,7 @@ def update_phone_session( api_params['userId'] = self._normalize_value(user_id) api_params['secret'] = self._normalize_value(secret) - response = self.client.call( + response = await self.client.call( 'put', api_path, { @@ -2018,7 +2018,7 @@ def update_phone_session( return self._parse_response(response, model=Session) - def create_session( + async def create_session( self, user_id: str, secret: str, @@ -2052,7 +2052,7 @@ def create_session( api_params['userId'] = self._normalize_value(user_id) api_params['secret'] = self._normalize_value(secret) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -2065,7 +2065,7 @@ def create_session( return self._parse_response(response, model=Session) - def get_session( + async def get_session( self, session_id: str, ) -> Session: @@ -2093,7 +2093,7 @@ def get_session( raise AppwriteException('Missing required parameter: "session_id"') api_path = api_path.replace('{sessionId}', str(self._normalize_value(session_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -2105,7 +2105,7 @@ def get_session( return self._parse_response(response, model=Session) - def update_session( + async def update_session( self, session_id: str, ) -> Session: @@ -2133,7 +2133,7 @@ def update_session( raise AppwriteException('Missing required parameter: "session_id"') api_path = api_path.replace('{sessionId}', str(self._normalize_value(session_id))) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -2146,7 +2146,7 @@ def update_session( return self._parse_response(response, model=Session) - def delete_session( + async def delete_session( self, session_id: str, ) -> Dict[str, Any]: @@ -2174,7 +2174,7 @@ def delete_session( raise AppwriteException('Missing required parameter: "session_id"') api_path = api_path.replace('{sessionId}', str(self._normalize_value(session_id))) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -2187,7 +2187,7 @@ def delete_session( return response - def update_status( + async def update_status( self, model_type: Type[T] = dict, ) -> User[T]: @@ -2213,7 +2213,7 @@ def update_status( api_path = '/account/status' api_params = {} - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -2226,7 +2226,7 @@ def update_status( return User.with_data(response, model_type) - def create_email_token( + async def create_email_token( self, user_id: str, email: str, @@ -2267,7 +2267,7 @@ def create_email_token( if phrase is not None: api_params['phrase'] = self._normalize_value(phrase) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -2280,7 +2280,7 @@ def create_email_token( return self._parse_response(response, model=Token) - def create_magic_url_token( + async def create_magic_url_token( self, user_id: str, email: str, @@ -2326,7 +2326,7 @@ def create_magic_url_token( if phrase is not None: api_params['phrase'] = self._normalize_value(phrase) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -2339,7 +2339,7 @@ def create_magic_url_token( return self._parse_response(response, model=Token) - def create_o_auth2_token( + async def create_o_auth2_token( self, provider: OAuthProvider, success: Optional[str] = None, @@ -2393,7 +2393,7 @@ def create_o_auth2_token( if state is not None: api_params['state'] = self._normalize_value(state) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -2406,7 +2406,7 @@ def create_o_auth2_token( return response - def create_passkey_token( + async def create_passkey_token( self, ) -> PasskeyChallenge: """ @@ -2425,7 +2425,7 @@ def create_passkey_token( api_path = '/account/tokens/passkey' api_params = {} - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -2438,7 +2438,7 @@ def create_passkey_token( return self._parse_response(response, model=PasskeyChallenge) - def update_passkey_token( + async def update_passkey_token( self, challenge_id: str, credential: Dict[str, Any], @@ -2472,7 +2472,7 @@ def update_passkey_token( api_params['challengeId'] = self._normalize_value(challenge_id) api_params['credential'] = self._normalize_value(credential) - response = self.client.call( + response = await self.client.call( 'put', api_path, { @@ -2485,7 +2485,7 @@ def update_passkey_token( return self._parse_response(response, model=TokenSecret) - def create_phone_token( + async def create_phone_token( self, user_id: str, phone: str, @@ -2521,7 +2521,7 @@ def create_phone_token( api_params['userId'] = self._normalize_value(user_id) api_params['phone'] = self._normalize_value(phone) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -2534,7 +2534,7 @@ def create_phone_token( return self._parse_response(response, model=Token) - def create_email_verification( + async def create_email_verification( self, url: str, ) -> Token: @@ -2564,7 +2564,7 @@ def create_email_verification( raise AppwriteException('Missing required parameter: "url"') api_params['url'] = self._normalize_value(url) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -2578,7 +2578,7 @@ def create_email_verification( return self._parse_response(response, model=Token) @deprecated("This API has been deprecated since 1.8.0. Please use `account.create_email_verification` instead.") - def create_verification( + async def create_verification( self, url: str, ) -> Token: @@ -2610,7 +2610,7 @@ def create_verification( raise AppwriteException('Missing required parameter: "url"') api_params['url'] = self._normalize_value(url) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -2623,7 +2623,7 @@ def create_verification( return self._parse_response(response, model=Token) - def update_email_verification( + async def update_email_verification( self, user_id: str, secret: str, @@ -2657,7 +2657,7 @@ def update_email_verification( api_params['userId'] = self._normalize_value(user_id) api_params['secret'] = self._normalize_value(secret) - response = self.client.call( + response = await self.client.call( 'put', api_path, { @@ -2671,7 +2671,7 @@ def update_email_verification( return self._parse_response(response, model=Token) @deprecated("This API has been deprecated since 1.8.0. Please use `account.update_email_verification` instead.") - def update_verification( + async def update_verification( self, user_id: str, secret: str, @@ -2707,7 +2707,7 @@ def update_verification( api_params['userId'] = self._normalize_value(user_id) api_params['secret'] = self._normalize_value(secret) - response = self.client.call( + response = await self.client.call( 'put', api_path, { @@ -2720,7 +2720,7 @@ def update_verification( return self._parse_response(response, model=Token) - def create_email_verification_otp( + async def create_email_verification_otp( self, phrase: Optional[bool] = None, ) -> Token: @@ -2749,7 +2749,7 @@ def create_email_verification_otp( if phrase is not None: api_params['phrase'] = self._normalize_value(phrase) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -2762,7 +2762,7 @@ def create_email_verification_otp( return self._parse_response(response, model=Token) - def update_email_verification_otp( + async def update_email_verification_otp( self, user_id: str, secret: str, @@ -2796,7 +2796,7 @@ def update_email_verification_otp( api_params['userId'] = self._normalize_value(user_id) api_params['secret'] = self._normalize_value(secret) - response = self.client.call( + response = await self.client.call( 'put', api_path, { @@ -2809,7 +2809,7 @@ def update_email_verification_otp( return self._parse_response(response, model=Token) - def create_phone_verification( + async def create_phone_verification( self, ) -> Token: """ @@ -2828,7 +2828,7 @@ def create_phone_verification( api_path = '/account/verifications/phone' api_params = {} - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -2841,7 +2841,7 @@ def create_phone_verification( return self._parse_response(response, model=Token) - def update_phone_verification( + async def update_phone_verification( self, user_id: str, secret: str, @@ -2875,7 +2875,7 @@ def update_phone_verification( api_params['userId'] = self._normalize_value(user_id) api_params['secret'] = self._normalize_value(secret) - response = self.client.call( + response = await self.client.call( 'put', api_path, { diff --git a/appwrite/services/activities.py b/appwrite/services/activities.py index 8556609f..2325aec4 100644 --- a/appwrite/services/activities.py +++ b/appwrite/services/activities.py @@ -12,7 +12,7 @@ class Activities(Service): def __init__(self, client) -> None: super(Activities, self).__init__(client) - def list_events( + async def list_events( self, queries: Optional[List[str]] = None, total: Optional[bool] = None, @@ -44,7 +44,7 @@ def list_events( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -56,7 +56,7 @@ def list_events( return self._parse_response(response, model=ActivityEventList) - def get_event( + async def get_event( self, event_id: str, ) -> ActivityEvent: @@ -84,7 +84,7 @@ def get_event( raise AppwriteException('Missing required parameter: "event_id"') api_path = api_path.replace('{eventId}', str(self._normalize_value(event_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { diff --git a/appwrite/services/advisor.py b/appwrite/services/advisor.py index 194d0b7a..4660bb4e 100644 --- a/appwrite/services/advisor.py +++ b/appwrite/services/advisor.py @@ -14,7 +14,7 @@ class Advisor(Service): def __init__(self, client) -> None: super(Advisor, self).__init__(client) - def list_reports( + async def list_reports( self, queries: Optional[List[str]] = None, total: Optional[bool] = None, @@ -46,7 +46,7 @@ def list_reports( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -58,7 +58,7 @@ def list_reports( return self._parse_response(response, model=ReportList) - def get_report( + async def get_report( self, report_id: str, ) -> Report: @@ -86,7 +86,7 @@ def get_report( raise AppwriteException('Missing required parameter: "report_id"') api_path = api_path.replace('{reportId}', str(self._normalize_value(report_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -98,7 +98,7 @@ def get_report( return self._parse_response(response, model=Report) - def delete_report( + async def delete_report( self, report_id: str, ) -> Dict[str, Any]: @@ -126,7 +126,7 @@ def delete_report( raise AppwriteException('Missing required parameter: "report_id"') api_path = api_path.replace('{reportId}', str(self._normalize_value(report_id))) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -139,7 +139,7 @@ def delete_report( return response - def list_insights( + async def list_insights( self, report_id: str, queries: Optional[List[str]] = None, @@ -177,7 +177,7 @@ def list_insights( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -189,7 +189,7 @@ def list_insights( return self._parse_response(response, model=InsightList) - def get_insight( + async def get_insight( self, report_id: str, insight_id: str, @@ -223,7 +223,7 @@ def get_insight( api_path = api_path.replace('{reportId}', str(self._normalize_value(report_id))) api_path = api_path.replace('{insightId}', str(self._normalize_value(insight_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { diff --git a/appwrite/services/apps.py b/appwrite/services/apps.py index 6a3439a6..e6940ea9 100644 --- a/appwrite/services/apps.py +++ b/appwrite/services/apps.py @@ -21,7 +21,7 @@ class Apps(Service): def __init__(self, client) -> None: super(Apps, self).__init__(client) - def list( + async def list( self, queries: Optional[List[str]] = None, total: Optional[bool] = None, @@ -53,7 +53,7 @@ def list( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -65,7 +65,7 @@ def list( return self._parse_response(response, model=AppsList) - def create( + async def create( self, app_id: str, name: str, @@ -185,7 +185,7 @@ def create( if team_id is not None: api_params['teamId'] = self._normalize_value(team_id) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -198,7 +198,7 @@ def create( return self._parse_response(response, model=App) - def list_installation_scopes( + async def list_installation_scopes( self, ) -> AppScopeList: """ @@ -217,7 +217,7 @@ def list_installation_scopes( api_path = '/apps/scopes/installations' api_params = {} - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -229,7 +229,7 @@ def list_installation_scopes( return self._parse_response(response, model=AppScopeList) - def list_o_auth2_scopes( + async def list_o_auth2_scopes( self, ) -> AppScopeList: """ @@ -248,7 +248,7 @@ def list_o_auth2_scopes( api_path = '/apps/scopes/oauth2' api_params = {} - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -260,7 +260,7 @@ def list_o_auth2_scopes( return self._parse_response(response, model=AppScopeList) - def get( + async def get( self, app_id: str, ) -> App: @@ -288,7 +288,7 @@ def get( raise AppwriteException('Missing required parameter: "app_id"') api_path = api_path.replace('{appId}', str(self._normalize_value(app_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -300,7 +300,7 @@ def get( return self._parse_response(response, model=App) - def update( + async def update( self, app_id: str, name: str, @@ -424,7 +424,7 @@ def update( if installation_redirect_url is not None: api_params['installationRedirectUrl'] = self._normalize_value(installation_redirect_url) - response = self.client.call( + response = await self.client.call( 'put', api_path, { @@ -437,7 +437,7 @@ def update( return self._parse_response(response, model=App) - def delete( + async def delete( self, app_id: str, ) -> Dict[str, Any]: @@ -465,7 +465,7 @@ def delete( raise AppwriteException('Missing required parameter: "app_id"') api_path = api_path.replace('{appId}', str(self._normalize_value(app_id))) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -478,7 +478,7 @@ def delete( return response - def list_installations( + async def list_installations( self, app_id: str, queries: Optional[List[str]] = None, @@ -516,7 +516,7 @@ def list_installations( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -528,7 +528,7 @@ def list_installations( return self._parse_response(response, model=AppInstallationList) - def get_installation( + async def get_installation( self, app_id: str, installation_id: str, @@ -562,7 +562,7 @@ def get_installation( api_path = api_path.replace('{appId}', str(self._normalize_value(app_id))) api_path = api_path.replace('{installationId}', str(self._normalize_value(installation_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -574,7 +574,7 @@ def get_installation( return self._parse_response(response, model=AppInstallation) - def delete_installation( + async def delete_installation( self, app_id: str, installation_id: str, @@ -608,7 +608,7 @@ def delete_installation( api_path = api_path.replace('{appId}', str(self._normalize_value(app_id))) api_path = api_path.replace('{installationId}', str(self._normalize_value(installation_id))) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -621,7 +621,7 @@ def delete_installation( return response - def create_installation_token( + async def create_installation_token( self, app_id: str, installation_id: str, @@ -655,7 +655,7 @@ def create_installation_token( api_path = api_path.replace('{appId}', str(self._normalize_value(app_id))) api_path = api_path.replace('{installationId}', str(self._normalize_value(installation_id))) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -668,7 +668,7 @@ def create_installation_token( return self._parse_response(response, model=Oauth2Token) - def list_keys( + async def list_keys( self, app_id: str, queries: Optional[List[str]] = None, @@ -706,7 +706,7 @@ def list_keys( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -718,7 +718,7 @@ def list_keys( return self._parse_response(response, model=AppKeyList) - def create_key( + async def create_key( self, app_id: str, ) -> AppKey: @@ -746,7 +746,7 @@ def create_key( raise AppwriteException('Missing required parameter: "app_id"') api_path = api_path.replace('{appId}', str(self._normalize_value(app_id))) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -759,7 +759,7 @@ def create_key( return self._parse_response(response, model=AppKey) - def get_key( + async def get_key( self, app_id: str, key_id: str, @@ -793,7 +793,7 @@ def get_key( api_path = api_path.replace('{appId}', str(self._normalize_value(app_id))) api_path = api_path.replace('{keyId}', str(self._normalize_value(key_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -805,7 +805,7 @@ def get_key( return self._parse_response(response, model=AppKey) - def delete_key( + async def delete_key( self, app_id: str, key_id: str, @@ -839,7 +839,7 @@ def delete_key( api_path = api_path.replace('{appId}', str(self._normalize_value(app_id))) api_path = api_path.replace('{keyId}', str(self._normalize_value(key_id))) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -852,7 +852,7 @@ def delete_key( return response - def update_labels( + async def update_labels( self, app_id: str, labels: List[str], @@ -886,7 +886,7 @@ def update_labels( api_path = api_path.replace('{appId}', str(self._normalize_value(app_id))) api_params['labels'] = self._normalize_value(labels) - response = self.client.call( + response = await self.client.call( 'put', api_path, { @@ -899,7 +899,7 @@ def update_labels( return self._parse_response(response, model=App) - def list_secrets( + async def list_secrets( self, app_id: str, queries: Optional[List[str]] = None, @@ -937,7 +937,7 @@ def list_secrets( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -949,7 +949,7 @@ def list_secrets( return self._parse_response(response, model=AppSecretList) - def create_secret( + async def create_secret( self, app_id: str, ) -> AppSecretPlaintext: @@ -977,7 +977,7 @@ def create_secret( raise AppwriteException('Missing required parameter: "app_id"') api_path = api_path.replace('{appId}', str(self._normalize_value(app_id))) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -990,7 +990,7 @@ def create_secret( return self._parse_response(response, model=AppSecretPlaintext) - def get_secret( + async def get_secret( self, app_id: str, secret_id: str, @@ -1024,7 +1024,7 @@ def get_secret( api_path = api_path.replace('{appId}', str(self._normalize_value(app_id))) api_path = api_path.replace('{secretId}', str(self._normalize_value(secret_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -1036,7 +1036,7 @@ def get_secret( return self._parse_response(response, model=AppSecret) - def delete_secret( + async def delete_secret( self, app_id: str, secret_id: str, @@ -1070,7 +1070,7 @@ def delete_secret( api_path = api_path.replace('{appId}', str(self._normalize_value(app_id))) api_path = api_path.replace('{secretId}', str(self._normalize_value(secret_id))) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -1083,7 +1083,7 @@ def delete_secret( return response - def update_team( + async def update_team( self, app_id: str, team_id: str, @@ -1117,7 +1117,7 @@ def update_team( api_path = api_path.replace('{appId}', str(self._normalize_value(app_id))) api_params['teamId'] = self._normalize_value(team_id) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -1130,7 +1130,7 @@ def update_team( return self._parse_response(response, model=App) - def delete_tokens( + async def delete_tokens( self, app_id: str, ) -> Dict[str, Any]: @@ -1158,7 +1158,7 @@ def delete_tokens( raise AppwriteException('Missing required parameter: "app_id"') api_path = api_path.replace('{appId}', str(self._normalize_value(app_id))) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { diff --git a/appwrite/services/avatars.py b/appwrite/services/avatars.py index a01b4baf..f71666ea 100644 --- a/appwrite/services/avatars.py +++ b/appwrite/services/avatars.py @@ -21,7 +21,7 @@ class Avatars(Service): def __init__(self, client) -> None: super(Avatars, self).__init__(client) - def get_browser( + async def get_browser( self, code: Browser, width: Optional[float] = None, @@ -66,7 +66,7 @@ def get_browser( if quality is not None: api_params['quality'] = self._normalize_value(quality) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -78,7 +78,7 @@ def get_browser( return response - def get_credit_card( + async def get_credit_card( self, code: CreditCard, width: Optional[float] = None, @@ -123,7 +123,7 @@ def get_credit_card( if quality is not None: api_params['quality'] = self._normalize_value(quality) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -135,7 +135,7 @@ def get_credit_card( return response - def get_favicon( + async def get_favicon( self, url: str, ) -> bytes: @@ -165,7 +165,7 @@ def get_favicon( raise AppwriteException('Missing required parameter: "url"') api_params['url'] = self._normalize_value(url) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -177,7 +177,7 @@ def get_favicon( return response - def get_flag( + async def get_flag( self, code: Flag, width: Optional[float] = None, @@ -222,7 +222,7 @@ def get_flag( if quality is not None: api_params['quality'] = self._normalize_value(quality) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -234,7 +234,7 @@ def get_flag( return response - def get_image( + async def get_image( self, url: str, width: Optional[float] = None, @@ -276,7 +276,7 @@ def get_image( if height is not None: api_params['height'] = self._normalize_value(height) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -288,7 +288,7 @@ def get_image( return response - def get_initials( + async def get_initials( self, name: Optional[str] = None, width: Optional[float] = None, @@ -334,7 +334,7 @@ def get_initials( if background is not None: api_params['background'] = self._normalize_value(background) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -346,7 +346,7 @@ def get_initials( return response - def get_photo( + async def get_photo( self, width: Optional[float] = None, height: Optional[float] = None, @@ -410,7 +410,7 @@ def get_photo( if name is not None: api_params['name'] = self._normalize_value(name) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -422,7 +422,7 @@ def get_photo( return response - def update_photo( + async def update_photo( self, file: InputFile, on_progress=None, @@ -462,7 +462,7 @@ def update_photo( upload_id = '' - response = self.client.chunked_upload( + response = await self.client.chunked_upload( api_path, { 'X-Appwrite-Project': self.client.get_config('project'), @@ -478,7 +478,7 @@ def update_photo( return Account.with_data(response, model_type) - def delete_photo( + async def delete_photo( self, ) -> Dict[str, Any]: """ @@ -497,7 +497,7 @@ def delete_photo( api_path = '/avatars/photo' api_params = {} - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -510,7 +510,7 @@ def delete_photo( return response - def get_qr( + async def get_qr( self, text: str, size: Optional[float] = None, @@ -553,7 +553,7 @@ def get_qr( if download is not None: api_params['download'] = self._normalize_value(download) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -565,7 +565,7 @@ def get_qr( return response - def get_screenshot( + async def get_screenshot( self, url: str, headers: Optional[Dict[str, Any]] = None, @@ -692,7 +692,7 @@ def get_screenshot( if output is not None: api_params['output'] = self._normalize_value(output) - response = self.client.call( + response = await self.client.call( 'get', api_path, { diff --git a/appwrite/services/backups.py b/appwrite/services/backups.py index b33b009c..19933aea 100644 --- a/appwrite/services/backups.py +++ b/appwrite/services/backups.py @@ -17,7 +17,7 @@ class Backups(Service): def __init__(self, client) -> None: super(Backups, self).__init__(client) - def list_archives( + async def list_archives( self, queries: Optional[List[str]] = None, total: Optional[bool] = None, @@ -49,7 +49,7 @@ def list_archives( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -61,7 +61,7 @@ def list_archives( return self._parse_response(response, model=BackupArchiveList) - def create_archive( + async def create_archive( self, services: List[BackupServices], resource_id: Optional[str] = None, @@ -94,7 +94,7 @@ def create_archive( if resource_id is not None: api_params['resourceId'] = self._normalize_value(resource_id) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -107,7 +107,7 @@ def create_archive( return self._parse_response(response, model=BackupArchive) - def get_archive( + async def get_archive( self, archive_id: str, ) -> BackupArchive: @@ -135,7 +135,7 @@ def get_archive( raise AppwriteException('Missing required parameter: "archive_id"') api_path = api_path.replace('{archiveId}', str(self._normalize_value(archive_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -147,7 +147,7 @@ def get_archive( return self._parse_response(response, model=BackupArchive) - def delete_archive( + async def delete_archive( self, archive_id: str, ) -> Dict[str, Any]: @@ -175,7 +175,7 @@ def delete_archive( raise AppwriteException('Missing required parameter: "archive_id"') api_path = api_path.replace('{archiveId}', str(self._normalize_value(archive_id))) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -188,7 +188,7 @@ def delete_archive( return response - def list_policies( + async def list_policies( self, queries: Optional[List[str]] = None, total: Optional[bool] = None, @@ -220,7 +220,7 @@ def list_policies( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -232,7 +232,7 @@ def list_policies( return self._parse_response(response, model=BackupPolicyList) - def create_policy( + async def create_policy( self, policy_id: str, services: List[BackupServices], @@ -293,7 +293,7 @@ def create_policy( api_params['retention'] = self._normalize_value(retention) api_params['schedule'] = self._normalize_value(schedule) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -306,7 +306,7 @@ def create_policy( return self._parse_response(response, model=BackupPolicy) - def get_policy( + async def get_policy( self, policy_id: str, ) -> BackupPolicy: @@ -334,7 +334,7 @@ def get_policy( raise AppwriteException('Missing required parameter: "policy_id"') api_path = api_path.replace('{policyId}', str(self._normalize_value(policy_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -346,7 +346,7 @@ def get_policy( return self._parse_response(response, model=BackupPolicy) - def update_policy( + async def update_policy( self, policy_id: str, name: Optional[str] = None, @@ -394,7 +394,7 @@ def update_policy( if enabled is not None: api_params['enabled'] = self._normalize_value(enabled) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -407,7 +407,7 @@ def update_policy( return self._parse_response(response, model=BackupPolicy) - def delete_policy( + async def delete_policy( self, policy_id: str, ) -> Dict[str, Any]: @@ -435,7 +435,7 @@ def delete_policy( raise AppwriteException('Missing required parameter: "policy_id"') api_path = api_path.replace('{policyId}', str(self._normalize_value(policy_id))) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -448,7 +448,7 @@ def delete_policy( return response - def create_restoration( + async def create_restoration( self, archive_id: str, services: List[BackupServices], @@ -500,7 +500,7 @@ def create_restoration( if new_resource_name is not None: api_params['newResourceName'] = self._normalize_value(new_resource_name) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -513,7 +513,7 @@ def create_restoration( return self._parse_response(response, model=BackupRestoration) - def list_restorations( + async def list_restorations( self, queries: Optional[List[str]] = None, total: Optional[bool] = None, @@ -545,7 +545,7 @@ def list_restorations( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -557,7 +557,7 @@ def list_restorations( return self._parse_response(response, model=BackupRestorationList) - def get_restoration( + async def get_restoration( self, restoration_id: str, ) -> BackupRestoration: @@ -585,7 +585,7 @@ def get_restoration( raise AppwriteException('Missing required parameter: "restoration_id"') api_path = api_path.replace('{restorationId}', str(self._normalize_value(restoration_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { diff --git a/appwrite/services/databases.py b/appwrite/services/databases.py index 179b6b20..9f8637ae 100644 --- a/appwrite/services/databases.py +++ b/appwrite/services/databases.py @@ -46,7 +46,7 @@ def __init__(self, client) -> None: super(Databases, self).__init__(client) @deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.list` instead.") - def list( + async def list( self, queries: Optional[List[str]] = None, search: Optional[str] = None, @@ -85,7 +85,7 @@ def list( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -98,7 +98,7 @@ def list( return self._parse_response(response, model=DatabaseList) @deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.create` instead.") - def create( + async def create( self, database_id: str, name: str, @@ -144,7 +144,7 @@ def create( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -158,7 +158,7 @@ def create( return self._parse_response(response, model=Database) @deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.list_transactions` instead.") - def list_transactions( + async def list_transactions( self, queries: Optional[List[str]] = None, total: Optional[bool] = None, @@ -192,7 +192,7 @@ def list_transactions( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -205,7 +205,7 @@ def list_transactions( return self._parse_response(response, model=TransactionList) @deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.create_transaction` instead.") - def create_transaction( + async def create_transaction( self, ttl: Optional[float] = None, ) -> Transaction: @@ -234,7 +234,7 @@ def create_transaction( if ttl is not None: api_params['ttl'] = self._normalize_value(ttl) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -248,7 +248,7 @@ def create_transaction( return self._parse_response(response, model=Transaction) @deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.get_transaction` instead.") - def get_transaction( + async def get_transaction( self, transaction_id: str, ) -> Transaction: @@ -278,7 +278,7 @@ def get_transaction( raise AppwriteException('Missing required parameter: "transaction_id"') api_path = api_path.replace('{transactionId}', str(self._normalize_value(transaction_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -291,7 +291,7 @@ def get_transaction( return self._parse_response(response, model=Transaction) @deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.update_transaction` instead.") - def update_transaction( + async def update_transaction( self, transaction_id: str, commit: Optional[bool] = None, @@ -331,7 +331,7 @@ def update_transaction( if rollback is not None: api_params['rollback'] = self._normalize_value(rollback) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -345,7 +345,7 @@ def update_transaction( return self._parse_response(response, model=Transaction) @deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.delete_transaction` instead.") - def delete_transaction( + async def delete_transaction( self, transaction_id: str, ) -> Dict[str, Any]: @@ -375,7 +375,7 @@ def delete_transaction( raise AppwriteException('Missing required parameter: "transaction_id"') api_path = api_path.replace('{transactionId}', str(self._normalize_value(transaction_id))) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -389,7 +389,7 @@ def delete_transaction( return response @deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.create_operations` instead.") - def create_operations( + async def create_operations( self, transaction_id: str, operations: Optional[List[Dict[str, Any]]] = None, @@ -424,7 +424,7 @@ def create_operations( if operations is not None: api_params['operations'] = self._normalize_value(operations) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -438,7 +438,7 @@ def create_operations( return self._parse_response(response, model=Transaction) @deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.get` instead.") - def get( + async def get( self, database_id: str, ) -> Database: @@ -468,7 +468,7 @@ def get( raise AppwriteException('Missing required parameter: "database_id"') api_path = api_path.replace('{databaseId}', str(self._normalize_value(database_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -481,7 +481,7 @@ def get( return self._parse_response(response, model=Database) @deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.update` instead.") - def update( + async def update( self, database_id: str, name: Optional[str] = None, @@ -526,7 +526,7 @@ def update( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'put', api_path, { @@ -540,7 +540,7 @@ def update( return self._parse_response(response, model=Database) @deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.delete` instead.") - def delete( + async def delete( self, database_id: str, ) -> Dict[str, Any]: @@ -570,7 +570,7 @@ def delete( raise AppwriteException('Missing required parameter: "database_id"') api_path = api_path.replace('{databaseId}', str(self._normalize_value(database_id))) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -584,7 +584,7 @@ def delete( return response @deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.list_tables` instead.") - def list_collections( + async def list_collections( self, database_id: str, queries: Optional[List[str]] = None, @@ -629,7 +629,7 @@ def list_collections( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -642,7 +642,7 @@ def list_collections( return self._parse_response(response, model=CollectionList) @deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.create_table` instead.") - def create_collection( + async def create_collection( self, database_id: str, collection_id: str, @@ -714,7 +714,7 @@ def create_collection( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -728,7 +728,7 @@ def create_collection( return self._parse_response(response, model=Collection) @deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.get_table` instead.") - def get_collection( + async def get_collection( self, database_id: str, collection_id: str, @@ -764,7 +764,7 @@ def get_collection( api_path = api_path.replace('{databaseId}', str(self._normalize_value(database_id))) api_path = api_path.replace('{collectionId}', str(self._normalize_value(collection_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -777,7 +777,7 @@ def get_collection( return self._parse_response(response, model=Collection) @deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.update_table` instead.") - def update_collection( + async def update_collection( self, database_id: str, collection_id: str, @@ -843,7 +843,7 @@ def update_collection( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'put', api_path, { @@ -857,7 +857,7 @@ def update_collection( return self._parse_response(response, model=Collection) @deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.delete_table` instead.") - def delete_collection( + async def delete_collection( self, database_id: str, collection_id: str, @@ -893,7 +893,7 @@ def delete_collection( api_path = api_path.replace('{databaseId}', str(self._normalize_value(database_id))) api_path = api_path.replace('{collectionId}', str(self._normalize_value(collection_id))) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -907,7 +907,7 @@ def delete_collection( return response @deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.list_columns` instead.") - def list_attributes( + async def list_attributes( self, database_id: str, collection_id: str, @@ -953,7 +953,7 @@ def list_attributes( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -966,7 +966,7 @@ def list_attributes( return self._parse_response(response, model=AttributeList) @deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.create_big_int_column` instead.") - def create_big_int_attribute( + async def create_big_int_attribute( self, database_id: str, collection_id: str, @@ -1039,7 +1039,7 @@ def create_big_int_attribute( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -1053,7 +1053,7 @@ def create_big_int_attribute( return self._parse_response(response, model=AttributeBigint) @deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.update_big_int_column` instead.") - def update_big_int_attribute( + async def update_big_int_attribute( self, database_id: str, collection_id: str, @@ -1125,7 +1125,7 @@ def update_big_int_attribute( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -1139,7 +1139,7 @@ def update_big_int_attribute( return self._parse_response(response, model=AttributeBigint) @deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.create_boolean_column` instead.") - def create_boolean_attribute( + async def create_boolean_attribute( self, database_id: str, collection_id: str, @@ -1202,7 +1202,7 @@ def create_boolean_attribute( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -1216,7 +1216,7 @@ def create_boolean_attribute( return self._parse_response(response, model=AttributeBoolean) @deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.update_boolean_column` instead.") - def update_boolean_attribute( + async def update_boolean_attribute( self, database_id: str, collection_id: str, @@ -1278,7 +1278,7 @@ def update_boolean_attribute( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -1292,7 +1292,7 @@ def update_boolean_attribute( return self._parse_response(response, model=AttributeBoolean) @deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.create_datetime_column` instead.") - def create_datetime_attribute( + async def create_datetime_attribute( self, database_id: str, collection_id: str, @@ -1355,7 +1355,7 @@ def create_datetime_attribute( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -1369,7 +1369,7 @@ def create_datetime_attribute( return self._parse_response(response, model=AttributeDatetime) @deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.update_datetime_column` instead.") - def update_datetime_attribute( + async def update_datetime_attribute( self, database_id: str, collection_id: str, @@ -1431,7 +1431,7 @@ def update_datetime_attribute( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -1445,7 +1445,7 @@ def update_datetime_attribute( return self._parse_response(response, model=AttributeDatetime) @deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.create_email_column` instead.") - def create_email_attribute( + async def create_email_attribute( self, database_id: str, collection_id: str, @@ -1508,7 +1508,7 @@ def create_email_attribute( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -1522,7 +1522,7 @@ def create_email_attribute( return self._parse_response(response, model=AttributeEmail) @deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.update_email_column` instead.") - def update_email_attribute( + async def update_email_attribute( self, database_id: str, collection_id: str, @@ -1584,7 +1584,7 @@ def update_email_attribute( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -1598,7 +1598,7 @@ def update_email_attribute( return self._parse_response(response, model=AttributeEmail) @deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.create_enum_column` instead.") - def create_enum_attribute( + async def create_enum_attribute( self, database_id: str, collection_id: str, @@ -1667,7 +1667,7 @@ def create_enum_attribute( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -1681,7 +1681,7 @@ def create_enum_attribute( return self._parse_response(response, model=AttributeEnum) @deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.update_enum_column` instead.") - def update_enum_attribute( + async def update_enum_attribute( self, database_id: str, collection_id: str, @@ -1749,7 +1749,7 @@ def update_enum_attribute( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -1763,7 +1763,7 @@ def update_enum_attribute( return self._parse_response(response, model=AttributeEnum) @deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.create_float_column` instead.") - def create_float_attribute( + async def create_float_attribute( self, database_id: str, collection_id: str, @@ -1836,7 +1836,7 @@ def create_float_attribute( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -1850,7 +1850,7 @@ def create_float_attribute( return self._parse_response(response, model=AttributeFloat) @deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.update_float_column` instead.") - def update_float_attribute( + async def update_float_attribute( self, database_id: str, collection_id: str, @@ -1922,7 +1922,7 @@ def update_float_attribute( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -1936,7 +1936,7 @@ def update_float_attribute( return self._parse_response(response, model=AttributeFloat) @deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.create_integer_column` instead.") - def create_integer_attribute( + async def create_integer_attribute( self, database_id: str, collection_id: str, @@ -2009,7 +2009,7 @@ def create_integer_attribute( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -2023,7 +2023,7 @@ def create_integer_attribute( return self._parse_response(response, model=AttributeInteger) @deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.update_integer_column` instead.") - def update_integer_attribute( + async def update_integer_attribute( self, database_id: str, collection_id: str, @@ -2095,7 +2095,7 @@ def update_integer_attribute( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -2109,7 +2109,7 @@ def update_integer_attribute( return self._parse_response(response, model=AttributeInteger) @deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.create_ip_column` instead.") - def create_ip_attribute( + async def create_ip_attribute( self, database_id: str, collection_id: str, @@ -2172,7 +2172,7 @@ def create_ip_attribute( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -2186,7 +2186,7 @@ def create_ip_attribute( return self._parse_response(response, model=AttributeIp) @deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.update_ip_column` instead.") - def update_ip_attribute( + async def update_ip_attribute( self, database_id: str, collection_id: str, @@ -2248,7 +2248,7 @@ def update_ip_attribute( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -2262,7 +2262,7 @@ def update_ip_attribute( return self._parse_response(response, model=AttributeIp) @deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.create_line_column` instead.") - def create_line_attribute( + async def create_line_attribute( self, database_id: str, collection_id: str, @@ -2320,7 +2320,7 @@ def create_line_attribute( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -2334,7 +2334,7 @@ def create_line_attribute( return self._parse_response(response, model=AttributeLine) @deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.update_line_column` instead.") - def update_line_attribute( + async def update_line_attribute( self, database_id: str, collection_id: str, @@ -2397,7 +2397,7 @@ def update_line_attribute( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -2411,7 +2411,7 @@ def update_line_attribute( return self._parse_response(response, model=AttributeLine) @deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.create_longtext_column` instead.") - def create_longtext_attribute( + async def create_longtext_attribute( self, database_id: str, collection_id: str, @@ -2479,7 +2479,7 @@ def create_longtext_attribute( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -2493,7 +2493,7 @@ def create_longtext_attribute( return self._parse_response(response, model=AttributeLongtext) @deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.update_longtext_column` instead.") - def update_longtext_attribute( + async def update_longtext_attribute( self, database_id: str, collection_id: str, @@ -2555,7 +2555,7 @@ def update_longtext_attribute( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -2569,7 +2569,7 @@ def update_longtext_attribute( return self._parse_response(response, model=AttributeLongtext) @deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.create_mediumtext_column` instead.") - def create_mediumtext_attribute( + async def create_mediumtext_attribute( self, database_id: str, collection_id: str, @@ -2637,7 +2637,7 @@ def create_mediumtext_attribute( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -2651,7 +2651,7 @@ def create_mediumtext_attribute( return self._parse_response(response, model=AttributeMediumtext) @deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.update_mediumtext_column` instead.") - def update_mediumtext_attribute( + async def update_mediumtext_attribute( self, database_id: str, collection_id: str, @@ -2713,7 +2713,7 @@ def update_mediumtext_attribute( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -2727,7 +2727,7 @@ def update_mediumtext_attribute( return self._parse_response(response, model=AttributeMediumtext) @deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.create_point_column` instead.") - def create_point_attribute( + async def create_point_attribute( self, database_id: str, collection_id: str, @@ -2785,7 +2785,7 @@ def create_point_attribute( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -2799,7 +2799,7 @@ def create_point_attribute( return self._parse_response(response, model=AttributePoint) @deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.update_point_column` instead.") - def update_point_attribute( + async def update_point_attribute( self, database_id: str, collection_id: str, @@ -2862,7 +2862,7 @@ def update_point_attribute( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -2876,7 +2876,7 @@ def update_point_attribute( return self._parse_response(response, model=AttributePoint) @deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.create_polygon_column` instead.") - def create_polygon_attribute( + async def create_polygon_attribute( self, database_id: str, collection_id: str, @@ -2934,7 +2934,7 @@ def create_polygon_attribute( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -2948,7 +2948,7 @@ def create_polygon_attribute( return self._parse_response(response, model=AttributePolygon) @deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.update_polygon_column` instead.") - def update_polygon_attribute( + async def update_polygon_attribute( self, database_id: str, collection_id: str, @@ -3011,7 +3011,7 @@ def update_polygon_attribute( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -3025,7 +3025,7 @@ def update_polygon_attribute( return self._parse_response(response, model=AttributePolygon) @deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.create_relationship_column` instead.") - def create_relationship_attribute( + async def create_relationship_attribute( self, database_id: str, collection_id: str, @@ -3098,7 +3098,7 @@ def create_relationship_attribute( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -3112,7 +3112,7 @@ def create_relationship_attribute( return self._parse_response(response, model=AttributeRelationship) @deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.update_relationship_column` instead.") - def update_relationship_attribute( + async def update_relationship_attribute( self, database_id: str, collection_id: str, @@ -3169,7 +3169,7 @@ def update_relationship_attribute( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -3183,7 +3183,7 @@ def update_relationship_attribute( return self._parse_response(response, model=AttributeRelationship) @deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.create_string_column` instead.") - def create_string_attribute( + async def create_string_attribute( self, database_id: str, collection_id: str, @@ -3257,7 +3257,7 @@ def create_string_attribute( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -3271,7 +3271,7 @@ def create_string_attribute( return self._parse_response(response, model=AttributeString) @deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.update_string_column` instead.") - def update_string_attribute( + async def update_string_attribute( self, database_id: str, collection_id: str, @@ -3338,7 +3338,7 @@ def update_string_attribute( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -3352,7 +3352,7 @@ def update_string_attribute( return self._parse_response(response, model=AttributeString) @deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.create_text_column` instead.") - def create_text_attribute( + async def create_text_attribute( self, database_id: str, collection_id: str, @@ -3420,7 +3420,7 @@ def create_text_attribute( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -3434,7 +3434,7 @@ def create_text_attribute( return self._parse_response(response, model=AttributeText) @deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.update_text_column` instead.") - def update_text_attribute( + async def update_text_attribute( self, database_id: str, collection_id: str, @@ -3496,7 +3496,7 @@ def update_text_attribute( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -3510,7 +3510,7 @@ def update_text_attribute( return self._parse_response(response, model=AttributeText) @deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.create_url_column` instead.") - def create_url_attribute( + async def create_url_attribute( self, database_id: str, collection_id: str, @@ -3573,7 +3573,7 @@ def create_url_attribute( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -3587,7 +3587,7 @@ def create_url_attribute( return self._parse_response(response, model=AttributeUrl) @deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.update_url_column` instead.") - def update_url_attribute( + async def update_url_attribute( self, database_id: str, collection_id: str, @@ -3649,7 +3649,7 @@ def update_url_attribute( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -3663,7 +3663,7 @@ def update_url_attribute( return self._parse_response(response, model=AttributeUrl) @deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.create_varchar_column` instead.") - def create_varchar_attribute( + async def create_varchar_attribute( self, database_id: str, collection_id: str, @@ -3737,7 +3737,7 @@ def create_varchar_attribute( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -3751,7 +3751,7 @@ def create_varchar_attribute( return self._parse_response(response, model=AttributeVarchar) @deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.update_varchar_column` instead.") - def update_varchar_attribute( + async def update_varchar_attribute( self, database_id: str, collection_id: str, @@ -3818,7 +3818,7 @@ def update_varchar_attribute( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -3832,7 +3832,7 @@ def update_varchar_attribute( return self._parse_response(response, model=AttributeVarchar) @deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.get_column` instead.") - def get_attribute( + async def get_attribute( self, database_id: str, collection_id: str, @@ -3893,7 +3893,7 @@ def get_attribute( api_path = api_path.replace('{collectionId}', str(self._normalize_value(collection_id))) api_path = api_path.replace('{key}', str(self._normalize_value(key))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -3962,7 +3962,7 @@ def get_attribute( raise AppwriteException('Unable to match response to any known model') @deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.delete_column` instead.") - def delete_attribute( + async def delete_attribute( self, database_id: str, collection_id: str, @@ -4004,7 +4004,7 @@ def delete_attribute( api_path = api_path.replace('{collectionId}', str(self._normalize_value(collection_id))) api_path = api_path.replace('{key}', str(self._normalize_value(key))) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -4018,7 +4018,7 @@ def delete_attribute( return response @deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.list_rows` instead.") - def list_documents( + async def list_documents( self, database_id: str, collection_id: str, @@ -4080,7 +4080,7 @@ def list_documents( if ttl is not None: api_params['ttl'] = self._normalize_value(ttl) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -4093,7 +4093,7 @@ def list_documents( return DocumentList.with_data(response, model_type) @deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.create_row` instead.") - def create_document( + async def create_document( self, database_id: str, collection_id: str, @@ -4155,7 +4155,7 @@ def create_document( if transaction_id is not None: api_params['transactionId'] = self._normalize_value(transaction_id) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -4169,7 +4169,7 @@ def create_document( return Document.with_data(response, model_type) @deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.create_rows` instead.") - def create_documents( + async def create_documents( self, database_id: str, collection_id: str, @@ -4220,7 +4220,7 @@ def create_documents( if transaction_id is not None: api_params['transactionId'] = self._normalize_value(transaction_id) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -4234,7 +4234,7 @@ def create_documents( return DocumentList.with_data(response, model_type) @deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.upsert_rows` instead.") - def upsert_documents( + async def upsert_documents( self, database_id: str, collection_id: str, @@ -4285,7 +4285,7 @@ def upsert_documents( if transaction_id is not None: api_params['transactionId'] = self._normalize_value(transaction_id) - response = self.client.call( + response = await self.client.call( 'put', api_path, { @@ -4299,7 +4299,7 @@ def upsert_documents( return DocumentList.with_data(response, model_type) @deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.update_rows` instead.") - def update_documents( + async def update_documents( self, database_id: str, collection_id: str, @@ -4354,7 +4354,7 @@ def update_documents( if transaction_id is not None: api_params['transactionId'] = self._normalize_value(transaction_id) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -4368,7 +4368,7 @@ def update_documents( return DocumentList.with_data(response, model_type) @deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.delete_rows` instead.") - def delete_documents( + async def delete_documents( self, database_id: str, collection_id: str, @@ -4418,7 +4418,7 @@ def delete_documents( if transaction_id is not None: api_params['transactionId'] = self._normalize_value(transaction_id) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -4432,7 +4432,7 @@ def delete_documents( return DocumentList.with_data(response, model_type) @deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.create_query` instead.") - def create_query( + async def create_query( self, database_id: str, collection_id: str, @@ -4492,7 +4492,7 @@ def create_query( if ttl is not None: api_params['ttl'] = self._normalize_value(ttl) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -4506,7 +4506,7 @@ def create_query( return DocumentList.with_data(response, model_type) @deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.get_row` instead.") - def get_document( + async def get_document( self, database_id: str, collection_id: str, @@ -4562,7 +4562,7 @@ def get_document( if transaction_id is not None: api_params['transactionId'] = self._normalize_value(transaction_id) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -4575,7 +4575,7 @@ def get_document( return Document.with_data(response, model_type) @deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.upsert_row` instead.") - def upsert_document( + async def upsert_document( self, database_id: str, collection_id: str, @@ -4636,7 +4636,7 @@ def upsert_document( if transaction_id is not None: api_params['transactionId'] = self._normalize_value(transaction_id) - response = self.client.call( + response = await self.client.call( 'put', api_path, { @@ -4650,7 +4650,7 @@ def upsert_document( return Document.with_data(response, model_type) @deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.update_row` instead.") - def update_document( + async def update_document( self, database_id: str, collection_id: str, @@ -4711,7 +4711,7 @@ def update_document( if transaction_id is not None: api_params['transactionId'] = self._normalize_value(transaction_id) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -4725,7 +4725,7 @@ def update_document( return Document.with_data(response, model_type) @deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.delete_row` instead.") - def delete_document( + async def delete_document( self, database_id: str, collection_id: str, @@ -4772,7 +4772,7 @@ def delete_document( if transaction_id is not None: api_params['transactionId'] = self._normalize_value(transaction_id) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -4786,7 +4786,7 @@ def delete_document( return response @deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.decrement_row_column` instead.") - def decrement_document_attribute( + async def decrement_document_attribute( self, database_id: str, collection_id: str, @@ -4853,7 +4853,7 @@ def decrement_document_attribute( if transaction_id is not None: api_params['transactionId'] = self._normalize_value(transaction_id) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -4867,7 +4867,7 @@ def decrement_document_attribute( return Document.with_data(response, model_type) @deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.increment_row_column` instead.") - def increment_document_attribute( + async def increment_document_attribute( self, database_id: str, collection_id: str, @@ -4934,7 +4934,7 @@ def increment_document_attribute( if transaction_id is not None: api_params['transactionId'] = self._normalize_value(transaction_id) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -4948,7 +4948,7 @@ def increment_document_attribute( return Document.with_data(response, model_type) @deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.list_indexes` instead.") - def list_indexes( + async def list_indexes( self, database_id: str, collection_id: str, @@ -4994,7 +4994,7 @@ def list_indexes( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -5007,7 +5007,7 @@ def list_indexes( return self._parse_response(response, model=IndexList) @deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.create_index` instead.") - def create_index( + async def create_index( self, database_id: str, collection_id: str, @@ -5077,7 +5077,7 @@ def create_index( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -5091,7 +5091,7 @@ def create_index( return self._parse_response(response, model=Index) @deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.get_index` instead.") - def get_index( + async def get_index( self, database_id: str, collection_id: str, @@ -5133,7 +5133,7 @@ def get_index( api_path = api_path.replace('{collectionId}', str(self._normalize_value(collection_id))) api_path = api_path.replace('{key}', str(self._normalize_value(key))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -5146,7 +5146,7 @@ def get_index( return self._parse_response(response, model=Index) @deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.delete_index` instead.") - def delete_index( + async def delete_index( self, database_id: str, collection_id: str, @@ -5188,7 +5188,7 @@ def delete_index( api_path = api_path.replace('{collectionId}', str(self._normalize_value(collection_id))) api_path = api_path.replace('{key}', str(self._normalize_value(key))) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { diff --git a/appwrite/services/documents_db.py b/appwrite/services/documents_db.py index 234f2b66..282628f2 100644 --- a/appwrite/services/documents_db.py +++ b/appwrite/services/documents_db.py @@ -29,7 +29,7 @@ class DocumentsDB(Service): def __init__(self, client) -> None: super(DocumentsDB, self).__init__(client) - def list( + async def list( self, queries: Optional[List[str]] = None, total: Optional[bool] = None, @@ -61,7 +61,7 @@ def list( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -73,7 +73,7 @@ def list( return self._parse_response(response, model=DatabaseList) - def create( + async def create( self, database_id: str, name: str, @@ -132,7 +132,7 @@ def create( if sync_mode is not None: api_params['syncMode'] = self._normalize_value(sync_mode) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -145,7 +145,7 @@ def create( return self._parse_response(response, model=Database) - def list_specifications( + async def list_specifications( self, ) -> DedicatedDatabaseSpecificationList: """ @@ -164,7 +164,7 @@ def list_specifications( api_path = '/documentsdb/specifications' api_params = {} - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -176,7 +176,7 @@ def list_specifications( return self._parse_response(response, model=DedicatedDatabaseSpecificationList) - def list_transactions( + async def list_transactions( self, queries: Optional[List[str]] = None, total: Optional[bool] = None, @@ -208,7 +208,7 @@ def list_transactions( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -220,7 +220,7 @@ def list_transactions( return self._parse_response(response, model=TransactionList) - def create_transaction( + async def create_transaction( self, ttl: Optional[float] = None, ) -> Transaction: @@ -247,7 +247,7 @@ def create_transaction( if ttl is not None: api_params['ttl'] = self._normalize_value(ttl) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -260,7 +260,7 @@ def create_transaction( return self._parse_response(response, model=Transaction) - def get_transaction( + async def get_transaction( self, transaction_id: str, ) -> Transaction: @@ -288,7 +288,7 @@ def get_transaction( raise AppwriteException('Missing required parameter: "transaction_id"') api_path = api_path.replace('{transactionId}', str(self._normalize_value(transaction_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -300,7 +300,7 @@ def get_transaction( return self._parse_response(response, model=Transaction) - def update_transaction( + async def update_transaction( self, transaction_id: str, commit: Optional[bool] = None, @@ -338,7 +338,7 @@ def update_transaction( if rollback is not None: api_params['rollback'] = self._normalize_value(rollback) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -351,7 +351,7 @@ def update_transaction( return self._parse_response(response, model=Transaction) - def delete_transaction( + async def delete_transaction( self, transaction_id: str, ) -> Dict[str, Any]: @@ -379,7 +379,7 @@ def delete_transaction( raise AppwriteException('Missing required parameter: "transaction_id"') api_path = api_path.replace('{transactionId}', str(self._normalize_value(transaction_id))) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -392,7 +392,7 @@ def delete_transaction( return response - def create_operations( + async def create_operations( self, transaction_id: str, operations: Optional[List[Dict[str, Any]]] = None, @@ -425,7 +425,7 @@ def create_operations( if operations is not None: api_params['operations'] = self._normalize_value(operations) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -438,7 +438,7 @@ def create_operations( return self._parse_response(response, model=Transaction) - def get( + async def get( self, database_id: str, ) -> Database: @@ -466,7 +466,7 @@ def get( raise AppwriteException('Missing required parameter: "database_id"') api_path = api_path.replace('{databaseId}', str(self._normalize_value(database_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -478,7 +478,7 @@ def get( return self._parse_response(response, model=Database) - def update( + async def update( self, database_id: str, name: str, @@ -537,7 +537,7 @@ def update( if sync_mode is not None: api_params['syncMode'] = self._normalize_value(sync_mode) - response = self.client.call( + response = await self.client.call( 'put', api_path, { @@ -550,7 +550,7 @@ def update( return self._parse_response(response, model=Database) - def delete( + async def delete( self, database_id: str, ) -> Dict[str, Any]: @@ -578,7 +578,7 @@ def delete( raise AppwriteException('Missing required parameter: "database_id"') api_path = api_path.replace('{databaseId}', str(self._normalize_value(database_id))) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -591,7 +591,7 @@ def delete( return response - def list_collections( + async def list_collections( self, database_id: str, queries: Optional[List[str]] = None, @@ -634,7 +634,7 @@ def list_collections( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -646,7 +646,7 @@ def list_collections( return self._parse_response(response, model=CollectionList) - def create_collection( + async def create_collection( self, database_id: str, collection_id: str, @@ -716,7 +716,7 @@ def create_collection( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -729,7 +729,7 @@ def create_collection( return self._parse_response(response, model=Collection) - def get_collection( + async def get_collection( self, database_id: str, collection_id: str, @@ -763,7 +763,7 @@ def get_collection( api_path = api_path.replace('{databaseId}', str(self._normalize_value(database_id))) api_path = api_path.replace('{collectionId}', str(self._normalize_value(collection_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -775,7 +775,7 @@ def get_collection( return self._parse_response(response, model=Collection) - def update_collection( + async def update_collection( self, database_id: str, collection_id: str, @@ -840,7 +840,7 @@ def update_collection( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'put', api_path, { @@ -853,7 +853,7 @@ def update_collection( return self._parse_response(response, model=Collection) - def delete_collection( + async def delete_collection( self, database_id: str, collection_id: str, @@ -887,7 +887,7 @@ def delete_collection( api_path = api_path.replace('{databaseId}', str(self._normalize_value(database_id))) api_path = api_path.replace('{collectionId}', str(self._normalize_value(collection_id))) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -900,7 +900,7 @@ def delete_collection( return response - def list_documents( + async def list_documents( self, database_id: str, collection_id: str, @@ -958,7 +958,7 @@ def list_documents( if ttl is not None: api_params['ttl'] = self._normalize_value(ttl) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -970,7 +970,7 @@ def list_documents( return DocumentList.with_data(response, model_type) - def create_document( + async def create_document( self, database_id: str, collection_id: str, @@ -1030,7 +1030,7 @@ def create_document( if transaction_id is not None: api_params['transactionId'] = self._normalize_value(transaction_id) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -1043,7 +1043,7 @@ def create_document( return Document.with_data(response, model_type) - def create_documents( + async def create_documents( self, database_id: str, collection_id: str, @@ -1092,7 +1092,7 @@ def create_documents( if transaction_id is not None: api_params['transactionId'] = self._normalize_value(transaction_id) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -1105,7 +1105,7 @@ def create_documents( return DocumentList.with_data(response, model_type) - def upsert_documents( + async def upsert_documents( self, database_id: str, collection_id: str, @@ -1154,7 +1154,7 @@ def upsert_documents( if transaction_id is not None: api_params['transactionId'] = self._normalize_value(transaction_id) - response = self.client.call( + response = await self.client.call( 'put', api_path, { @@ -1167,7 +1167,7 @@ def upsert_documents( return DocumentList.with_data(response, model_type) - def update_documents( + async def update_documents( self, database_id: str, collection_id: str, @@ -1220,7 +1220,7 @@ def update_documents( if transaction_id is not None: api_params['transactionId'] = self._normalize_value(transaction_id) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -1233,7 +1233,7 @@ def update_documents( return DocumentList.with_data(response, model_type) - def delete_documents( + async def delete_documents( self, database_id: str, collection_id: str, @@ -1281,7 +1281,7 @@ def delete_documents( if transaction_id is not None: api_params['transactionId'] = self._normalize_value(transaction_id) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -1294,7 +1294,7 @@ def delete_documents( return DocumentList.with_data(response, model_type) - def create_query( + async def create_query( self, database_id: str, collection_id: str, @@ -1352,7 +1352,7 @@ def create_query( if ttl is not None: api_params['ttl'] = self._normalize_value(ttl) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -1365,7 +1365,7 @@ def create_query( return DocumentList.with_data(response, model_type) - def get_document( + async def get_document( self, database_id: str, collection_id: str, @@ -1419,7 +1419,7 @@ def get_document( if transaction_id is not None: api_params['transactionId'] = self._normalize_value(transaction_id) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -1431,7 +1431,7 @@ def get_document( return Document.with_data(response, model_type) - def upsert_document( + async def upsert_document( self, database_id: str, collection_id: str, @@ -1490,7 +1490,7 @@ def upsert_document( if transaction_id is not None: api_params['transactionId'] = self._normalize_value(transaction_id) - response = self.client.call( + response = await self.client.call( 'put', api_path, { @@ -1503,7 +1503,7 @@ def upsert_document( return Document.with_data(response, model_type) - def update_document( + async def update_document( self, database_id: str, collection_id: str, @@ -1562,7 +1562,7 @@ def update_document( if transaction_id is not None: api_params['transactionId'] = self._normalize_value(transaction_id) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -1575,7 +1575,7 @@ def update_document( return Document.with_data(response, model_type) - def delete_document( + async def delete_document( self, database_id: str, collection_id: str, @@ -1620,7 +1620,7 @@ def delete_document( if transaction_id is not None: api_params['transactionId'] = self._normalize_value(transaction_id) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -1633,7 +1633,7 @@ def delete_document( return response - def decrement_document_attribute( + async def decrement_document_attribute( self, database_id: str, collection_id: str, @@ -1698,7 +1698,7 @@ def decrement_document_attribute( if transaction_id is not None: api_params['transactionId'] = self._normalize_value(transaction_id) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -1711,7 +1711,7 @@ def decrement_document_attribute( return Document.with_data(response, model_type) - def increment_document_attribute( + async def increment_document_attribute( self, database_id: str, collection_id: str, @@ -1776,7 +1776,7 @@ def increment_document_attribute( if transaction_id is not None: api_params['transactionId'] = self._normalize_value(transaction_id) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -1789,7 +1789,7 @@ def increment_document_attribute( return Document.with_data(response, model_type) - def list_indexes( + async def list_indexes( self, database_id: str, collection_id: str, @@ -1833,7 +1833,7 @@ def list_indexes( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -1845,7 +1845,7 @@ def list_indexes( return self._parse_response(response, model=IndexList) - def create_index( + async def create_index( self, database_id: str, collection_id: str, @@ -1913,7 +1913,7 @@ def create_index( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -1926,7 +1926,7 @@ def create_index( return self._parse_response(response, model=Index) - def get_index( + async def get_index( self, database_id: str, collection_id: str, @@ -1966,7 +1966,7 @@ def get_index( api_path = api_path.replace('{collectionId}', str(self._normalize_value(collection_id))) api_path = api_path.replace('{key}', str(self._normalize_value(key))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -1978,7 +1978,7 @@ def get_index( return self._parse_response(response, model=Index) - def delete_index( + async def delete_index( self, database_id: str, collection_id: str, @@ -2018,7 +2018,7 @@ def delete_index( api_path = api_path.replace('{collectionId}', str(self._normalize_value(collection_id))) api_path = api_path.replace('{key}', str(self._normalize_value(key))) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -2031,7 +2031,7 @@ def delete_index( return response - def create_failover( + async def create_failover( self, database_id: str, target_replica_id: Optional[str] = None, @@ -2064,7 +2064,7 @@ def create_failover( if target_replica_id is not None: api_params['targetReplicaId'] = self._normalize_value(target_replica_id) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -2077,7 +2077,7 @@ def create_failover( return self._parse_response(response, model=DedicatedDatabase) - def list_operations( + async def list_operations( self, database_id: str, status: Optional[str] = None, @@ -2120,7 +2120,7 @@ def list_operations( if offset is not None: api_params['offset'] = self._normalize_value(offset) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -2132,7 +2132,7 @@ def list_operations( return self._parse_response(response, model=DedicatedDatabaseOperationList) - def get_replicas( + async def get_replicas( self, database_id: str, ) -> DedicatedDatabaseReplicas: @@ -2160,7 +2160,7 @@ def get_replicas( raise AppwriteException('Missing required parameter: "database_id"') api_path = api_path.replace('{databaseId}', str(self._normalize_value(database_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -2172,7 +2172,7 @@ def get_replicas( return self._parse_response(response, model=DedicatedDatabaseReplicas) - def get_status( + async def get_status( self, database_id: str, ) -> DatabaseStatus: @@ -2200,7 +2200,7 @@ def get_status( raise AppwriteException('Missing required parameter: "database_id"') api_path = api_path.replace('{databaseId}', str(self._normalize_value(database_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { diff --git a/appwrite/services/domains.py b/appwrite/services/domains.py index bce1dc23..6973c912 100644 --- a/appwrite/services/domains.py +++ b/appwrite/services/domains.py @@ -18,7 +18,7 @@ class Domains(Service): def __init__(self, client) -> None: super(Domains, self).__init__(client) - def list( + async def list( self, queries: Optional[List[str]] = None, search: Optional[str] = None, @@ -55,7 +55,7 @@ def list( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -67,7 +67,7 @@ def list( return self._parse_response(response, model=DomainsList) - def create( + async def create( self, team_id: str, domain: str, @@ -101,7 +101,7 @@ def create( api_params['teamId'] = self._normalize_value(team_id) api_params['domain'] = self._normalize_value(domain) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -115,7 +115,7 @@ def create( return self._parse_response(response, model=Domain) @deprecated("This API has been deprecated since 2.0.0. Please use `domains.list_prices` instead.") - def get_price( + async def get_price( self, domain: str, period_years: Optional[float] = None, @@ -155,7 +155,7 @@ def get_price( if registration_type is not None: api_params['registrationType'] = self._normalize_value(registration_type) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -167,7 +167,7 @@ def get_price( return self._parse_response(response, model=DomainPrice) - def list_prices( + async def list_prices( self, domains: List[str], period_years: Optional[float] = None, @@ -205,7 +205,7 @@ def list_prices( if registration_type is not None: api_params['registrationType'] = self._normalize_value(registration_type) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -217,7 +217,7 @@ def list_prices( return self._parse_response(response, model=DomainPricesList) - def get( + async def get( self, domain_id: str, ) -> Domain: @@ -245,7 +245,7 @@ def get( raise AppwriteException('Missing required parameter: "domain_id"') api_path = api_path.replace('{domainId}', str(self._normalize_value(domain_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -257,7 +257,7 @@ def get( return self._parse_response(response, model=Domain) - def delete( + async def delete( self, domain_id: str, ) -> Dict[str, Any]: @@ -286,7 +286,7 @@ def delete( raise AppwriteException('Missing required parameter: "domain_id"') api_path = api_path.replace('{domainId}', str(self._normalize_value(domain_id))) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -299,7 +299,7 @@ def delete( return response - def update_nameservers( + async def update_nameservers( self, domain_id: str, nameservers: Optional[List[str]] = None, @@ -333,7 +333,7 @@ def update_nameservers( if nameservers is not None: api_params['nameservers'] = self._normalize_value(nameservers) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -346,7 +346,7 @@ def update_nameservers( return self._parse_response(response, model=Domain) - def verify_nameservers( + async def verify_nameservers( self, domain_id: str, ) -> Domain: @@ -376,7 +376,7 @@ def verify_nameservers( raise AppwriteException('Missing required parameter: "domain_id"') api_path = api_path.replace('{domainId}', str(self._normalize_value(domain_id))) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -389,7 +389,7 @@ def verify_nameservers( return self._parse_response(response, model=Domain) - def get_preset_google_workspace( + async def get_preset_google_workspace( self, domain_id: str, ) -> DnsRecordsList: @@ -417,7 +417,7 @@ def get_preset_google_workspace( raise AppwriteException('Missing required parameter: "domain_id"') api_path = api_path.replace('{domainId}', str(self._normalize_value(domain_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -429,7 +429,7 @@ def get_preset_google_workspace( return self._parse_response(response, model=DnsRecordsList) - def create_preset_google_workspace( + async def create_preset_google_workspace( self, domain_id: str, ) -> DnsRecordsList: @@ -458,7 +458,7 @@ def create_preset_google_workspace( raise AppwriteException('Missing required parameter: "domain_id"') api_path = api_path.replace('{domainId}', str(self._normalize_value(domain_id))) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -471,7 +471,7 @@ def create_preset_google_workspace( return self._parse_response(response, model=DnsRecordsList) - def get_preset_i_cloud( + async def get_preset_i_cloud( self, domain_id: str, ) -> DnsRecordsList: @@ -499,7 +499,7 @@ def get_preset_i_cloud( raise AppwriteException('Missing required parameter: "domain_id"') api_path = api_path.replace('{domainId}', str(self._normalize_value(domain_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -511,7 +511,7 @@ def get_preset_i_cloud( return self._parse_response(response, model=DnsRecordsList) - def create_preset_i_cloud( + async def create_preset_i_cloud( self, domain_id: str, ) -> DnsRecordsList: @@ -540,7 +540,7 @@ def create_preset_i_cloud( raise AppwriteException('Missing required parameter: "domain_id"') api_path = api_path.replace('{domainId}', str(self._normalize_value(domain_id))) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -553,7 +553,7 @@ def create_preset_i_cloud( return self._parse_response(response, model=DnsRecordsList) - def get_preset_mailgun( + async def get_preset_mailgun( self, domain_id: str, ) -> DnsRecordsList: @@ -581,7 +581,7 @@ def get_preset_mailgun( raise AppwriteException('Missing required parameter: "domain_id"') api_path = api_path.replace('{domainId}', str(self._normalize_value(domain_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -593,7 +593,7 @@ def get_preset_mailgun( return self._parse_response(response, model=DnsRecordsList) - def create_preset_mailgun( + async def create_preset_mailgun( self, domain_id: str, ) -> DnsRecordsList: @@ -622,7 +622,7 @@ def create_preset_mailgun( raise AppwriteException('Missing required parameter: "domain_id"') api_path = api_path.replace('{domainId}', str(self._normalize_value(domain_id))) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -635,7 +635,7 @@ def create_preset_mailgun( return self._parse_response(response, model=DnsRecordsList) - def get_preset_outlook( + async def get_preset_outlook( self, domain_id: str, ) -> DnsRecordsList: @@ -663,7 +663,7 @@ def get_preset_outlook( raise AppwriteException('Missing required parameter: "domain_id"') api_path = api_path.replace('{domainId}', str(self._normalize_value(domain_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -675,7 +675,7 @@ def get_preset_outlook( return self._parse_response(response, model=DnsRecordsList) - def create_preset_outlook( + async def create_preset_outlook( self, domain_id: str, ) -> DnsRecordsList: @@ -704,7 +704,7 @@ def create_preset_outlook( raise AppwriteException('Missing required parameter: "domain_id"') api_path = api_path.replace('{domainId}', str(self._normalize_value(domain_id))) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -717,7 +717,7 @@ def create_preset_outlook( return self._parse_response(response, model=DnsRecordsList) - def get_preset_proton_mail( + async def get_preset_proton_mail( self, domain_id: str, ) -> DnsRecordsList: @@ -745,7 +745,7 @@ def get_preset_proton_mail( raise AppwriteException('Missing required parameter: "domain_id"') api_path = api_path.replace('{domainId}', str(self._normalize_value(domain_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -757,7 +757,7 @@ def get_preset_proton_mail( return self._parse_response(response, model=DnsRecordsList) - def create_preset_proton_mail( + async def create_preset_proton_mail( self, domain_id: str, ) -> DnsRecordsList: @@ -786,7 +786,7 @@ def create_preset_proton_mail( raise AppwriteException('Missing required parameter: "domain_id"') api_path = api_path.replace('{domainId}', str(self._normalize_value(domain_id))) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -799,7 +799,7 @@ def create_preset_proton_mail( return self._parse_response(response, model=DnsRecordsList) - def get_preset_zoho( + async def get_preset_zoho( self, domain_id: str, ) -> DnsRecordsList: @@ -827,7 +827,7 @@ def get_preset_zoho( raise AppwriteException('Missing required parameter: "domain_id"') api_path = api_path.replace('{domainId}', str(self._normalize_value(domain_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -839,7 +839,7 @@ def get_preset_zoho( return self._parse_response(response, model=DnsRecordsList) - def create_preset_zoho( + async def create_preset_zoho( self, domain_id: str, ) -> DnsRecordsList: @@ -868,7 +868,7 @@ def create_preset_zoho( raise AppwriteException('Missing required parameter: "domain_id"') api_path = api_path.replace('{domainId}', str(self._normalize_value(domain_id))) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -881,7 +881,7 @@ def create_preset_zoho( return self._parse_response(response, model=DnsRecordsList) - def list_records( + async def list_records( self, domain_id: str, queries: Optional[List[str]] = None, @@ -920,7 +920,7 @@ def list_records( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -932,7 +932,7 @@ def list_records( return self._parse_response(response, model=DnsRecordsList) - def create_record_a( + async def create_record_a( self, domain_id: str, name: str, @@ -984,7 +984,7 @@ def create_record_a( if comment is not None: api_params['comment'] = self._normalize_value(comment) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -997,7 +997,7 @@ def create_record_a( return self._parse_response(response, model=DnsRecord) - def update_record_a( + async def update_record_a( self, domain_id: str, record_id: str, @@ -1056,7 +1056,7 @@ def update_record_a( if comment is not None: api_params['comment'] = self._normalize_value(comment) - response = self.client.call( + response = await self.client.call( 'put', api_path, { @@ -1069,7 +1069,7 @@ def update_record_a( return self._parse_response(response, model=DnsRecord) - def create_record_aaaa( + async def create_record_aaaa( self, domain_id: str, name: str, @@ -1121,7 +1121,7 @@ def create_record_aaaa( if comment is not None: api_params['comment'] = self._normalize_value(comment) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -1134,7 +1134,7 @@ def create_record_aaaa( return self._parse_response(response, model=DnsRecord) - def update_record_aaaa( + async def update_record_aaaa( self, domain_id: str, record_id: str, @@ -1193,7 +1193,7 @@ def update_record_aaaa( if comment is not None: api_params['comment'] = self._normalize_value(comment) - response = self.client.call( + response = await self.client.call( 'put', api_path, { @@ -1206,7 +1206,7 @@ def update_record_aaaa( return self._parse_response(response, model=DnsRecord) - def create_record_alias( + async def create_record_alias( self, domain_id: str, name: str, @@ -1259,7 +1259,7 @@ def create_record_alias( if comment is not None: api_params['comment'] = self._normalize_value(comment) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -1272,7 +1272,7 @@ def create_record_alias( return self._parse_response(response, model=DnsRecord) - def update_record_alias( + async def update_record_alias( self, domain_id: str, record_id: str, @@ -1333,7 +1333,7 @@ def update_record_alias( if comment is not None: api_params['comment'] = self._normalize_value(comment) - response = self.client.call( + response = await self.client.call( 'put', api_path, { @@ -1346,7 +1346,7 @@ def update_record_alias( return self._parse_response(response, model=DnsRecord) - def create_record_caa( + async def create_record_caa( self, domain_id: str, name: str, @@ -1398,7 +1398,7 @@ def create_record_caa( if comment is not None: api_params['comment'] = self._normalize_value(comment) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -1411,7 +1411,7 @@ def create_record_caa( return self._parse_response(response, model=DnsRecord) - def update_record_caa( + async def update_record_caa( self, domain_id: str, record_id: str, @@ -1470,7 +1470,7 @@ def update_record_caa( if comment is not None: api_params['comment'] = self._normalize_value(comment) - response = self.client.call( + response = await self.client.call( 'put', api_path, { @@ -1483,7 +1483,7 @@ def update_record_caa( return self._parse_response(response, model=DnsRecord) - def create_record_cname( + async def create_record_cname( self, domain_id: str, name: str, @@ -1538,7 +1538,7 @@ def create_record_cname( if comment is not None: api_params['comment'] = self._normalize_value(comment) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -1551,7 +1551,7 @@ def create_record_cname( return self._parse_response(response, model=DnsRecord) - def update_record_cname( + async def update_record_cname( self, domain_id: str, record_id: str, @@ -1608,7 +1608,7 @@ def update_record_cname( if comment is not None: api_params['comment'] = self._normalize_value(comment) - response = self.client.call( + response = await self.client.call( 'put', api_path, { @@ -1621,7 +1621,7 @@ def update_record_cname( return self._parse_response(response, model=DnsRecord) - def create_record_https( + async def create_record_https( self, domain_id: str, name: str, @@ -1673,7 +1673,7 @@ def create_record_https( if comment is not None: api_params['comment'] = self._normalize_value(comment) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -1686,7 +1686,7 @@ def create_record_https( return self._parse_response(response, model=DnsRecord) - def update_record_https( + async def update_record_https( self, domain_id: str, record_id: str, @@ -1745,7 +1745,7 @@ def update_record_https( if comment is not None: api_params['comment'] = self._normalize_value(comment) - response = self.client.call( + response = await self.client.call( 'put', api_path, { @@ -1758,7 +1758,7 @@ def update_record_https( return self._parse_response(response, model=DnsRecord) - def create_record_mx( + async def create_record_mx( self, domain_id: str, name: str, @@ -1818,7 +1818,7 @@ def create_record_mx( if comment is not None: api_params['comment'] = self._normalize_value(comment) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -1831,7 +1831,7 @@ def create_record_mx( return self._parse_response(response, model=DnsRecord) - def update_record_mx( + async def update_record_mx( self, domain_id: str, record_id: str, @@ -1894,7 +1894,7 @@ def update_record_mx( if comment is not None: api_params['comment'] = self._normalize_value(comment) - response = self.client.call( + response = await self.client.call( 'put', api_path, { @@ -1907,7 +1907,7 @@ def update_record_mx( return self._parse_response(response, model=DnsRecord) - def create_record_ns( + async def create_record_ns( self, domain_id: str, name: str, @@ -1959,7 +1959,7 @@ def create_record_ns( if comment is not None: api_params['comment'] = self._normalize_value(comment) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -1972,7 +1972,7 @@ def create_record_ns( return self._parse_response(response, model=DnsRecord) - def update_record_ns( + async def update_record_ns( self, domain_id: str, record_id: str, @@ -2032,7 +2032,7 @@ def update_record_ns( if comment is not None: api_params['comment'] = self._normalize_value(comment) - response = self.client.call( + response = await self.client.call( 'put', api_path, { @@ -2045,7 +2045,7 @@ def update_record_ns( return self._parse_response(response, model=DnsRecord) - def create_record_srv( + async def create_record_srv( self, domain_id: str, name: str, @@ -2116,7 +2116,7 @@ def create_record_srv( if comment is not None: api_params['comment'] = self._normalize_value(comment) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -2129,7 +2129,7 @@ def create_record_srv( return self._parse_response(response, model=DnsRecord) - def update_record_srv( + async def update_record_srv( self, domain_id: str, record_id: str, @@ -2217,7 +2217,7 @@ def update_record_srv( if comment is not None: api_params['comment'] = self._normalize_value(comment) - response = self.client.call( + response = await self.client.call( 'put', api_path, { @@ -2230,7 +2230,7 @@ def update_record_srv( return self._parse_response(response, model=DnsRecord) - def create_record_txt( + async def create_record_txt( self, domain_id: str, name: str, @@ -2282,7 +2282,7 @@ def create_record_txt( if comment is not None: api_params['comment'] = self._normalize_value(comment) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -2295,7 +2295,7 @@ def create_record_txt( return self._parse_response(response, model=DnsRecord) - def update_record_txt( + async def update_record_txt( self, domain_id: str, record_id: str, @@ -2355,7 +2355,7 @@ def update_record_txt( if comment is not None: api_params['comment'] = self._normalize_value(comment) - response = self.client.call( + response = await self.client.call( 'put', api_path, { @@ -2368,7 +2368,7 @@ def update_record_txt( return self._parse_response(response, model=DnsRecord) - def get_record( + async def get_record( self, domain_id: str, record_id: str, @@ -2406,7 +2406,7 @@ def get_record( api_path = api_path.replace('{domainId}', str(self._normalize_value(domain_id))) api_path = api_path.replace('{recordId}', str(self._normalize_value(record_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -2418,7 +2418,7 @@ def get_record( return self._parse_response(response, model=DnsRecord) - def delete_record( + async def delete_record( self, domain_id: str, record_id: str, @@ -2453,7 +2453,7 @@ def delete_record( api_path = api_path.replace('{domainId}', str(self._normalize_value(domain_id))) api_path = api_path.replace('{recordId}', str(self._normalize_value(record_id))) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -2466,7 +2466,7 @@ def delete_record( return response - def update_team( + async def update_team( self, domain_id: str, team_id: str, @@ -2504,7 +2504,7 @@ def update_team( api_path = api_path.replace('{domainId}', str(self._normalize_value(domain_id))) api_params['teamId'] = self._normalize_value(team_id) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -2517,7 +2517,7 @@ def update_team( return self._parse_response(response, model=Domain) - def get_transfer_status( + async def get_transfer_status( self, domain_id: str, ) -> DomainTransferStatus: @@ -2545,7 +2545,7 @@ def get_transfer_status( raise AppwriteException('Missing required parameter: "domain_id"') api_path = api_path.replace('{domainId}', str(self._normalize_value(domain_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -2557,7 +2557,7 @@ def get_transfer_status( return self._parse_response(response, model=DomainTransferStatus) - def get_zone( + async def get_zone( self, domain_id: str, ) -> str: @@ -2586,7 +2586,7 @@ def get_zone( raise AppwriteException('Missing required parameter: "domain_id"') api_path = api_path.replace('{domainId}', str(self._normalize_value(domain_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -2599,7 +2599,7 @@ def get_zone( return response - def update_zone( + async def update_zone( self, domain_id: str, content: str, @@ -2634,7 +2634,7 @@ def update_zone( api_path = api_path.replace('{domainId}', str(self._normalize_value(domain_id))) api_params['content'] = self._normalize_value(content) - response = self.client.call( + response = await self.client.call( 'put', api_path, { diff --git a/appwrite/services/embeddings.py b/appwrite/services/embeddings.py index 4068b552..0bd09328 100644 --- a/appwrite/services/embeddings.py +++ b/appwrite/services/embeddings.py @@ -12,7 +12,7 @@ class Embeddings(Service): def __init__(self, client) -> None: super(Embeddings, self).__init__(client) - def create_text_embeddings( + async def create_text_embeddings( self, texts: List[str], model: Optional[EmbeddingModel] = None, @@ -45,7 +45,7 @@ def create_text_embeddings( if model is not None: api_params['model'] = self._normalize_value(model) - response = self.client.call( + response = await self.client.call( 'post', api_path, { diff --git a/appwrite/services/functions.py b/appwrite/services/functions.py index fa109998..43e6f35d 100644 --- a/appwrite/services/functions.py +++ b/appwrite/services/functions.py @@ -27,7 +27,7 @@ class Functions(Service): def __init__(self, client) -> None: super(Functions, self).__init__(client) - def list( + async def list( self, queries: Optional[List[str]] = None, search: Optional[str] = None, @@ -64,7 +64,7 @@ def list( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -76,7 +76,7 @@ def list( return self._parse_response(response, model=FunctionList) - def create( + async def create( self, function_id: str, name: str, @@ -221,7 +221,7 @@ def create( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -234,7 +234,7 @@ def create( return self._parse_response(response, model=Function) - def list_runtimes( + async def list_runtimes( self, total: Optional[bool] = None, ) -> RuntimeList: @@ -261,7 +261,7 @@ def list_runtimes( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -273,7 +273,7 @@ def list_runtimes( return self._parse_response(response, model=RuntimeList) - def list_specifications( + async def list_specifications( self, type: Optional[str] = None, total: Optional[bool] = None, @@ -305,7 +305,7 @@ def list_specifications( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -317,7 +317,7 @@ def list_specifications( return self._parse_response(response, model=SpecificationList) - def get( + async def get( self, function_id: str, ) -> Function: @@ -345,7 +345,7 @@ def get( raise AppwriteException('Missing required parameter: "function_id"') api_path = api_path.replace('{functionId}', str(self._normalize_value(function_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -357,7 +357,7 @@ def get( return self._parse_response(response, model=Function) - def update( + async def update( self, function_id: str, name: str, @@ -506,7 +506,7 @@ def update( if email_enabled is not None: api_params['emailEnabled'] = self._normalize_value(email_enabled) - response = self.client.call( + response = await self.client.call( 'put', api_path, { @@ -519,7 +519,7 @@ def update( return self._parse_response(response, model=Function) - def delete( + async def delete( self, function_id: str, ) -> Dict[str, Any]: @@ -547,7 +547,7 @@ def delete( raise AppwriteException('Missing required parameter: "function_id"') api_path = api_path.replace('{functionId}', str(self._normalize_value(function_id))) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -560,7 +560,7 @@ def delete( return response - def update_function_deployment( + async def update_function_deployment( self, function_id: str, deployment_id: str, @@ -594,7 +594,7 @@ def update_function_deployment( api_path = api_path.replace('{functionId}', str(self._normalize_value(function_id))) api_params['deploymentId'] = self._normalize_value(deployment_id) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -607,7 +607,7 @@ def update_function_deployment( return self._parse_response(response, model=Function) - def list_deployments( + async def list_deployments( self, function_id: str, queries: Optional[List[str]] = None, @@ -650,7 +650,7 @@ def list_deployments( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -662,7 +662,7 @@ def list_deployments( return self._parse_response(response, model=DeploymentList) - def create_deployment( + async def create_deployment( self, function_id: str, code: InputFile, @@ -724,7 +724,7 @@ def create_deployment( upload_id = '' - response = self.client.chunked_upload( + response = await self.client.chunked_upload( api_path, { 'X-Appwrite-Project': self.client.get_config('project'), @@ -740,7 +740,7 @@ def create_deployment( return self._parse_response(response, model=Deployment) - def create_duplicate_deployment( + async def create_duplicate_deployment( self, function_id: str, deployment_id: str, @@ -779,7 +779,7 @@ def create_duplicate_deployment( if build_id is not None: api_params['buildId'] = self._normalize_value(build_id) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -792,7 +792,7 @@ def create_duplicate_deployment( return self._parse_response(response, model=Deployment) - def create_template_deployment( + async def create_template_deployment( self, function_id: str, repository: str, @@ -857,7 +857,7 @@ def create_template_deployment( if activate is not None: api_params['activate'] = self._normalize_value(activate) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -870,7 +870,7 @@ def create_template_deployment( return self._parse_response(response, model=Deployment) - def create_vcs_deployment( + async def create_vcs_deployment( self, function_id: str, type: VCSReferenceType, @@ -917,7 +917,7 @@ def create_vcs_deployment( if activate is not None: api_params['activate'] = self._normalize_value(activate) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -930,7 +930,7 @@ def create_vcs_deployment( return self._parse_response(response, model=Deployment) - def get_deployment( + async def get_deployment( self, function_id: str, deployment_id: str, @@ -964,7 +964,7 @@ def get_deployment( api_path = api_path.replace('{functionId}', str(self._normalize_value(function_id))) api_path = api_path.replace('{deploymentId}', str(self._normalize_value(deployment_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -976,7 +976,7 @@ def get_deployment( return self._parse_response(response, model=Deployment) - def delete_deployment( + async def delete_deployment( self, function_id: str, deployment_id: str, @@ -1010,7 +1010,7 @@ def delete_deployment( api_path = api_path.replace('{functionId}', str(self._normalize_value(function_id))) api_path = api_path.replace('{deploymentId}', str(self._normalize_value(deployment_id))) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -1023,7 +1023,7 @@ def delete_deployment( return response - def get_deployment_download( + async def get_deployment_download( self, function_id: str, deployment_id: str, @@ -1067,7 +1067,7 @@ def get_deployment_download( if token is not None: api_params['token'] = self._normalize_value(token) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -1079,7 +1079,7 @@ def get_deployment_download( return response - def update_deployment_status( + async def update_deployment_status( self, function_id: str, deployment_id: str, @@ -1113,7 +1113,7 @@ def update_deployment_status( api_path = api_path.replace('{functionId}', str(self._normalize_value(function_id))) api_path = api_path.replace('{deploymentId}', str(self._normalize_value(deployment_id))) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -1126,7 +1126,7 @@ def update_deployment_status( return self._parse_response(response, model=Deployment) - def list_executions( + async def list_executions( self, function_id: str, queries: Optional[List[str]] = None, @@ -1164,7 +1164,7 @@ def list_executions( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -1176,7 +1176,7 @@ def list_executions( return self._parse_response(response, model=ExecutionList) - def create_execution( + async def create_execution( self, function_id: str, body: Optional[str] = None, @@ -1234,7 +1234,7 @@ def create_execution( if scheduled_at is not None: api_params['scheduledAt'] = self._normalize_value(scheduled_at) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -1247,7 +1247,7 @@ def create_execution( return self._parse_response(response, model=Execution) - def get_execution( + async def get_execution( self, function_id: str, execution_id: str, @@ -1281,7 +1281,7 @@ def get_execution( api_path = api_path.replace('{functionId}', str(self._normalize_value(function_id))) api_path = api_path.replace('{executionId}', str(self._normalize_value(execution_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -1293,7 +1293,7 @@ def get_execution( return self._parse_response(response, model=Execution) - def delete_execution( + async def delete_execution( self, function_id: str, execution_id: str, @@ -1327,7 +1327,7 @@ def delete_execution( api_path = api_path.replace('{functionId}', str(self._normalize_value(function_id))) api_path = api_path.replace('{executionId}', str(self._normalize_value(execution_id))) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -1340,7 +1340,7 @@ def delete_execution( return response - def list_variables( + async def list_variables( self, function_id: str, queries: Optional[List[str]] = None, @@ -1378,7 +1378,7 @@ def list_variables( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -1390,7 +1390,7 @@ def list_variables( return self._parse_response(response, model=VariableList) - def create_variable( + async def create_variable( self, function_id: str, variable_id: str, @@ -1446,7 +1446,7 @@ def create_variable( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -1459,7 +1459,7 @@ def create_variable( return self._parse_response(response, model=Variable) - def get_variable( + async def get_variable( self, function_id: str, variable_id: str, @@ -1493,7 +1493,7 @@ def get_variable( api_path = api_path.replace('{functionId}', str(self._normalize_value(function_id))) api_path = api_path.replace('{variableId}', str(self._normalize_value(variable_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -1505,7 +1505,7 @@ def get_variable( return self._parse_response(response, model=Variable) - def update_variable( + async def update_variable( self, function_id: str, variable_id: str, @@ -1559,7 +1559,7 @@ def update_variable( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'put', api_path, { @@ -1572,7 +1572,7 @@ def update_variable( return self._parse_response(response, model=Variable) - def delete_variable( + async def delete_variable( self, function_id: str, variable_id: str, @@ -1606,7 +1606,7 @@ def delete_variable( api_path = api_path.replace('{functionId}', str(self._normalize_value(function_id))) api_path = api_path.replace('{variableId}', str(self._normalize_value(variable_id))) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { diff --git a/appwrite/services/graphql.py b/appwrite/services/graphql.py index ed8661b2..f1919774 100644 --- a/appwrite/services/graphql.py +++ b/appwrite/services/graphql.py @@ -10,7 +10,7 @@ class Graphql(Service): def __init__(self, client) -> None: super(Graphql, self).__init__(client) - def query( + async def query( self, query: Dict[str, Any], ) -> Dict[str, Any]: @@ -38,7 +38,7 @@ def query( raise AppwriteException('Missing required parameter: "query"') api_params['query'] = self._normalize_value(query) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -52,7 +52,7 @@ def query( return response - def mutation( + async def mutation( self, query: Dict[str, Any], ) -> Dict[str, Any]: @@ -80,7 +80,7 @@ def mutation( raise AppwriteException('Missing required parameter: "query"') api_params['query'] = self._normalize_value(query) - response = self.client.call( + response = await self.client.call( 'post', api_path, { diff --git a/appwrite/services/locale.py b/appwrite/services/locale.py index e0e69e70..3a242350 100644 --- a/appwrite/services/locale.py +++ b/appwrite/services/locale.py @@ -17,7 +17,7 @@ class Locale(Service): def __init__(self, client) -> None: super(Locale, self).__init__(client) - def get( + async def get( self, ) -> LocaleModel: """ @@ -38,7 +38,7 @@ def get( api_path = '/locale' api_params = {} - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -50,7 +50,7 @@ def get( return self._parse_response(response, model=LocaleModel) - def list_codes( + async def list_codes( self, total: Optional[bool] = None, ) -> LocaleCodeList: @@ -77,7 +77,7 @@ def list_codes( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -89,7 +89,7 @@ def list_codes( return self._parse_response(response, model=LocaleCodeList) - def list_continents( + async def list_continents( self, total: Optional[bool] = None, ) -> ContinentList: @@ -116,7 +116,7 @@ def list_continents( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -128,7 +128,7 @@ def list_continents( return self._parse_response(response, model=ContinentList) - def list_countries( + async def list_countries( self, total: Optional[bool] = None, ) -> CountryList: @@ -155,7 +155,7 @@ def list_countries( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -167,7 +167,7 @@ def list_countries( return self._parse_response(response, model=CountryList) - def list_countries_eu( + async def list_countries_eu( self, total: Optional[bool] = None, ) -> CountryList: @@ -194,7 +194,7 @@ def list_countries_eu( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -206,7 +206,7 @@ def list_countries_eu( return self._parse_response(response, model=CountryList) - def list_countries_phones( + async def list_countries_phones( self, total: Optional[bool] = None, ) -> PhoneList: @@ -233,7 +233,7 @@ def list_countries_phones( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -245,7 +245,7 @@ def list_countries_phones( return self._parse_response(response, model=PhoneList) - def list_currencies( + async def list_currencies( self, total: Optional[bool] = None, ) -> CurrencyList: @@ -272,7 +272,7 @@ def list_currencies( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -284,7 +284,7 @@ def list_currencies( return self._parse_response(response, model=CurrencyList) - def list_languages( + async def list_languages( self, total: Optional[bool] = None, ) -> LanguageList: @@ -311,7 +311,7 @@ def list_languages( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { diff --git a/appwrite/services/messaging.py b/appwrite/services/messaging.py index df5083f7..1845351e 100644 --- a/appwrite/services/messaging.py +++ b/appwrite/services/messaging.py @@ -21,7 +21,7 @@ class Messaging(Service): def __init__(self, client) -> None: super(Messaging, self).__init__(client) - def list_messages( + async def list_messages( self, queries: Optional[List[str]] = None, search: Optional[str] = None, @@ -58,7 +58,7 @@ def list_messages( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -70,7 +70,7 @@ def list_messages( return self._parse_response(response, model=MessageList) - def create_email( + async def create_email( self, message_id: str, subject: str, @@ -170,7 +170,7 @@ def create_email( if emails is not None: api_params['emails'] = self._normalize_value(emails) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -183,7 +183,7 @@ def create_email( return self._parse_response(response, model=Message) - def update_email( + async def update_email( self, message_id: str, topics: Optional[List[str]] = None, @@ -281,7 +281,7 @@ def update_email( if emails is not None: api_params['emails'] = self._normalize_value(emails) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -294,7 +294,7 @@ def update_email( return self._parse_response(response, model=Message) - def create_push( + async def create_push( self, message_id: str, title: Optional[str] = None, @@ -417,7 +417,7 @@ def create_push( if channel_id is not None: api_params['channelId'] = self._normalize_value(channel_id) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -430,7 +430,7 @@ def create_push( return self._parse_response(response, model=Message) - def update_push( + async def update_push( self, message_id: str, topics: Optional[List[str]] = None, @@ -553,7 +553,7 @@ def update_push( if channel_id is not None: api_params['channelId'] = self._normalize_value(channel_id) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -566,7 +566,7 @@ def update_push( return self._parse_response(response, model=Message) - def create_sms( + async def create_sms( self, message_id: str, content: str, @@ -625,7 +625,7 @@ def create_sms( if scheduled_at is not None: api_params['scheduledAt'] = self._normalize_value(scheduled_at) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -638,7 +638,7 @@ def create_sms( return self._parse_response(response, model=Message) - def update_sms( + async def update_sms( self, message_id: str, topics: Optional[List[str]] = None, @@ -696,7 +696,7 @@ def update_sms( if scheduled_at is not None: api_params['scheduledAt'] = self._normalize_value(scheduled_at) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -709,7 +709,7 @@ def update_sms( return self._parse_response(response, model=Message) - def get_message( + async def get_message( self, message_id: str, ) -> Message: @@ -737,7 +737,7 @@ def get_message( raise AppwriteException('Missing required parameter: "message_id"') api_path = api_path.replace('{messageId}', str(self._normalize_value(message_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -749,7 +749,7 @@ def get_message( return self._parse_response(response, model=Message) - def delete( + async def delete( self, message_id: str, ) -> Dict[str, Any]: @@ -777,7 +777,7 @@ def delete( raise AppwriteException('Missing required parameter: "message_id"') api_path = api_path.replace('{messageId}', str(self._normalize_value(message_id))) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -790,7 +790,7 @@ def delete( return response - def list_targets( + async def list_targets( self, message_id: str, queries: Optional[List[str]] = None, @@ -828,7 +828,7 @@ def list_targets( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -840,7 +840,7 @@ def list_targets( return self._parse_response(response, model=TargetList) - def list_providers( + async def list_providers( self, queries: Optional[List[str]] = None, search: Optional[str] = None, @@ -877,7 +877,7 @@ def list_providers( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -889,7 +889,7 @@ def list_providers( return self._parse_response(response, model=ProviderList) - def create_apns_provider( + async def create_apns_provider( self, provider_id: str, name: str, @@ -953,7 +953,7 @@ def create_apns_provider( if enabled is not None: api_params['enabled'] = self._normalize_value(enabled) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -966,7 +966,7 @@ def create_apns_provider( return self._parse_response(response, model=Provider) - def update_apns_provider( + async def update_apns_provider( self, provider_id: str, name: Optional[str] = None, @@ -1029,7 +1029,7 @@ def update_apns_provider( if sandbox is not None: api_params['sandbox'] = self._normalize_value(sandbox) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -1042,7 +1042,7 @@ def update_apns_provider( return self._parse_response(response, model=Provider) - def create_appwrite_provider( + async def create_appwrite_provider( self, provider_id: str, name: str, @@ -1091,7 +1091,7 @@ def create_appwrite_provider( if expiry is not None: api_params['expiry'] = self._normalize_value(expiry) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -1104,7 +1104,7 @@ def create_appwrite_provider( return self._parse_response(response, model=Provider) - def update_appwrite_provider( + async def update_appwrite_provider( self, provider_id: str, name: Optional[str] = None, @@ -1152,7 +1152,7 @@ def update_appwrite_provider( if expiry is not None: api_params['expiry'] = self._normalize_value(expiry) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -1165,7 +1165,7 @@ def update_appwrite_provider( return self._parse_response(response, model=Provider) - def create_fcm_provider( + async def create_fcm_provider( self, provider_id: str, name: str, @@ -1209,7 +1209,7 @@ def create_fcm_provider( if enabled is not None: api_params['enabled'] = self._normalize_value(enabled) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -1222,7 +1222,7 @@ def create_fcm_provider( return self._parse_response(response, model=Provider) - def update_fcm_provider( + async def update_fcm_provider( self, provider_id: str, name: Optional[str] = None, @@ -1265,7 +1265,7 @@ def update_fcm_provider( if service_account_json is not None: api_params['serviceAccountJSON'] = self._normalize_value(service_account_json) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -1278,7 +1278,7 @@ def update_fcm_provider( return self._parse_response(response, model=Provider) - def create_mailgun_provider( + async def create_mailgun_provider( self, provider_id: str, name: str, @@ -1352,7 +1352,7 @@ def create_mailgun_provider( if enabled is not None: api_params['enabled'] = self._normalize_value(enabled) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -1365,7 +1365,7 @@ def create_mailgun_provider( return self._parse_response(response, model=Provider) - def update_mailgun_provider( + async def update_mailgun_provider( self, provider_id: str, name: Optional[str] = None, @@ -1438,7 +1438,7 @@ def update_mailgun_provider( if reply_to_email is not None: api_params['replyToEmail'] = self._normalize_value(reply_to_email) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -1451,7 +1451,7 @@ def update_mailgun_provider( return self._parse_response(response, model=Provider) - def create_msg91_provider( + async def create_msg91_provider( self, provider_id: str, name: str, @@ -1505,7 +1505,7 @@ def create_msg91_provider( if enabled is not None: api_params['enabled'] = self._normalize_value(enabled) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -1518,7 +1518,7 @@ def create_msg91_provider( return self._parse_response(response, model=Provider) - def update_msg91_provider( + async def update_msg91_provider( self, provider_id: str, name: Optional[str] = None, @@ -1571,7 +1571,7 @@ def update_msg91_provider( if auth_key is not None: api_params['authKey'] = self._normalize_value(auth_key) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -1584,7 +1584,7 @@ def update_msg91_provider( return self._parse_response(response, model=Provider) - def create_resend_provider( + async def create_resend_provider( self, provider_id: str, name: str, @@ -1648,7 +1648,7 @@ def create_resend_provider( if enabled is not None: api_params['enabled'] = self._normalize_value(enabled) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -1661,7 +1661,7 @@ def create_resend_provider( return self._parse_response(response, model=Provider) - def update_resend_provider( + async def update_resend_provider( self, provider_id: str, name: Optional[str] = None, @@ -1724,7 +1724,7 @@ def update_resend_provider( if reply_to_email is not None: api_params['replyToEmail'] = self._normalize_value(reply_to_email) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -1737,7 +1737,7 @@ def update_resend_provider( return self._parse_response(response, model=Provider) - def create_sendgrid_provider( + async def create_sendgrid_provider( self, provider_id: str, name: str, @@ -1801,7 +1801,7 @@ def create_sendgrid_provider( if enabled is not None: api_params['enabled'] = self._normalize_value(enabled) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -1814,7 +1814,7 @@ def create_sendgrid_provider( return self._parse_response(response, model=Provider) - def update_sendgrid_provider( + async def update_sendgrid_provider( self, provider_id: str, name: Optional[str] = None, @@ -1877,7 +1877,7 @@ def update_sendgrid_provider( if reply_to_email is not None: api_params['replyToEmail'] = self._normalize_value(reply_to_email) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -1890,7 +1890,7 @@ def update_sendgrid_provider( return self._parse_response(response, model=Provider) - def create_ses_provider( + async def create_ses_provider( self, provider_id: str, name: str, @@ -1964,7 +1964,7 @@ def create_ses_provider( if enabled is not None: api_params['enabled'] = self._normalize_value(enabled) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -1977,7 +1977,7 @@ def create_ses_provider( return self._parse_response(response, model=Provider) - def update_ses_provider( + async def update_ses_provider( self, provider_id: str, name: Optional[str] = None, @@ -2050,7 +2050,7 @@ def update_ses_provider( if reply_to_email is not None: api_params['replyToEmail'] = self._normalize_value(reply_to_email) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -2063,7 +2063,7 @@ def update_ses_provider( return self._parse_response(response, model=Provider) - def create_smtp_provider( + async def create_smtp_provider( self, provider_id: str, name: str, @@ -2158,7 +2158,7 @@ def create_smtp_provider( if enabled is not None: api_params['enabled'] = self._normalize_value(enabled) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -2171,7 +2171,7 @@ def create_smtp_provider( return self._parse_response(response, model=Provider) - def update_smtp_provider( + async def update_smtp_provider( self, provider_id: str, name: Optional[str] = None, @@ -2264,7 +2264,7 @@ def update_smtp_provider( if enabled is not None: api_params['enabled'] = self._normalize_value(enabled) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -2277,7 +2277,7 @@ def update_smtp_provider( return self._parse_response(response, model=Provider) - def create_telesign_provider( + async def create_telesign_provider( self, provider_id: str, name: str, @@ -2331,7 +2331,7 @@ def create_telesign_provider( if enabled is not None: api_params['enabled'] = self._normalize_value(enabled) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -2344,7 +2344,7 @@ def create_telesign_provider( return self._parse_response(response, model=Provider) - def update_telesign_provider( + async def update_telesign_provider( self, provider_id: str, name: Optional[str] = None, @@ -2397,7 +2397,7 @@ def update_telesign_provider( if xfrom is not None: api_params['from'] = self._normalize_value(xfrom) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -2410,7 +2410,7 @@ def update_telesign_provider( return self._parse_response(response, model=Provider) - def create_textmagic_provider( + async def create_textmagic_provider( self, provider_id: str, name: str, @@ -2464,7 +2464,7 @@ def create_textmagic_provider( if enabled is not None: api_params['enabled'] = self._normalize_value(enabled) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -2477,7 +2477,7 @@ def create_textmagic_provider( return self._parse_response(response, model=Provider) - def update_textmagic_provider( + async def update_textmagic_provider( self, provider_id: str, name: Optional[str] = None, @@ -2530,7 +2530,7 @@ def update_textmagic_provider( if xfrom is not None: api_params['from'] = self._normalize_value(xfrom) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -2543,7 +2543,7 @@ def update_textmagic_provider( return self._parse_response(response, model=Provider) - def create_twilio_provider( + async def create_twilio_provider( self, provider_id: str, name: str, @@ -2597,7 +2597,7 @@ def create_twilio_provider( if enabled is not None: api_params['enabled'] = self._normalize_value(enabled) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -2610,7 +2610,7 @@ def create_twilio_provider( return self._parse_response(response, model=Provider) - def update_twilio_provider( + async def update_twilio_provider( self, provider_id: str, name: Optional[str] = None, @@ -2663,7 +2663,7 @@ def update_twilio_provider( if xfrom is not None: api_params['from'] = self._normalize_value(xfrom) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -2676,7 +2676,7 @@ def update_twilio_provider( return self._parse_response(response, model=Provider) - def create_vonage_provider( + async def create_vonage_provider( self, provider_id: str, name: str, @@ -2730,7 +2730,7 @@ def create_vonage_provider( if enabled is not None: api_params['enabled'] = self._normalize_value(enabled) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -2743,7 +2743,7 @@ def create_vonage_provider( return self._parse_response(response, model=Provider) - def update_vonage_provider( + async def update_vonage_provider( self, provider_id: str, name: Optional[str] = None, @@ -2796,7 +2796,7 @@ def update_vonage_provider( if xfrom is not None: api_params['from'] = self._normalize_value(xfrom) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -2809,7 +2809,7 @@ def update_vonage_provider( return self._parse_response(response, model=Provider) - def get_provider( + async def get_provider( self, provider_id: str, ) -> Provider: @@ -2837,7 +2837,7 @@ def get_provider( raise AppwriteException('Missing required parameter: "provider_id"') api_path = api_path.replace('{providerId}', str(self._normalize_value(provider_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -2849,7 +2849,7 @@ def get_provider( return self._parse_response(response, model=Provider) - def delete_provider( + async def delete_provider( self, provider_id: str, ) -> Dict[str, Any]: @@ -2877,7 +2877,7 @@ def delete_provider( raise AppwriteException('Missing required parameter: "provider_id"') api_path = api_path.replace('{providerId}', str(self._normalize_value(provider_id))) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -2890,7 +2890,7 @@ def delete_provider( return response - def list_topics( + async def list_topics( self, queries: Optional[List[str]] = None, search: Optional[str] = None, @@ -2927,7 +2927,7 @@ def list_topics( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -2939,7 +2939,7 @@ def list_topics( return self._parse_response(response, model=TopicList) - def create_topic( + async def create_topic( self, topic_id: str, name: str, @@ -2993,7 +2993,7 @@ def create_topic( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -3006,7 +3006,7 @@ def create_topic( return self._parse_response(response, model=Topic) - def get_topic( + async def get_topic( self, topic_id: str, ) -> Topic: @@ -3034,7 +3034,7 @@ def get_topic( raise AppwriteException('Missing required parameter: "topic_id"') api_path = api_path.replace('{topicId}', str(self._normalize_value(topic_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -3046,7 +3046,7 @@ def get_topic( return self._parse_response(response, model=Topic) - def update_topic( + async def update_topic( self, topic_id: str, name: Optional[str] = None, @@ -3099,7 +3099,7 @@ def update_topic( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -3112,7 +3112,7 @@ def update_topic( return self._parse_response(response, model=Topic) - def delete_topic( + async def delete_topic( self, topic_id: str, ) -> Dict[str, Any]: @@ -3140,7 +3140,7 @@ def delete_topic( raise AppwriteException('Missing required parameter: "topic_id"') api_path = api_path.replace('{topicId}', str(self._normalize_value(topic_id))) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -3153,7 +3153,7 @@ def delete_topic( return response - def list_subscribers( + async def list_subscribers( self, topic_id: str, queries: Optional[List[str]] = None, @@ -3196,7 +3196,7 @@ def list_subscribers( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -3208,7 +3208,7 @@ def list_subscribers( return self._parse_response(response, model=SubscriberList) - def create_subscriber( + async def create_subscriber( self, topic_id: str, subscriber_id: str, @@ -3248,7 +3248,7 @@ def create_subscriber( api_params['subscriberId'] = self._normalize_value(subscriber_id) api_params['targetId'] = self._normalize_value(target_id) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -3261,7 +3261,7 @@ def create_subscriber( return self._parse_response(response, model=Subscriber) - def get_subscriber( + async def get_subscriber( self, topic_id: str, subscriber_id: str, @@ -3295,7 +3295,7 @@ def get_subscriber( api_path = api_path.replace('{topicId}', str(self._normalize_value(topic_id))) api_path = api_path.replace('{subscriberId}', str(self._normalize_value(subscriber_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -3307,7 +3307,7 @@ def get_subscriber( return self._parse_response(response, model=Subscriber) - def delete_subscriber( + async def delete_subscriber( self, topic_id: str, subscriber_id: str, @@ -3341,7 +3341,7 @@ def delete_subscriber( api_path = api_path.replace('{topicId}', str(self._normalize_value(topic_id))) api_path = api_path.replace('{subscriberId}', str(self._normalize_value(subscriber_id))) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { diff --git a/appwrite/services/mongo.py b/appwrite/services/mongo.py index f377fe6c..462011f2 100644 --- a/appwrite/services/mongo.py +++ b/appwrite/services/mongo.py @@ -26,7 +26,7 @@ class Mongo(Service): def __init__(self, client) -> None: super(Mongo, self).__init__(client) - def list( + async def list( self, queries: Optional[List[str]] = None, total: Optional[bool] = None, @@ -58,7 +58,7 @@ def list( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -70,7 +70,7 @@ def list( return self._parse_response(response, model=DedicatedDatabaseList) - def create( + async def create( self, database_id: str, name: str, @@ -166,7 +166,7 @@ def create( if storage_autoscaling_max_gb is not None: api_params['storageAutoscalingMaxGb'] = self._normalize_value(storage_autoscaling_max_gb) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -179,7 +179,7 @@ def create( return self._parse_response(response, model=DedicatedDatabase) - def list_specifications( + async def list_specifications( self, ) -> DedicatedDatabaseSpecificationList: """ @@ -198,7 +198,7 @@ def list_specifications( api_path = '/mongo/specifications' api_params = {} - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -210,7 +210,7 @@ def list_specifications( return self._parse_response(response, model=DedicatedDatabaseSpecificationList) - def get( + async def get( self, database_id: str, ) -> DedicatedDatabase: @@ -238,7 +238,7 @@ def get( raise AppwriteException('Missing required parameter: "database_id"') api_path = api_path.replace('{databaseId}', str(self._normalize_value(database_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -250,7 +250,7 @@ def get( return self._parse_response(response, model=DedicatedDatabase) - def update( + async def update( self, database_id: str, name: Optional[str] = None, @@ -380,7 +380,7 @@ def update( if sql_api_timeout_seconds is not None: api_params['sqlApiTimeoutSeconds'] = self._normalize_value(sql_api_timeout_seconds) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -393,7 +393,7 @@ def update( return self._parse_response(response, model=DedicatedDatabase) - def delete( + async def delete( self, database_id: str, ) -> Dict[str, Any]: @@ -421,7 +421,7 @@ def delete( raise AppwriteException('Missing required parameter: "database_id"') api_path = api_path.replace('{databaseId}', str(self._normalize_value(database_id))) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -434,7 +434,7 @@ def delete( return response - def list_backups( + async def list_backups( self, database_id: str, queries: Optional[List[str]] = None, @@ -472,7 +472,7 @@ def list_backups( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -484,7 +484,7 @@ def list_backups( return self._parse_response(response, model=DedicatedDatabaseBackupList) - def create_backup( + async def create_backup( self, database_id: str, type: Optional[str] = None, @@ -517,7 +517,7 @@ def create_backup( if type is not None: api_params['type'] = self._normalize_value(type) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -530,7 +530,7 @@ def create_backup( return self._parse_response(response, model=DedicatedDatabaseBackup) - def list_backup_policies( + async def list_backup_policies( self, database_id: str, queries: Optional[List[str]] = None, @@ -568,7 +568,7 @@ def list_backup_policies( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -580,7 +580,7 @@ def list_backup_policies( return self._parse_response(response, model=BackupPolicyList) - def create_backup_policy( + async def create_backup_policy( self, database_id: str, policy_id: str, @@ -642,7 +642,7 @@ def create_backup_policy( if enabled is not None: api_params['enabled'] = self._normalize_value(enabled) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -655,7 +655,7 @@ def create_backup_policy( return self._parse_response(response, model=BackupPolicy) - def get_backup_policy( + async def get_backup_policy( self, database_id: str, policy_id: str, @@ -689,7 +689,7 @@ def get_backup_policy( api_path = api_path.replace('{databaseId}', str(self._normalize_value(database_id))) api_path = api_path.replace('{policyId}', str(self._normalize_value(policy_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -701,7 +701,7 @@ def get_backup_policy( return self._parse_response(response, model=BackupPolicy) - def update_backup_policy( + async def update_backup_policy( self, database_id: str, policy_id: str, @@ -755,7 +755,7 @@ def update_backup_policy( if enabled is not None: api_params['enabled'] = self._normalize_value(enabled) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -768,7 +768,7 @@ def update_backup_policy( return self._parse_response(response, model=BackupPolicy) - def delete_backup_policy( + async def delete_backup_policy( self, database_id: str, policy_id: str, @@ -802,7 +802,7 @@ def delete_backup_policy( api_path = api_path.replace('{databaseId}', str(self._normalize_value(database_id))) api_path = api_path.replace('{policyId}', str(self._normalize_value(policy_id))) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -815,7 +815,7 @@ def delete_backup_policy( return response - def update_backup_storage( + async def update_backup_storage( self, database_id: str, provider: str, @@ -882,7 +882,7 @@ def update_backup_storage( api_params['accessKey'] = self._normalize_value(access_key) api_params['secretKey'] = self._normalize_value(secret_key) - response = self.client.call( + response = await self.client.call( 'put', api_path, { @@ -895,7 +895,7 @@ def update_backup_storage( return self._parse_response(response, model=DedicatedDatabaseBackupStorage) - def get_backup( + async def get_backup( self, database_id: str, backup_id: str, @@ -929,7 +929,7 @@ def get_backup( api_path = api_path.replace('{databaseId}', str(self._normalize_value(database_id))) api_path = api_path.replace('{backupId}', str(self._normalize_value(backup_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -941,7 +941,7 @@ def get_backup( return self._parse_response(response, model=DedicatedDatabaseBackup) - def delete_backup( + async def delete_backup( self, database_id: str, backup_id: str, @@ -975,7 +975,7 @@ def delete_backup( api_path = api_path.replace('{databaseId}', str(self._normalize_value(database_id))) api_path = api_path.replace('{backupId}', str(self._normalize_value(backup_id))) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -988,7 +988,7 @@ def delete_backup( return response - def list_branches( + async def list_branches( self, database_id: str, ) -> DedicatedDatabaseBranchList: @@ -1016,7 +1016,7 @@ def list_branches( raise AppwriteException('Missing required parameter: "database_id"') api_path = api_path.replace('{databaseId}', str(self._normalize_value(database_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -1028,7 +1028,7 @@ def list_branches( return self._parse_response(response, model=DedicatedDatabaseBranchList) - def create_branch( + async def create_branch( self, database_id: str, branch_id: Optional[str] = None, @@ -1066,7 +1066,7 @@ def create_branch( if ttl is not None: api_params['ttl'] = self._normalize_value(ttl) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -1079,7 +1079,7 @@ def create_branch( return self._parse_response(response, model=DedicatedDatabase) - def delete_branch( + async def delete_branch( self, database_id: str, branch_id: str, @@ -1113,7 +1113,7 @@ def delete_branch( api_path = api_path.replace('{databaseId}', str(self._normalize_value(database_id))) api_path = api_path.replace('{branchId}', str(self._normalize_value(branch_id))) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -1126,7 +1126,7 @@ def delete_branch( return self._parse_response(response, model=DedicatedDatabase) - def update_credentials( + async def update_credentials( self, database_id: str, ) -> DedicatedDatabaseOperation: @@ -1154,7 +1154,7 @@ def update_credentials( raise AppwriteException('Missing required parameter: "database_id"') api_path = api_path.replace('{databaseId}', str(self._normalize_value(database_id))) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -1167,7 +1167,7 @@ def update_credentials( return self._parse_response(response, model=DedicatedDatabaseOperation) - def create_failover( + async def create_failover( self, database_id: str, target_replica_id: Optional[str] = None, @@ -1200,7 +1200,7 @@ def create_failover( if target_replica_id is not None: api_params['targetReplicaId'] = self._normalize_value(target_replica_id) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -1213,7 +1213,7 @@ def create_failover( return self._parse_response(response, model=DedicatedDatabase) - def update_maintenance( + async def update_maintenance( self, database_id: str, day: str, @@ -1253,7 +1253,7 @@ def update_maintenance( api_params['day'] = self._normalize_value(day) api_params['hourUtc'] = self._normalize_value(hour_utc) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -1266,7 +1266,7 @@ def update_maintenance( return self._parse_response(response, model=DedicatedDatabase) - def create_migration( + async def create_migration( self, database_id: str, target_type: str, @@ -1305,7 +1305,7 @@ def create_migration( if specification is not None: api_params['specification'] = self._normalize_value(specification) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -1318,7 +1318,7 @@ def create_migration( return self._parse_response(response, model=DedicatedDatabase) - def list_operations( + async def list_operations( self, database_id: str, status: Optional[str] = None, @@ -1361,7 +1361,7 @@ def list_operations( if offset is not None: api_params['offset'] = self._normalize_value(offset) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -1373,7 +1373,7 @@ def list_operations( return self._parse_response(response, model=DedicatedDatabaseOperationList) - def get_pitr( + async def get_pitr( self, database_id: str, ) -> DedicatedDatabasePITRWindows: @@ -1401,7 +1401,7 @@ def get_pitr( raise AppwriteException('Missing required parameter: "database_id"') api_path = api_path.replace('{databaseId}', str(self._normalize_value(database_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -1413,7 +1413,7 @@ def get_pitr( return self._parse_response(response, model=DedicatedDatabasePITRWindows) - def get_replicas( + async def get_replicas( self, database_id: str, ) -> DedicatedDatabaseReplicas: @@ -1441,7 +1441,7 @@ def get_replicas( raise AppwriteException('Missing required parameter: "database_id"') api_path = api_path.replace('{databaseId}', str(self._normalize_value(database_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -1453,7 +1453,7 @@ def get_replicas( return self._parse_response(response, model=DedicatedDatabaseReplicas) - def list_restorations( + async def list_restorations( self, database_id: str, status: Optional[str] = None, @@ -1501,7 +1501,7 @@ def list_restorations( if offset is not None: api_params['offset'] = self._normalize_value(offset) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -1513,7 +1513,7 @@ def list_restorations( return self._parse_response(response, model=DedicatedDatabaseRestorationList) - def create_restoration( + async def create_restoration( self, database_id: str, type: Optional[str] = None, @@ -1578,7 +1578,7 @@ def create_restoration( if auto_promote is not None: api_params['autoPromote'] = self._normalize_value(auto_promote) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -1591,7 +1591,7 @@ def create_restoration( return self._parse_response(response, model=DedicatedDatabaseRestoration) - def get_restoration( + async def get_restoration( self, database_id: str, restoration_id: str, @@ -1625,7 +1625,7 @@ def get_restoration( api_path = api_path.replace('{databaseId}', str(self._normalize_value(database_id))) api_path = api_path.replace('{restorationId}', str(self._normalize_value(restoration_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -1637,7 +1637,7 @@ def get_restoration( return self._parse_response(response, model=DedicatedDatabaseRestoration) - def promote_restoration( + async def promote_restoration( self, database_id: str, restoration_id: str, @@ -1674,7 +1674,7 @@ def promote_restoration( api_path = api_path.replace('{databaseId}', str(self._normalize_value(database_id))) api_path = api_path.replace('{restorationId}', str(self._normalize_value(restoration_id))) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -1687,7 +1687,7 @@ def promote_restoration( return self._parse_response(response, model=DedicatedDatabaseRestoration) - def get_status( + async def get_status( self, database_id: str, ) -> DatabaseStatus: @@ -1715,7 +1715,7 @@ def get_status( raise AppwriteException('Missing required parameter: "database_id"') api_path = api_path.replace('{databaseId}', str(self._normalize_value(database_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -1727,7 +1727,7 @@ def get_status( return self._parse_response(response, model=DatabaseStatus) - def create_upgrade( + async def create_upgrade( self, database_id: str, target_version: str, @@ -1761,7 +1761,7 @@ def create_upgrade( api_path = api_path.replace('{databaseId}', str(self._normalize_value(database_id))) api_params['targetVersion'] = self._normalize_value(target_version) - response = self.client.call( + response = await self.client.call( 'post', api_path, { diff --git a/appwrite/services/mysql.py b/appwrite/services/mysql.py index 0e402fe2..dd967189 100644 --- a/appwrite/services/mysql.py +++ b/appwrite/services/mysql.py @@ -28,7 +28,7 @@ class Mysql(Service): def __init__(self, client) -> None: super(Mysql, self).__init__(client) - def list( + async def list( self, queries: Optional[List[str]] = None, total: Optional[bool] = None, @@ -60,7 +60,7 @@ def list( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -72,7 +72,7 @@ def list( return self._parse_response(response, model=DedicatedDatabaseList) - def create( + async def create( self, database_id: str, name: str, @@ -168,7 +168,7 @@ def create( if storage_autoscaling_max_gb is not None: api_params['storageAutoscalingMaxGb'] = self._normalize_value(storage_autoscaling_max_gb) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -181,7 +181,7 @@ def create( return self._parse_response(response, model=DedicatedDatabase) - def list_specifications( + async def list_specifications( self, ) -> DedicatedDatabaseSpecificationList: """ @@ -200,7 +200,7 @@ def list_specifications( api_path = '/mysql/specifications' api_params = {} - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -212,7 +212,7 @@ def list_specifications( return self._parse_response(response, model=DedicatedDatabaseSpecificationList) - def get( + async def get( self, database_id: str, ) -> DedicatedDatabase: @@ -240,7 +240,7 @@ def get( raise AppwriteException('Missing required parameter: "database_id"') api_path = api_path.replace('{databaseId}', str(self._normalize_value(database_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -252,7 +252,7 @@ def get( return self._parse_response(response, model=DedicatedDatabase) - def update( + async def update( self, database_id: str, name: Optional[str] = None, @@ -382,7 +382,7 @@ def update( if sql_api_timeout_seconds is not None: api_params['sqlApiTimeoutSeconds'] = self._normalize_value(sql_api_timeout_seconds) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -395,7 +395,7 @@ def update( return self._parse_response(response, model=DedicatedDatabase) - def delete( + async def delete( self, database_id: str, ) -> Dict[str, Any]: @@ -423,7 +423,7 @@ def delete( raise AppwriteException('Missing required parameter: "database_id"') api_path = api_path.replace('{databaseId}', str(self._normalize_value(database_id))) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -436,7 +436,7 @@ def delete( return response - def list_backups( + async def list_backups( self, database_id: str, queries: Optional[List[str]] = None, @@ -474,7 +474,7 @@ def list_backups( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -486,7 +486,7 @@ def list_backups( return self._parse_response(response, model=DedicatedDatabaseBackupList) - def create_backup( + async def create_backup( self, database_id: str, type: Optional[str] = None, @@ -519,7 +519,7 @@ def create_backup( if type is not None: api_params['type'] = self._normalize_value(type) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -532,7 +532,7 @@ def create_backup( return self._parse_response(response, model=DedicatedDatabaseBackup) - def list_backup_policies( + async def list_backup_policies( self, database_id: str, queries: Optional[List[str]] = None, @@ -570,7 +570,7 @@ def list_backup_policies( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -582,7 +582,7 @@ def list_backup_policies( return self._parse_response(response, model=BackupPolicyList) - def create_backup_policy( + async def create_backup_policy( self, database_id: str, policy_id: str, @@ -644,7 +644,7 @@ def create_backup_policy( if enabled is not None: api_params['enabled'] = self._normalize_value(enabled) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -657,7 +657,7 @@ def create_backup_policy( return self._parse_response(response, model=BackupPolicy) - def get_backup_policy( + async def get_backup_policy( self, database_id: str, policy_id: str, @@ -691,7 +691,7 @@ def get_backup_policy( api_path = api_path.replace('{databaseId}', str(self._normalize_value(database_id))) api_path = api_path.replace('{policyId}', str(self._normalize_value(policy_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -703,7 +703,7 @@ def get_backup_policy( return self._parse_response(response, model=BackupPolicy) - def update_backup_policy( + async def update_backup_policy( self, database_id: str, policy_id: str, @@ -757,7 +757,7 @@ def update_backup_policy( if enabled is not None: api_params['enabled'] = self._normalize_value(enabled) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -770,7 +770,7 @@ def update_backup_policy( return self._parse_response(response, model=BackupPolicy) - def delete_backup_policy( + async def delete_backup_policy( self, database_id: str, policy_id: str, @@ -804,7 +804,7 @@ def delete_backup_policy( api_path = api_path.replace('{databaseId}', str(self._normalize_value(database_id))) api_path = api_path.replace('{policyId}', str(self._normalize_value(policy_id))) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -817,7 +817,7 @@ def delete_backup_policy( return response - def update_backup_storage( + async def update_backup_storage( self, database_id: str, provider: str, @@ -884,7 +884,7 @@ def update_backup_storage( api_params['accessKey'] = self._normalize_value(access_key) api_params['secretKey'] = self._normalize_value(secret_key) - response = self.client.call( + response = await self.client.call( 'put', api_path, { @@ -897,7 +897,7 @@ def update_backup_storage( return self._parse_response(response, model=DedicatedDatabaseBackupStorage) - def get_backup( + async def get_backup( self, database_id: str, backup_id: str, @@ -931,7 +931,7 @@ def get_backup( api_path = api_path.replace('{databaseId}', str(self._normalize_value(database_id))) api_path = api_path.replace('{backupId}', str(self._normalize_value(backup_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -943,7 +943,7 @@ def get_backup( return self._parse_response(response, model=DedicatedDatabaseBackup) - def delete_backup( + async def delete_backup( self, database_id: str, backup_id: str, @@ -977,7 +977,7 @@ def delete_backup( api_path = api_path.replace('{databaseId}', str(self._normalize_value(database_id))) api_path = api_path.replace('{backupId}', str(self._normalize_value(backup_id))) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -990,7 +990,7 @@ def delete_backup( return response - def list_branches( + async def list_branches( self, database_id: str, ) -> DedicatedDatabaseBranchList: @@ -1018,7 +1018,7 @@ def list_branches( raise AppwriteException('Missing required parameter: "database_id"') api_path = api_path.replace('{databaseId}', str(self._normalize_value(database_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -1030,7 +1030,7 @@ def list_branches( return self._parse_response(response, model=DedicatedDatabaseBranchList) - def create_branch( + async def create_branch( self, database_id: str, branch_id: Optional[str] = None, @@ -1068,7 +1068,7 @@ def create_branch( if ttl is not None: api_params['ttl'] = self._normalize_value(ttl) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -1081,7 +1081,7 @@ def create_branch( return self._parse_response(response, model=DedicatedDatabase) - def delete_branch( + async def delete_branch( self, database_id: str, branch_id: str, @@ -1115,7 +1115,7 @@ def delete_branch( api_path = api_path.replace('{databaseId}', str(self._normalize_value(database_id))) api_path = api_path.replace('{branchId}', str(self._normalize_value(branch_id))) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -1128,7 +1128,7 @@ def delete_branch( return self._parse_response(response, model=DedicatedDatabase) - def update_credentials( + async def update_credentials( self, database_id: str, ) -> DedicatedDatabaseOperation: @@ -1156,7 +1156,7 @@ def update_credentials( raise AppwriteException('Missing required parameter: "database_id"') api_path = api_path.replace('{databaseId}', str(self._normalize_value(database_id))) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -1169,7 +1169,7 @@ def update_credentials( return self._parse_response(response, model=DedicatedDatabaseOperation) - def create_execution( + async def create_execution( self, database_id: str, sql: str, @@ -1213,7 +1213,7 @@ def create_execution( if timeout_seconds is not None: api_params['timeoutSeconds'] = self._normalize_value(timeout_seconds) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -1226,7 +1226,7 @@ def create_execution( return self._parse_response(response, model=DedicatedDatabaseExecution) - def create_failover( + async def create_failover( self, database_id: str, target_replica_id: Optional[str] = None, @@ -1259,7 +1259,7 @@ def create_failover( if target_replica_id is not None: api_params['targetReplicaId'] = self._normalize_value(target_replica_id) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -1272,7 +1272,7 @@ def create_failover( return self._parse_response(response, model=DedicatedDatabase) - def update_maintenance( + async def update_maintenance( self, database_id: str, day: str, @@ -1312,7 +1312,7 @@ def update_maintenance( api_params['day'] = self._normalize_value(day) api_params['hourUtc'] = self._normalize_value(hour_utc) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -1325,7 +1325,7 @@ def update_maintenance( return self._parse_response(response, model=DedicatedDatabase) - def create_migration( + async def create_migration( self, database_id: str, target_type: str, @@ -1364,7 +1364,7 @@ def create_migration( if specification is not None: api_params['specification'] = self._normalize_value(specification) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -1377,7 +1377,7 @@ def create_migration( return self._parse_response(response, model=DedicatedDatabase) - def list_operations( + async def list_operations( self, database_id: str, status: Optional[str] = None, @@ -1420,7 +1420,7 @@ def list_operations( if offset is not None: api_params['offset'] = self._normalize_value(offset) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -1432,7 +1432,7 @@ def list_operations( return self._parse_response(response, model=DedicatedDatabaseOperationList) - def get_pitr( + async def get_pitr( self, database_id: str, ) -> DedicatedDatabasePITRWindows: @@ -1460,7 +1460,7 @@ def get_pitr( raise AppwriteException('Missing required parameter: "database_id"') api_path = api_path.replace('{databaseId}', str(self._normalize_value(database_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -1472,7 +1472,7 @@ def get_pitr( return self._parse_response(response, model=DedicatedDatabasePITRWindows) - def get_pooler( + async def get_pooler( self, database_id: str, ) -> DedicatedDatabasePooler: @@ -1500,7 +1500,7 @@ def get_pooler( raise AppwriteException('Missing required parameter: "database_id"') api_path = api_path.replace('{databaseId}', str(self._normalize_value(database_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -1512,7 +1512,7 @@ def get_pooler( return self._parse_response(response, model=DedicatedDatabasePooler) - def update_pooler( + async def update_pooler( self, database_id: str, mode: Optional[str] = None, @@ -1580,7 +1580,7 @@ def update_pooler( if pooler_memory_limit is not None: api_params['poolerMemoryLimit'] = self._normalize_value(pooler_memory_limit) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -1593,7 +1593,7 @@ def update_pooler( return self._parse_response(response, model=DedicatedDatabasePooler) - def get_replicas( + async def get_replicas( self, database_id: str, ) -> DedicatedDatabaseReplicas: @@ -1621,7 +1621,7 @@ def get_replicas( raise AppwriteException('Missing required parameter: "database_id"') api_path = api_path.replace('{databaseId}', str(self._normalize_value(database_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -1633,7 +1633,7 @@ def get_replicas( return self._parse_response(response, model=DedicatedDatabaseReplicas) - def list_restorations( + async def list_restorations( self, database_id: str, status: Optional[str] = None, @@ -1681,7 +1681,7 @@ def list_restorations( if offset is not None: api_params['offset'] = self._normalize_value(offset) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -1693,7 +1693,7 @@ def list_restorations( return self._parse_response(response, model=DedicatedDatabaseRestorationList) - def create_restoration( + async def create_restoration( self, database_id: str, type: Optional[str] = None, @@ -1758,7 +1758,7 @@ def create_restoration( if auto_promote is not None: api_params['autoPromote'] = self._normalize_value(auto_promote) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -1771,7 +1771,7 @@ def create_restoration( return self._parse_response(response, model=DedicatedDatabaseRestoration) - def get_restoration( + async def get_restoration( self, database_id: str, restoration_id: str, @@ -1805,7 +1805,7 @@ def get_restoration( api_path = api_path.replace('{databaseId}', str(self._normalize_value(database_id))) api_path = api_path.replace('{restorationId}', str(self._normalize_value(restoration_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -1817,7 +1817,7 @@ def get_restoration( return self._parse_response(response, model=DedicatedDatabaseRestoration) - def promote_restoration( + async def promote_restoration( self, database_id: str, restoration_id: str, @@ -1854,7 +1854,7 @@ def promote_restoration( api_path = api_path.replace('{databaseId}', str(self._normalize_value(database_id))) api_path = api_path.replace('{restorationId}', str(self._normalize_value(restoration_id))) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -1867,7 +1867,7 @@ def promote_restoration( return self._parse_response(response, model=DedicatedDatabaseRestoration) - def get_status( + async def get_status( self, database_id: str, ) -> DatabaseStatus: @@ -1895,7 +1895,7 @@ def get_status( raise AppwriteException('Missing required parameter: "database_id"') api_path = api_path.replace('{databaseId}', str(self._normalize_value(database_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -1907,7 +1907,7 @@ def get_status( return self._parse_response(response, model=DatabaseStatus) - def create_upgrade( + async def create_upgrade( self, database_id: str, target_version: str, @@ -1941,7 +1941,7 @@ def create_upgrade( api_path = api_path.replace('{databaseId}', str(self._normalize_value(database_id))) api_params['targetVersion'] = self._normalize_value(target_version) - response = self.client.call( + response = await self.client.call( 'post', api_path, { diff --git a/appwrite/services/oauth2.py b/appwrite/services/oauth2.py index 774dcf2c..cc887f35 100644 --- a/appwrite/services/oauth2.py +++ b/appwrite/services/oauth2.py @@ -20,7 +20,7 @@ class Oauth2(Service): def __init__(self, client) -> None: super(Oauth2, self).__init__(client) - def approve( + async def approve( self, grant_id: str, authorization_details: Optional[str] = None, @@ -59,7 +59,7 @@ def approve( if scope is not None: api_params['scope'] = self._normalize_value(scope) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -71,7 +71,7 @@ def approve( return self._parse_response(response, model=Oauth2Approve) - def authorize( + async def authorize( self, client_id: Optional[str] = None, redirect_uri: Optional[str] = None, @@ -164,7 +164,7 @@ def authorize( if request_uri is not None: api_params['request_uri'] = self._normalize_value(request_uri) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -175,7 +175,7 @@ def authorize( return self._parse_response(response, model=Oauth2Authorize) - def authorize_post( + async def authorize_post( self, client_id: Optional[str] = None, redirect_uri: Optional[str] = None, @@ -268,7 +268,7 @@ def authorize_post( if request_uri is not None: api_params['request_uri'] = self._normalize_value(request_uri) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -280,7 +280,7 @@ def authorize_post( return self._parse_response(response, model=Oauth2Authorize) - def create_device_authorization( + async def create_device_authorization( self, client_id: Optional[str] = None, scope: Optional[str] = None, @@ -328,7 +328,7 @@ def create_device_authorization( if audience is not None: api_params['audience'] = self._normalize_value(audience) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -340,7 +340,7 @@ def create_device_authorization( return self._parse_response(response, model=Oauth2DeviceAuthorization) - def create_grant( + async def create_grant( self, user_code: str, ) -> Oauth2Grant: @@ -369,7 +369,7 @@ def create_grant( api_path = api_path.replace('{project_id}', str(self._normalize_value(self.client.get_config('project')))) api_params['user_code'] = self._normalize_value(user_code) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -381,7 +381,7 @@ def create_grant( return self._parse_response(response, model=Oauth2Grant) - def get_grant( + async def get_grant( self, grant_id: str, ) -> Oauth2Grant: @@ -410,7 +410,7 @@ def get_grant( api_path = api_path.replace('{project_id}', str(self._normalize_value(self.client.get_config('project')))) api_path = api_path.replace('{grant_id}', str(self._normalize_value(grant_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -421,7 +421,7 @@ def get_grant( return self._parse_response(response, model=Oauth2Grant) - def introspect( + async def introspect( self, token: str, token_type_hint: Optional[str] = None, @@ -465,7 +465,7 @@ def introspect( if client_secret is not None: api_params['client_secret'] = self._normalize_value(client_secret) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -477,7 +477,7 @@ def introspect( return self._parse_response(response, model=Oauth2Introspection) - def list_organizations( + async def list_organizations( self, limit: Optional[float] = None, offset: Optional[float] = None, @@ -515,7 +515,7 @@ def list_organizations( if search is not None: api_params['search'] = self._normalize_value(search) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -526,7 +526,7 @@ def list_organizations( return self._parse_response(response, model=Oauth2OrganizationList) - def create_par( + async def create_par( self, client_id: str, redirect_uri: str, @@ -617,7 +617,7 @@ def create_par( if audience is not None: api_params['audience'] = self._normalize_value(audience) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -629,7 +629,7 @@ def create_par( return self._parse_response(response, model=Oauth2PAR) - def list_projects( + async def list_projects( self, limit: Optional[float] = None, offset: Optional[float] = None, @@ -667,7 +667,7 @@ def list_projects( if search is not None: api_params['search'] = self._normalize_value(search) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -678,7 +678,7 @@ def list_projects( return self._parse_response(response, model=Oauth2ProjectList) - def reject( + async def reject( self, grant_id: str, ) -> Oauth2Reject: @@ -707,7 +707,7 @@ def reject( api_path = api_path.replace('{project_id}', str(self._normalize_value(self.client.get_config('project')))) api_params['grant_id'] = self._normalize_value(grant_id) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -719,7 +719,7 @@ def reject( return self._parse_response(response, model=Oauth2Reject) - def revoke( + async def revoke( self, token: str, token_type_hint: Optional[str] = None, @@ -763,7 +763,7 @@ def revoke( if client_secret is not None: api_params['client_secret'] = self._normalize_value(client_secret) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -775,7 +775,7 @@ def revoke( return response - def create_token( + async def create_token( self, grant_type: str, code: Optional[str] = None, @@ -849,7 +849,7 @@ def create_token( if audience is not None: api_params['audience'] = self._normalize_value(audience) - response = self.client.call( + response = await self.client.call( 'post', api_path, { diff --git a/appwrite/services/organization.py b/appwrite/services/organization.py index ecb7efdb..44c67397 100644 --- a/appwrite/services/organization.py +++ b/appwrite/services/organization.py @@ -24,7 +24,7 @@ class Organization(Service): def __init__(self, client) -> None: super(Organization, self).__init__(client) - def get( + async def get( self, model_type: Type[T] = dict, ) -> OrganizationModel[T]: @@ -50,7 +50,7 @@ def get( api_path = '/organization' api_params = {} - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -62,7 +62,7 @@ def get( return OrganizationModel.with_data(response, model_type) - def update( + async def update( self, name: str, model_type: Type[T] = dict, @@ -94,7 +94,7 @@ def update( raise AppwriteException('Missing required parameter: "name"') api_params['name'] = self._normalize_value(name) - response = self.client.call( + response = await self.client.call( 'put', api_path, { @@ -107,7 +107,7 @@ def update( return OrganizationModel.with_data(response, model_type) - def delete( + async def delete( self, ) -> Dict[str, Any]: """ @@ -126,7 +126,7 @@ def delete( api_path = '/organization' api_params = {} - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -139,7 +139,7 @@ def delete( return response - def list_installations( + async def list_installations( self, queries: Optional[List[str]] = None, total: Optional[bool] = None, @@ -171,7 +171,7 @@ def list_installations( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -183,7 +183,7 @@ def list_installations( return self._parse_response(response, model=AppInstallationList) - def create_installation( + async def create_installation( self, app_id: str, authorization_details: Optional[str] = None, @@ -216,7 +216,7 @@ def create_installation( if authorization_details is not None: api_params['authorizationDetails'] = self._normalize_value(authorization_details) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -229,7 +229,7 @@ def create_installation( return self._parse_response(response, model=AppInstallation) - def get_installation( + async def get_installation( self, installation_id: str, ) -> AppInstallation: @@ -257,7 +257,7 @@ def get_installation( raise AppwriteException('Missing required parameter: "installation_id"') api_path = api_path.replace('{installationId}', str(self._normalize_value(installation_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -269,7 +269,7 @@ def get_installation( return self._parse_response(response, model=AppInstallation) - def update_installation( + async def update_installation( self, installation_id: str, authorization_details: Optional[str] = None, @@ -302,7 +302,7 @@ def update_installation( if authorization_details is not None: api_params['authorizationDetails'] = self._normalize_value(authorization_details) - response = self.client.call( + response = await self.client.call( 'put', api_path, { @@ -315,7 +315,7 @@ def update_installation( return self._parse_response(response, model=AppInstallation) - def delete_installation( + async def delete_installation( self, installation_id: str, ) -> Dict[str, Any]: @@ -343,7 +343,7 @@ def delete_installation( raise AppwriteException('Missing required parameter: "installation_id"') api_path = api_path.replace('{installationId}', str(self._normalize_value(installation_id))) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -356,7 +356,7 @@ def delete_installation( return response - def list_memberships( + async def list_memberships( self, queries: Optional[List[str]] = None, search: Optional[str] = None, @@ -393,7 +393,7 @@ def list_memberships( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -405,7 +405,7 @@ def list_memberships( return self._parse_response(response, model=MembershipList) - def create_membership( + async def create_membership( self, roles: List[str], email: Optional[str] = None, @@ -458,7 +458,7 @@ def create_membership( if name is not None: api_params['name'] = self._normalize_value(name) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -471,7 +471,7 @@ def create_membership( return self._parse_response(response, model=Membership) - def get_membership( + async def get_membership( self, membership_id: str, ) -> Membership: @@ -499,7 +499,7 @@ def get_membership( raise AppwriteException('Missing required parameter: "membership_id"') api_path = api_path.replace('{membershipId}', str(self._normalize_value(membership_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -511,7 +511,7 @@ def get_membership( return self._parse_response(response, model=Membership) - def update_membership( + async def update_membership( self, membership_id: str, roles: List[str], @@ -545,7 +545,7 @@ def update_membership( api_path = api_path.replace('{membershipId}', str(self._normalize_value(membership_id))) api_params['roles'] = self._normalize_value(roles) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -558,7 +558,7 @@ def update_membership( return self._parse_response(response, model=Membership) - def delete_membership( + async def delete_membership( self, membership_id: str, ) -> Dict[str, Any]: @@ -586,7 +586,7 @@ def delete_membership( raise AppwriteException('Missing required parameter: "membership_id"') api_path = api_path.replace('{membershipId}', str(self._normalize_value(membership_id))) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -599,7 +599,7 @@ def delete_membership( return response - def list_projects( + async def list_projects( self, queries: Optional[List[str]] = None, search: Optional[str] = None, @@ -636,7 +636,7 @@ def list_projects( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -648,7 +648,7 @@ def list_projects( return self._parse_response(response, model=ProjectList) - def create_project( + async def create_project( self, project_id: str, name: str, @@ -687,7 +687,7 @@ def create_project( if region is not None: api_params['region'] = self._normalize_value(region) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -700,7 +700,7 @@ def create_project( return self._parse_response(response, model=Project) - def get_project( + async def get_project( self, project_id: str, ) -> Project: @@ -728,7 +728,7 @@ def get_project( raise AppwriteException('Missing required parameter: "project_id"') api_path = api_path.replace('{projectId}', str(self._normalize_value(project_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -740,7 +740,7 @@ def get_project( return self._parse_response(response, model=Project) - def update_project( + async def update_project( self, project_id: str, name: str, @@ -774,7 +774,7 @@ def update_project( api_path = api_path.replace('{projectId}', str(self._normalize_value(project_id))) api_params['name'] = self._normalize_value(name) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -787,7 +787,7 @@ def update_project( return self._parse_response(response, model=Project) - def delete_project( + async def delete_project( self, project_id: str, ) -> Dict[str, Any]: @@ -815,7 +815,7 @@ def delete_project( raise AppwriteException('Missing required parameter: "project_id"') api_path = api_path.replace('{projectId}', str(self._normalize_value(project_id))) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -828,7 +828,7 @@ def delete_project( return response - def list_project_keys( + async def list_project_keys( self, project_id: str, queries: Optional[List[str]] = None, @@ -866,7 +866,7 @@ def list_project_keys( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -878,7 +878,7 @@ def list_project_keys( return self._parse_response(response, model=KeyList) - def create_ephemeral_project_key( + async def create_ephemeral_project_key( self, project_id: str, scopes: List[ProjectKeyScopes], @@ -920,7 +920,7 @@ def create_ephemeral_project_key( api_params['scopes'] = self._normalize_value(scopes) api_params['duration'] = self._normalize_value(duration) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -933,7 +933,7 @@ def create_ephemeral_project_key( return self._parse_response(response, model=EphemeralKey) - def get_project_key( + async def get_project_key( self, project_id: str, key_id: str, @@ -967,7 +967,7 @@ def get_project_key( api_path = api_path.replace('{projectId}', str(self._normalize_value(project_id))) api_path = api_path.replace('{keyId}', str(self._normalize_value(key_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -979,7 +979,7 @@ def get_project_key( return self._parse_response(response, model=Key) - def update_project_key( + async def update_project_key( self, project_id: str, key_id: str, @@ -1035,7 +1035,7 @@ def update_project_key( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'put', api_path, { @@ -1048,7 +1048,7 @@ def update_project_key( return self._parse_response(response, model=Key) - def delete_project_key( + async def delete_project_key( self, project_id: str, key_id: str, @@ -1082,7 +1082,7 @@ def delete_project_key( api_path = api_path.replace('{projectId}', str(self._normalize_value(project_id))) api_path = api_path.replace('{keyId}', str(self._normalize_value(key_id))) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { diff --git a/appwrite/services/postgresql.py b/appwrite/services/postgresql.py index a5692e05..bcd1e500 100644 --- a/appwrite/services/postgresql.py +++ b/appwrite/services/postgresql.py @@ -29,7 +29,7 @@ class Postgresql(Service): def __init__(self, client) -> None: super(Postgresql, self).__init__(client) - def list( + async def list( self, queries: Optional[List[str]] = None, total: Optional[bool] = None, @@ -61,7 +61,7 @@ def list( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -73,7 +73,7 @@ def list( return self._parse_response(response, model=DedicatedDatabaseList) - def create( + async def create( self, database_id: str, name: str, @@ -169,7 +169,7 @@ def create( if storage_autoscaling_max_gb is not None: api_params['storageAutoscalingMaxGb'] = self._normalize_value(storage_autoscaling_max_gb) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -182,7 +182,7 @@ def create( return self._parse_response(response, model=DedicatedDatabase) - def list_specifications( + async def list_specifications( self, ) -> DedicatedDatabaseSpecificationList: """ @@ -201,7 +201,7 @@ def list_specifications( api_path = '/postgresql/specifications' api_params = {} - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -213,7 +213,7 @@ def list_specifications( return self._parse_response(response, model=DedicatedDatabaseSpecificationList) - def get( + async def get( self, database_id: str, ) -> DedicatedDatabase: @@ -241,7 +241,7 @@ def get( raise AppwriteException('Missing required parameter: "database_id"') api_path = api_path.replace('{databaseId}', str(self._normalize_value(database_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -253,7 +253,7 @@ def get( return self._parse_response(response, model=DedicatedDatabase) - def update( + async def update( self, database_id: str, name: Optional[str] = None, @@ -383,7 +383,7 @@ def update( if sql_api_timeout_seconds is not None: api_params['sqlApiTimeoutSeconds'] = self._normalize_value(sql_api_timeout_seconds) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -396,7 +396,7 @@ def update( return self._parse_response(response, model=DedicatedDatabase) - def delete( + async def delete( self, database_id: str, ) -> Dict[str, Any]: @@ -424,7 +424,7 @@ def delete( raise AppwriteException('Missing required parameter: "database_id"') api_path = api_path.replace('{databaseId}', str(self._normalize_value(database_id))) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -437,7 +437,7 @@ def delete( return response - def list_backups( + async def list_backups( self, database_id: str, queries: Optional[List[str]] = None, @@ -475,7 +475,7 @@ def list_backups( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -487,7 +487,7 @@ def list_backups( return self._parse_response(response, model=DedicatedDatabaseBackupList) - def create_backup( + async def create_backup( self, database_id: str, type: Optional[str] = None, @@ -520,7 +520,7 @@ def create_backup( if type is not None: api_params['type'] = self._normalize_value(type) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -533,7 +533,7 @@ def create_backup( return self._parse_response(response, model=DedicatedDatabaseBackup) - def list_backup_policies( + async def list_backup_policies( self, database_id: str, queries: Optional[List[str]] = None, @@ -571,7 +571,7 @@ def list_backup_policies( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -583,7 +583,7 @@ def list_backup_policies( return self._parse_response(response, model=BackupPolicyList) - def create_backup_policy( + async def create_backup_policy( self, database_id: str, policy_id: str, @@ -645,7 +645,7 @@ def create_backup_policy( if enabled is not None: api_params['enabled'] = self._normalize_value(enabled) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -658,7 +658,7 @@ def create_backup_policy( return self._parse_response(response, model=BackupPolicy) - def get_backup_policy( + async def get_backup_policy( self, database_id: str, policy_id: str, @@ -692,7 +692,7 @@ def get_backup_policy( api_path = api_path.replace('{databaseId}', str(self._normalize_value(database_id))) api_path = api_path.replace('{policyId}', str(self._normalize_value(policy_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -704,7 +704,7 @@ def get_backup_policy( return self._parse_response(response, model=BackupPolicy) - def update_backup_policy( + async def update_backup_policy( self, database_id: str, policy_id: str, @@ -758,7 +758,7 @@ def update_backup_policy( if enabled is not None: api_params['enabled'] = self._normalize_value(enabled) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -771,7 +771,7 @@ def update_backup_policy( return self._parse_response(response, model=BackupPolicy) - def delete_backup_policy( + async def delete_backup_policy( self, database_id: str, policy_id: str, @@ -805,7 +805,7 @@ def delete_backup_policy( api_path = api_path.replace('{databaseId}', str(self._normalize_value(database_id))) api_path = api_path.replace('{policyId}', str(self._normalize_value(policy_id))) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -818,7 +818,7 @@ def delete_backup_policy( return response - def update_backup_storage( + async def update_backup_storage( self, database_id: str, provider: str, @@ -885,7 +885,7 @@ def update_backup_storage( api_params['accessKey'] = self._normalize_value(access_key) api_params['secretKey'] = self._normalize_value(secret_key) - response = self.client.call( + response = await self.client.call( 'put', api_path, { @@ -898,7 +898,7 @@ def update_backup_storage( return self._parse_response(response, model=DedicatedDatabaseBackupStorage) - def get_backup( + async def get_backup( self, database_id: str, backup_id: str, @@ -932,7 +932,7 @@ def get_backup( api_path = api_path.replace('{databaseId}', str(self._normalize_value(database_id))) api_path = api_path.replace('{backupId}', str(self._normalize_value(backup_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -944,7 +944,7 @@ def get_backup( return self._parse_response(response, model=DedicatedDatabaseBackup) - def delete_backup( + async def delete_backup( self, database_id: str, backup_id: str, @@ -978,7 +978,7 @@ def delete_backup( api_path = api_path.replace('{databaseId}', str(self._normalize_value(database_id))) api_path = api_path.replace('{backupId}', str(self._normalize_value(backup_id))) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -991,7 +991,7 @@ def delete_backup( return response - def list_branches( + async def list_branches( self, database_id: str, ) -> DedicatedDatabaseBranchList: @@ -1019,7 +1019,7 @@ def list_branches( raise AppwriteException('Missing required parameter: "database_id"') api_path = api_path.replace('{databaseId}', str(self._normalize_value(database_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -1031,7 +1031,7 @@ def list_branches( return self._parse_response(response, model=DedicatedDatabaseBranchList) - def create_branch( + async def create_branch( self, database_id: str, branch_id: Optional[str] = None, @@ -1069,7 +1069,7 @@ def create_branch( if ttl is not None: api_params['ttl'] = self._normalize_value(ttl) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -1082,7 +1082,7 @@ def create_branch( return self._parse_response(response, model=DedicatedDatabase) - def delete_branch( + async def delete_branch( self, database_id: str, branch_id: str, @@ -1116,7 +1116,7 @@ def delete_branch( api_path = api_path.replace('{databaseId}', str(self._normalize_value(database_id))) api_path = api_path.replace('{branchId}', str(self._normalize_value(branch_id))) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -1129,7 +1129,7 @@ def delete_branch( return self._parse_response(response, model=DedicatedDatabase) - def update_credentials( + async def update_credentials( self, database_id: str, ) -> DedicatedDatabaseOperation: @@ -1157,7 +1157,7 @@ def update_credentials( raise AppwriteException('Missing required parameter: "database_id"') api_path = api_path.replace('{databaseId}', str(self._normalize_value(database_id))) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -1170,7 +1170,7 @@ def update_credentials( return self._parse_response(response, model=DedicatedDatabaseOperation) - def create_execution( + async def create_execution( self, database_id: str, sql: str, @@ -1214,7 +1214,7 @@ def create_execution( if timeout_seconds is not None: api_params['timeoutSeconds'] = self._normalize_value(timeout_seconds) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -1227,7 +1227,7 @@ def create_execution( return self._parse_response(response, model=DedicatedDatabaseExecution) - def list_extensions( + async def list_extensions( self, database_id: str, ) -> DedicatedDatabaseExtensions: @@ -1255,7 +1255,7 @@ def list_extensions( raise AppwriteException('Missing required parameter: "database_id"') api_path = api_path.replace('{databaseId}', str(self._normalize_value(database_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -1267,7 +1267,7 @@ def list_extensions( return self._parse_response(response, model=DedicatedDatabaseExtensions) - def create_extension( + async def create_extension( self, database_id: str, name: str, @@ -1301,7 +1301,7 @@ def create_extension( api_path = api_path.replace('{databaseId}', str(self._normalize_value(database_id))) api_params['name'] = self._normalize_value(name) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -1314,7 +1314,7 @@ def create_extension( return self._parse_response(response, model=DedicatedDatabase) - def delete_extension( + async def delete_extension( self, database_id: str, extension_name: str, @@ -1348,7 +1348,7 @@ def delete_extension( api_path = api_path.replace('{databaseId}', str(self._normalize_value(database_id))) api_path = api_path.replace('{extensionName}', str(self._normalize_value(extension_name))) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -1361,7 +1361,7 @@ def delete_extension( return self._parse_response(response, model=DedicatedDatabase) - def create_failover( + async def create_failover( self, database_id: str, target_replica_id: Optional[str] = None, @@ -1394,7 +1394,7 @@ def create_failover( if target_replica_id is not None: api_params['targetReplicaId'] = self._normalize_value(target_replica_id) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -1407,7 +1407,7 @@ def create_failover( return self._parse_response(response, model=DedicatedDatabase) - def update_maintenance( + async def update_maintenance( self, database_id: str, day: str, @@ -1447,7 +1447,7 @@ def update_maintenance( api_params['day'] = self._normalize_value(day) api_params['hourUtc'] = self._normalize_value(hour_utc) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -1460,7 +1460,7 @@ def update_maintenance( return self._parse_response(response, model=DedicatedDatabase) - def create_migration( + async def create_migration( self, database_id: str, target_type: str, @@ -1499,7 +1499,7 @@ def create_migration( if specification is not None: api_params['specification'] = self._normalize_value(specification) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -1512,7 +1512,7 @@ def create_migration( return self._parse_response(response, model=DedicatedDatabase) - def list_operations( + async def list_operations( self, database_id: str, status: Optional[str] = None, @@ -1555,7 +1555,7 @@ def list_operations( if offset is not None: api_params['offset'] = self._normalize_value(offset) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -1567,7 +1567,7 @@ def list_operations( return self._parse_response(response, model=DedicatedDatabaseOperationList) - def get_pitr( + async def get_pitr( self, database_id: str, ) -> DedicatedDatabasePITRWindows: @@ -1595,7 +1595,7 @@ def get_pitr( raise AppwriteException('Missing required parameter: "database_id"') api_path = api_path.replace('{databaseId}', str(self._normalize_value(database_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -1607,7 +1607,7 @@ def get_pitr( return self._parse_response(response, model=DedicatedDatabasePITRWindows) - def get_pooler( + async def get_pooler( self, database_id: str, ) -> DedicatedDatabasePooler: @@ -1635,7 +1635,7 @@ def get_pooler( raise AppwriteException('Missing required parameter: "database_id"') api_path = api_path.replace('{databaseId}', str(self._normalize_value(database_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -1647,7 +1647,7 @@ def get_pooler( return self._parse_response(response, model=DedicatedDatabasePooler) - def update_pooler( + async def update_pooler( self, database_id: str, mode: Optional[str] = None, @@ -1715,7 +1715,7 @@ def update_pooler( if pooler_memory_limit is not None: api_params['poolerMemoryLimit'] = self._normalize_value(pooler_memory_limit) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -1728,7 +1728,7 @@ def update_pooler( return self._parse_response(response, model=DedicatedDatabasePooler) - def get_replicas( + async def get_replicas( self, database_id: str, ) -> DedicatedDatabaseReplicas: @@ -1756,7 +1756,7 @@ def get_replicas( raise AppwriteException('Missing required parameter: "database_id"') api_path = api_path.replace('{databaseId}', str(self._normalize_value(database_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -1768,7 +1768,7 @@ def get_replicas( return self._parse_response(response, model=DedicatedDatabaseReplicas) - def list_restorations( + async def list_restorations( self, database_id: str, status: Optional[str] = None, @@ -1816,7 +1816,7 @@ def list_restorations( if offset is not None: api_params['offset'] = self._normalize_value(offset) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -1828,7 +1828,7 @@ def list_restorations( return self._parse_response(response, model=DedicatedDatabaseRestorationList) - def create_restoration( + async def create_restoration( self, database_id: str, type: Optional[str] = None, @@ -1893,7 +1893,7 @@ def create_restoration( if auto_promote is not None: api_params['autoPromote'] = self._normalize_value(auto_promote) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -1906,7 +1906,7 @@ def create_restoration( return self._parse_response(response, model=DedicatedDatabaseRestoration) - def get_restoration( + async def get_restoration( self, database_id: str, restoration_id: str, @@ -1940,7 +1940,7 @@ def get_restoration( api_path = api_path.replace('{databaseId}', str(self._normalize_value(database_id))) api_path = api_path.replace('{restorationId}', str(self._normalize_value(restoration_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -1952,7 +1952,7 @@ def get_restoration( return self._parse_response(response, model=DedicatedDatabaseRestoration) - def promote_restoration( + async def promote_restoration( self, database_id: str, restoration_id: str, @@ -1989,7 +1989,7 @@ def promote_restoration( api_path = api_path.replace('{databaseId}', str(self._normalize_value(database_id))) api_path = api_path.replace('{restorationId}', str(self._normalize_value(restoration_id))) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -2002,7 +2002,7 @@ def promote_restoration( return self._parse_response(response, model=DedicatedDatabaseRestoration) - def get_status( + async def get_status( self, database_id: str, ) -> DatabaseStatus: @@ -2030,7 +2030,7 @@ def get_status( raise AppwriteException('Missing required parameter: "database_id"') api_path = api_path.replace('{databaseId}', str(self._normalize_value(database_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -2042,7 +2042,7 @@ def get_status( return self._parse_response(response, model=DatabaseStatus) - def create_upgrade( + async def create_upgrade( self, database_id: str, target_version: str, @@ -2076,7 +2076,7 @@ def create_upgrade( api_path = api_path.replace('{databaseId}', str(self._normalize_value(database_id))) api_params['targetVersion'] = self._normalize_value(target_version) - response = self.client.call( + response = await self.client.call( 'post', api_path, { diff --git a/appwrite/services/presences.py b/appwrite/services/presences.py index 7066914a..5f93c23e 100644 --- a/appwrite/services/presences.py +++ b/appwrite/services/presences.py @@ -12,7 +12,7 @@ class Presences(Service): def __init__(self, client) -> None: super(Presences, self).__init__(client) - def list( + async def list( self, queries: Optional[List[str]] = None, total: Optional[bool] = None, @@ -49,7 +49,7 @@ def list( if ttl is not None: api_params['ttl'] = self._normalize_value(ttl) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -61,7 +61,7 @@ def list( return self._parse_response(response, model=PresenceList) - def get( + async def get( self, presence_id: str, ) -> Presence: @@ -89,7 +89,7 @@ def get( raise AppwriteException('Missing required parameter: "presence_id"') api_path = api_path.replace('{presenceId}', str(self._normalize_value(presence_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -101,7 +101,7 @@ def get( return self._parse_response(response, model=Presence) - def upsert( + async def upsert( self, presence_id: str, user_id: str, @@ -156,7 +156,7 @@ def upsert( if metadata is not None: api_params['metadata'] = self._normalize_value(metadata) - response = self.client.call( + response = await self.client.call( 'put', api_path, { @@ -169,7 +169,7 @@ def upsert( return self._parse_response(response, model=Presence) - def update( + async def update( self, presence_id: str, user_id: str, @@ -228,7 +228,7 @@ def update( if purge is not None: api_params['purge'] = self._normalize_value(purge) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -241,7 +241,7 @@ def update( return self._parse_response(response, model=Presence) - def delete( + async def delete( self, presence_id: str, ) -> Dict[str, Any]: @@ -269,7 +269,7 @@ def delete( raise AppwriteException('Missing required parameter: "presence_id"') api_path = api_path.replace('{presenceId}', str(self._normalize_value(presence_id))) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { diff --git a/appwrite/services/project.py b/appwrite/services/project.py index d1d6da2d..39f054c3 100644 --- a/appwrite/services/project.py +++ b/appwrite/services/project.py @@ -113,7 +113,7 @@ class Project(Service): def __init__(self, client) -> None: super(Project, self).__init__(client) - def get( + async def get( self, ) -> ProjectModel: """ @@ -132,7 +132,7 @@ def get( api_path = '/project' api_params = {} - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -144,7 +144,7 @@ def get( return self._parse_response(response, model=ProjectModel) - def delete( + async def delete( self, ) -> Dict[str, Any]: """ @@ -163,7 +163,7 @@ def delete( api_path = '/project' api_params = {} - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -176,7 +176,7 @@ def delete( return response - def update_auth_method( + async def update_auth_method( self, method_id: ProjectAuthMethodId, enabled: bool, @@ -210,7 +210,7 @@ def update_auth_method( api_path = api_path.replace('{methodId}', str(self._normalize_value(method_id))) api_params['enabled'] = self._normalize_value(enabled) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -223,7 +223,7 @@ def update_auth_method( return self._parse_response(response, model=ProjectModel) - def list_environments( + async def list_environments( self, queries: Optional[List[str]] = None, total: Optional[bool] = None, @@ -255,7 +255,7 @@ def list_environments( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -267,7 +267,7 @@ def list_environments( return self._parse_response(response, model=ProjectList) - def create_environment( + async def create_environment( self, environment_id: str, name: str, @@ -301,7 +301,7 @@ def create_environment( api_params['environmentId'] = self._normalize_value(environment_id) api_params['name'] = self._normalize_value(name) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -314,7 +314,7 @@ def create_environment( return self._parse_response(response, model=ProjectModel) - def get_environment( + async def get_environment( self, environment_id: str, ) -> ProjectModel: @@ -342,7 +342,7 @@ def get_environment( raise AppwriteException('Missing required parameter: "environment_id"') api_path = api_path.replace('{environmentId}', str(self._normalize_value(environment_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -354,7 +354,7 @@ def get_environment( return self._parse_response(response, model=ProjectModel) - def update_environment( + async def update_environment( self, environment_id: str, name: str, @@ -388,7 +388,7 @@ def update_environment( api_path = api_path.replace('{environmentId}', str(self._normalize_value(environment_id))) api_params['name'] = self._normalize_value(name) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -401,7 +401,7 @@ def update_environment( return self._parse_response(response, model=ProjectModel) - def delete_environment( + async def delete_environment( self, environment_id: str, ) -> Dict[str, Any]: @@ -429,7 +429,7 @@ def delete_environment( raise AppwriteException('Missing required parameter: "environment_id"') api_path = api_path.replace('{environmentId}', str(self._normalize_value(environment_id))) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -442,7 +442,7 @@ def delete_environment( return response - def list_keys( + async def list_keys( self, queries: Optional[List[str]] = None, total: Optional[bool] = None, @@ -474,7 +474,7 @@ def list_keys( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -486,7 +486,7 @@ def list_keys( return self._parse_response(response, model=KeyList) - def create_ephemeral_key( + async def create_ephemeral_key( self, scopes: List[ProjectKeyScopes], duration: float, @@ -522,7 +522,7 @@ def create_ephemeral_key( api_params['scopes'] = self._normalize_value(scopes) api_params['duration'] = self._normalize_value(duration) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -535,7 +535,7 @@ def create_ephemeral_key( return self._parse_response(response, model=EphemeralKey) - def get_key( + async def get_key( self, key_id: str, ) -> Key: @@ -563,7 +563,7 @@ def get_key( raise AppwriteException('Missing required parameter: "key_id"') api_path = api_path.replace('{keyId}', str(self._normalize_value(key_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -575,7 +575,7 @@ def get_key( return self._parse_response(response, model=Key) - def update_key( + async def update_key( self, key_id: str, name: str, @@ -625,7 +625,7 @@ def update_key( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'put', api_path, { @@ -638,7 +638,7 @@ def update_key( return self._parse_response(response, model=Key) - def delete_key( + async def delete_key( self, key_id: str, ) -> Dict[str, Any]: @@ -666,7 +666,7 @@ def delete_key( raise AppwriteException('Missing required parameter: "key_id"') api_path = api_path.replace('{keyId}', str(self._normalize_value(key_id))) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -679,7 +679,7 @@ def delete_key( return response - def update_labels( + async def update_labels( self, labels: List[str], ) -> ProjectModel: @@ -707,7 +707,7 @@ def update_labels( raise AppwriteException('Missing required parameter: "labels"') api_params['labels'] = self._normalize_value(labels) - response = self.client.call( + response = await self.client.call( 'put', api_path, { @@ -720,7 +720,7 @@ def update_labels( return self._parse_response(response, model=ProjectModel) - def list_mock_phones( + async def list_mock_phones( self, queries: Optional[List[str]] = None, total: Optional[bool] = None, @@ -752,7 +752,7 @@ def list_mock_phones( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -764,7 +764,7 @@ def list_mock_phones( return self._parse_response(response, model=MockNumberList) - def create_mock_phone( + async def create_mock_phone( self, number: str, otp: str, @@ -798,7 +798,7 @@ def create_mock_phone( api_params['number'] = self._normalize_value(number) api_params['otp'] = self._normalize_value(otp) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -811,7 +811,7 @@ def create_mock_phone( return self._parse_response(response, model=MockNumber) - def get_mock_phone( + async def get_mock_phone( self, number: str, ) -> MockNumber: @@ -839,7 +839,7 @@ def get_mock_phone( raise AppwriteException('Missing required parameter: "number"') api_path = api_path.replace('{number}', str(self._normalize_value(number))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -851,7 +851,7 @@ def get_mock_phone( return self._parse_response(response, model=MockNumber) - def update_mock_phone( + async def update_mock_phone( self, number: str, otp: str, @@ -885,7 +885,7 @@ def update_mock_phone( api_path = api_path.replace('{number}', str(self._normalize_value(number))) api_params['otp'] = self._normalize_value(otp) - response = self.client.call( + response = await self.client.call( 'put', api_path, { @@ -898,7 +898,7 @@ def update_mock_phone( return self._parse_response(response, model=MockNumber) - def delete_mock_phone( + async def delete_mock_phone( self, number: str, ) -> Dict[str, Any]: @@ -926,7 +926,7 @@ def delete_mock_phone( raise AppwriteException('Missing required parameter: "number"') api_path = api_path.replace('{number}', str(self._normalize_value(number))) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -939,7 +939,7 @@ def delete_mock_phone( return response - def list_o_auth2_providers( + async def list_o_auth2_providers( self, queries: Optional[List[str]] = None, total: Optional[bool] = None, @@ -971,7 +971,7 @@ def list_o_auth2_providers( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -983,7 +983,7 @@ def list_o_auth2_providers( return self._parse_response(response, model=OAuth2ProviderList) - def update_o_auth2_server( + async def update_o_auth2_server( self, enabled: bool, authorization_url: str, @@ -1087,7 +1087,7 @@ def update_o_auth2_server( if installation_scopes is not None: api_params['installationScopes'] = self._normalize_value(installation_scopes) - response = self.client.call( + response = await self.client.call( 'put', api_path, { @@ -1100,7 +1100,7 @@ def update_o_auth2_server( return self._parse_response(response, model=ProjectModel) - def update_o_auth2_amazon( + async def update_o_auth2_amazon( self, client_id: Optional[str] = None, client_secret: Optional[str] = None, @@ -1137,7 +1137,7 @@ def update_o_auth2_amazon( if enabled is not None: api_params['enabled'] = self._normalize_value(enabled) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -1150,7 +1150,7 @@ def update_o_auth2_amazon( return self._parse_response(response, model=OAuth2Amazon) - def update_o_auth2_apple( + async def update_o_auth2_apple( self, service_id: Optional[str] = None, key_id: Optional[str] = None, @@ -1207,7 +1207,7 @@ def update_o_auth2_apple( if native_enabled is not None: api_params['nativeEnabled'] = self._normalize_value(native_enabled) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -1220,7 +1220,7 @@ def update_o_auth2_apple( return self._parse_response(response, model=OAuth2Apple) - def update_o_auth2_appwrite( + async def update_o_auth2_appwrite( self, client_id: Optional[str] = None, client_secret: Optional[str] = None, @@ -1257,7 +1257,7 @@ def update_o_auth2_appwrite( if enabled is not None: api_params['enabled'] = self._normalize_value(enabled) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -1270,7 +1270,7 @@ def update_o_auth2_appwrite( return self._parse_response(response, model=OAuth2Appwrite) - def update_o_auth2_auth0( + async def update_o_auth2_auth0( self, client_id: Optional[str] = None, client_secret: Optional[str] = None, @@ -1317,7 +1317,7 @@ def update_o_auth2_auth0( if prompt is not None: api_params['prompt'] = self._normalize_value(prompt) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -1330,7 +1330,7 @@ def update_o_auth2_auth0( return self._parse_response(response, model=OAuth2Auth0) - def update_o_auth2_authentik( + async def update_o_auth2_authentik( self, client_id: Optional[str] = None, client_secret: Optional[str] = None, @@ -1372,7 +1372,7 @@ def update_o_auth2_authentik( if enabled is not None: api_params['enabled'] = self._normalize_value(enabled) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -1385,7 +1385,7 @@ def update_o_auth2_authentik( return self._parse_response(response, model=OAuth2Authentik) - def update_o_auth2_autodesk( + async def update_o_auth2_autodesk( self, client_id: Optional[str] = None, client_secret: Optional[str] = None, @@ -1422,7 +1422,7 @@ def update_o_auth2_autodesk( if enabled is not None: api_params['enabled'] = self._normalize_value(enabled) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -1435,7 +1435,7 @@ def update_o_auth2_autodesk( return self._parse_response(response, model=OAuth2Autodesk) - def update_o_auth2_bitbucket( + async def update_o_auth2_bitbucket( self, key: Optional[str] = None, secret: Optional[str] = None, @@ -1472,7 +1472,7 @@ def update_o_auth2_bitbucket( if enabled is not None: api_params['enabled'] = self._normalize_value(enabled) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -1485,7 +1485,7 @@ def update_o_auth2_bitbucket( return self._parse_response(response, model=OAuth2Bitbucket) - def update_o_auth2_bitly( + async def update_o_auth2_bitly( self, client_id: Optional[str] = None, client_secret: Optional[str] = None, @@ -1522,7 +1522,7 @@ def update_o_auth2_bitly( if enabled is not None: api_params['enabled'] = self._normalize_value(enabled) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -1535,7 +1535,7 @@ def update_o_auth2_bitly( return self._parse_response(response, model=OAuth2Bitly) - def update_o_auth2_box( + async def update_o_auth2_box( self, client_id: Optional[str] = None, client_secret: Optional[str] = None, @@ -1572,7 +1572,7 @@ def update_o_auth2_box( if enabled is not None: api_params['enabled'] = self._normalize_value(enabled) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -1585,7 +1585,7 @@ def update_o_auth2_box( return self._parse_response(response, model=OAuth2Box) - def update_o_auth2_cloudflare( + async def update_o_auth2_cloudflare( self, client_id: Optional[str] = None, client_secret: Optional[str] = None, @@ -1622,7 +1622,7 @@ def update_o_auth2_cloudflare( if enabled is not None: api_params['enabled'] = self._normalize_value(enabled) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -1635,7 +1635,7 @@ def update_o_auth2_cloudflare( return self._parse_response(response, model=OAuth2Cloudflare) - def update_o_auth2_dailymotion( + async def update_o_auth2_dailymotion( self, api_key: Optional[str] = None, api_secret: Optional[str] = None, @@ -1672,7 +1672,7 @@ def update_o_auth2_dailymotion( if enabled is not None: api_params['enabled'] = self._normalize_value(enabled) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -1685,7 +1685,7 @@ def update_o_auth2_dailymotion( return self._parse_response(response, model=OAuth2Dailymotion) - def update_o_auth2_discord( + async def update_o_auth2_discord( self, client_id: Optional[str] = None, client_secret: Optional[str] = None, @@ -1727,7 +1727,7 @@ def update_o_auth2_discord( if prompt is not None: api_params['prompt'] = self._normalize_value(prompt) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -1740,7 +1740,7 @@ def update_o_auth2_discord( return self._parse_response(response, model=OAuth2Discord) - def update_o_auth2_disqus( + async def update_o_auth2_disqus( self, public_key: Optional[str] = None, secret_key: Optional[str] = None, @@ -1777,7 +1777,7 @@ def update_o_auth2_disqus( if enabled is not None: api_params['enabled'] = self._normalize_value(enabled) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -1790,7 +1790,7 @@ def update_o_auth2_disqus( return self._parse_response(response, model=OAuth2Disqus) - def update_o_auth2_dropbox( + async def update_o_auth2_dropbox( self, app_key: Optional[str] = None, app_secret: Optional[str] = None, @@ -1827,7 +1827,7 @@ def update_o_auth2_dropbox( if enabled is not None: api_params['enabled'] = self._normalize_value(enabled) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -1840,7 +1840,7 @@ def update_o_auth2_dropbox( return self._parse_response(response, model=OAuth2Dropbox) - def update_o_auth2_etsy( + async def update_o_auth2_etsy( self, key_string: Optional[str] = None, shared_secret: Optional[str] = None, @@ -1877,7 +1877,7 @@ def update_o_auth2_etsy( if enabled is not None: api_params['enabled'] = self._normalize_value(enabled) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -1890,7 +1890,7 @@ def update_o_auth2_etsy( return self._parse_response(response, model=OAuth2Etsy) - def update_o_auth2_facebook( + async def update_o_auth2_facebook( self, app_id: Optional[str] = None, app_secret: Optional[str] = None, @@ -1927,7 +1927,7 @@ def update_o_auth2_facebook( if enabled is not None: api_params['enabled'] = self._normalize_value(enabled) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -1940,7 +1940,7 @@ def update_o_auth2_facebook( return self._parse_response(response, model=OAuth2Facebook) - def update_o_auth2_figma( + async def update_o_auth2_figma( self, client_id: Optional[str] = None, client_secret: Optional[str] = None, @@ -1977,7 +1977,7 @@ def update_o_auth2_figma( if enabled is not None: api_params['enabled'] = self._normalize_value(enabled) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -1990,7 +1990,7 @@ def update_o_auth2_figma( return self._parse_response(response, model=OAuth2Figma) - def update_o_auth2_fusion_auth( + async def update_o_auth2_fusion_auth( self, client_id: Optional[str] = None, client_secret: Optional[str] = None, @@ -2032,7 +2032,7 @@ def update_o_auth2_fusion_auth( if enabled is not None: api_params['enabled'] = self._normalize_value(enabled) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -2045,7 +2045,7 @@ def update_o_auth2_fusion_auth( return self._parse_response(response, model=OAuth2FusionAuth) - def update_o_auth2_git_hub( + async def update_o_auth2_git_hub( self, client_id: Optional[str] = None, client_secret: Optional[str] = None, @@ -2087,7 +2087,7 @@ def update_o_auth2_git_hub( if prompt is not None: api_params['prompt'] = self._normalize_value(prompt) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -2100,7 +2100,7 @@ def update_o_auth2_git_hub( return self._parse_response(response, model=OAuth2Github) - def update_o_auth2_gitlab( + async def update_o_auth2_gitlab( self, application_id: Optional[str] = None, secret: Optional[str] = None, @@ -2142,7 +2142,7 @@ def update_o_auth2_gitlab( if enabled is not None: api_params['enabled'] = self._normalize_value(enabled) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -2155,7 +2155,7 @@ def update_o_auth2_gitlab( return self._parse_response(response, model=OAuth2Gitlab) - def update_o_auth2_google( + async def update_o_auth2_google( self, client_id: Optional[str] = None, client_secret: Optional[str] = None, @@ -2207,7 +2207,7 @@ def update_o_auth2_google( if native_enabled is not None: api_params['nativeEnabled'] = self._normalize_value(native_enabled) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -2220,7 +2220,7 @@ def update_o_auth2_google( return self._parse_response(response, model=OAuth2Google) - def update_o_auth2_hugging_face( + async def update_o_auth2_hugging_face( self, client_id: Optional[str] = None, client_secret: Optional[str] = None, @@ -2257,7 +2257,7 @@ def update_o_auth2_hugging_face( if enabled is not None: api_params['enabled'] = self._normalize_value(enabled) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -2270,7 +2270,7 @@ def update_o_auth2_hugging_face( return self._parse_response(response, model=OAuth2HuggingFace) - def update_o_auth2_kakao( + async def update_o_auth2_kakao( self, client_id: Optional[str] = None, client_secret: Optional[str] = None, @@ -2312,7 +2312,7 @@ def update_o_auth2_kakao( if prompt is not None: api_params['prompt'] = self._normalize_value(prompt) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -2325,7 +2325,7 @@ def update_o_auth2_kakao( return self._parse_response(response, model=OAuth2Kakao) - def update_o_auth2_keycloak( + async def update_o_auth2_keycloak( self, client_id: Optional[str] = None, client_secret: Optional[str] = None, @@ -2372,7 +2372,7 @@ def update_o_auth2_keycloak( if enabled is not None: api_params['enabled'] = self._normalize_value(enabled) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -2385,7 +2385,7 @@ def update_o_auth2_keycloak( return self._parse_response(response, model=OAuth2Keycloak) - def update_o_auth2_kick( + async def update_o_auth2_kick( self, client_id: Optional[str] = None, client_secret: Optional[str] = None, @@ -2422,7 +2422,7 @@ def update_o_auth2_kick( if enabled is not None: api_params['enabled'] = self._normalize_value(enabled) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -2435,7 +2435,7 @@ def update_o_auth2_kick( return self._parse_response(response, model=OAuth2Kick) - def update_o_auth2_linkedin( + async def update_o_auth2_linkedin( self, client_id: Optional[str] = None, primary_client_secret: Optional[str] = None, @@ -2472,7 +2472,7 @@ def update_o_auth2_linkedin( if enabled is not None: api_params['enabled'] = self._normalize_value(enabled) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -2485,7 +2485,7 @@ def update_o_auth2_linkedin( return self._parse_response(response, model=OAuth2Linkedin) - def update_o_auth2_microsoft( + async def update_o_auth2_microsoft( self, application_id: Optional[str] = None, application_secret: Optional[str] = None, @@ -2532,7 +2532,7 @@ def update_o_auth2_microsoft( if prompt is not None: api_params['prompt'] = self._normalize_value(prompt) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -2545,7 +2545,7 @@ def update_o_auth2_microsoft( return self._parse_response(response, model=OAuth2Microsoft) - def update_o_auth2_notion( + async def update_o_auth2_notion( self, oauth_client_id: Optional[str] = None, oauth_client_secret: Optional[str] = None, @@ -2582,7 +2582,7 @@ def update_o_auth2_notion( if enabled is not None: api_params['enabled'] = self._normalize_value(enabled) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -2595,7 +2595,7 @@ def update_o_auth2_notion( return self._parse_response(response, model=OAuth2Notion) - def update_o_auth2_oidc( + async def update_o_auth2_oidc( self, client_id: Optional[str] = None, client_secret: Optional[str] = None, @@ -2662,7 +2662,7 @@ def update_o_auth2_oidc( if enabled is not None: api_params['enabled'] = self._normalize_value(enabled) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -2675,7 +2675,7 @@ def update_o_auth2_oidc( return self._parse_response(response, model=OAuth2Oidc) - def update_o_auth2_okta( + async def update_o_auth2_okta( self, client_id: Optional[str] = None, client_secret: Optional[str] = None, @@ -2727,7 +2727,7 @@ def update_o_auth2_okta( if prompt is not None: api_params['prompt'] = self._normalize_value(prompt) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -2740,7 +2740,7 @@ def update_o_auth2_okta( return self._parse_response(response, model=OAuth2Okta) - def update_o_auth2_paypal( + async def update_o_auth2_paypal( self, client_id: Optional[str] = None, secret_key: Optional[str] = None, @@ -2777,7 +2777,7 @@ def update_o_auth2_paypal( if enabled is not None: api_params['enabled'] = self._normalize_value(enabled) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -2790,7 +2790,7 @@ def update_o_auth2_paypal( return self._parse_response(response, model=OAuth2Paypal) - def update_o_auth2_paypal_sandbox( + async def update_o_auth2_paypal_sandbox( self, client_id: Optional[str] = None, secret_key: Optional[str] = None, @@ -2827,7 +2827,7 @@ def update_o_auth2_paypal_sandbox( if enabled is not None: api_params['enabled'] = self._normalize_value(enabled) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -2840,7 +2840,7 @@ def update_o_auth2_paypal_sandbox( return self._parse_response(response, model=OAuth2Paypal) - def update_o_auth2_podio( + async def update_o_auth2_podio( self, client_id: Optional[str] = None, client_secret: Optional[str] = None, @@ -2877,7 +2877,7 @@ def update_o_auth2_podio( if enabled is not None: api_params['enabled'] = self._normalize_value(enabled) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -2890,7 +2890,7 @@ def update_o_auth2_podio( return self._parse_response(response, model=OAuth2Podio) - def update_o_auth2_resend( + async def update_o_auth2_resend( self, client_id: Optional[str] = None, client_secret: Optional[str] = None, @@ -2927,7 +2927,7 @@ def update_o_auth2_resend( if enabled is not None: api_params['enabled'] = self._normalize_value(enabled) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -2940,7 +2940,7 @@ def update_o_auth2_resend( return self._parse_response(response, model=OAuth2Resend) - def update_o_auth2_salesforce( + async def update_o_auth2_salesforce( self, customer_key: Optional[str] = None, customer_secret: Optional[str] = None, @@ -2982,7 +2982,7 @@ def update_o_auth2_salesforce( if prompt is not None: api_params['prompt'] = self._normalize_value(prompt) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -2995,7 +2995,7 @@ def update_o_auth2_salesforce( return self._parse_response(response, model=OAuth2Salesforce) - def update_o_auth2_slack( + async def update_o_auth2_slack( self, client_id: Optional[str] = None, client_secret: Optional[str] = None, @@ -3032,7 +3032,7 @@ def update_o_auth2_slack( if enabled is not None: api_params['enabled'] = self._normalize_value(enabled) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -3045,7 +3045,7 @@ def update_o_auth2_slack( return self._parse_response(response, model=OAuth2Slack) - def update_o_auth2_spotify( + async def update_o_auth2_spotify( self, client_id: Optional[str] = None, client_secret: Optional[str] = None, @@ -3082,7 +3082,7 @@ def update_o_auth2_spotify( if enabled is not None: api_params['enabled'] = self._normalize_value(enabled) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -3095,7 +3095,7 @@ def update_o_auth2_spotify( return self._parse_response(response, model=OAuth2Spotify) - def update_o_auth2_stripe( + async def update_o_auth2_stripe( self, client_id: Optional[str] = None, api_secret_key: Optional[str] = None, @@ -3132,7 +3132,7 @@ def update_o_auth2_stripe( if enabled is not None: api_params['enabled'] = self._normalize_value(enabled) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -3145,7 +3145,7 @@ def update_o_auth2_stripe( return self._parse_response(response, model=OAuth2Stripe) - def update_o_auth2_tik_tok( + async def update_o_auth2_tik_tok( self, client_id: Optional[str] = None, client_secret: Optional[str] = None, @@ -3182,7 +3182,7 @@ def update_o_auth2_tik_tok( if enabled is not None: api_params['enabled'] = self._normalize_value(enabled) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -3195,7 +3195,7 @@ def update_o_auth2_tik_tok( return self._parse_response(response, model=OAuth2TikTok) - def update_o_auth2_tradeshift( + async def update_o_auth2_tradeshift( self, oauth2_client_id: Optional[str] = None, oauth2_client_secret: Optional[str] = None, @@ -3232,7 +3232,7 @@ def update_o_auth2_tradeshift( if enabled is not None: api_params['enabled'] = self._normalize_value(enabled) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -3245,7 +3245,7 @@ def update_o_auth2_tradeshift( return self._parse_response(response, model=OAuth2Tradeshift) - def update_o_auth2_tradeshift_sandbox( + async def update_o_auth2_tradeshift_sandbox( self, oauth2_client_id: Optional[str] = None, oauth2_client_secret: Optional[str] = None, @@ -3282,7 +3282,7 @@ def update_o_auth2_tradeshift_sandbox( if enabled is not None: api_params['enabled'] = self._normalize_value(enabled) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -3295,7 +3295,7 @@ def update_o_auth2_tradeshift_sandbox( return self._parse_response(response, model=OAuth2Tradeshift) - def update_o_auth2_twitch( + async def update_o_auth2_twitch( self, client_id: Optional[str] = None, client_secret: Optional[str] = None, @@ -3332,7 +3332,7 @@ def update_o_auth2_twitch( if enabled is not None: api_params['enabled'] = self._normalize_value(enabled) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -3345,7 +3345,7 @@ def update_o_auth2_twitch( return self._parse_response(response, model=OAuth2Twitch) - def update_o_auth2_webflow( + async def update_o_auth2_webflow( self, client_id: Optional[str] = None, client_secret: Optional[str] = None, @@ -3382,7 +3382,7 @@ def update_o_auth2_webflow( if enabled is not None: api_params['enabled'] = self._normalize_value(enabled) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -3395,7 +3395,7 @@ def update_o_auth2_webflow( return self._parse_response(response, model=OAuth2Webflow) - def update_o_auth2_word_press( + async def update_o_auth2_word_press( self, client_id: Optional[str] = None, client_secret: Optional[str] = None, @@ -3432,7 +3432,7 @@ def update_o_auth2_word_press( if enabled is not None: api_params['enabled'] = self._normalize_value(enabled) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -3445,7 +3445,7 @@ def update_o_auth2_word_press( return self._parse_response(response, model=OAuth2WordPress) - def update_o_auth2_x( + async def update_o_auth2_x( self, customer_key: Optional[str] = None, secret_key: Optional[str] = None, @@ -3482,7 +3482,7 @@ def update_o_auth2_x( if enabled is not None: api_params['enabled'] = self._normalize_value(enabled) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -3495,7 +3495,7 @@ def update_o_auth2_x( return self._parse_response(response, model=OAuth2X) - def update_o_auth2_yahoo( + async def update_o_auth2_yahoo( self, client_id: Optional[str] = None, client_secret: Optional[str] = None, @@ -3532,7 +3532,7 @@ def update_o_auth2_yahoo( if enabled is not None: api_params['enabled'] = self._normalize_value(enabled) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -3545,7 +3545,7 @@ def update_o_auth2_yahoo( return self._parse_response(response, model=OAuth2Yahoo) - def update_o_auth2_yandex( + async def update_o_auth2_yandex( self, client_id: Optional[str] = None, client_secret: Optional[str] = None, @@ -3582,7 +3582,7 @@ def update_o_auth2_yandex( if enabled is not None: api_params['enabled'] = self._normalize_value(enabled) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -3595,7 +3595,7 @@ def update_o_auth2_yandex( return self._parse_response(response, model=OAuth2Yandex) - def update_o_auth2_zoho( + async def update_o_auth2_zoho( self, client_id: Optional[str] = None, client_secret: Optional[str] = None, @@ -3637,7 +3637,7 @@ def update_o_auth2_zoho( if prompt is not None: api_params['prompt'] = self._normalize_value(prompt) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -3650,7 +3650,7 @@ def update_o_auth2_zoho( return self._parse_response(response, model=OAuth2Zoho) - def update_o_auth2_zoom( + async def update_o_auth2_zoom( self, client_id: Optional[str] = None, client_secret: Optional[str] = None, @@ -3687,7 +3687,7 @@ def update_o_auth2_zoom( if enabled is not None: api_params['enabled'] = self._normalize_value(enabled) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -3700,7 +3700,7 @@ def update_o_auth2_zoom( return self._parse_response(response, model=OAuth2Zoom) - def get_o_auth2_provider( + async def get_o_auth2_provider( self, provider_id: ProjectOAuthProviderId, ) -> Union[ @@ -3775,7 +3775,7 @@ def get_o_auth2_provider( raise AppwriteException('Missing required parameter: "provider_id"') api_path = api_path.replace('{providerId}', str(self._normalize_value(provider_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -3927,7 +3927,7 @@ def get_o_auth2_provider( raise AppwriteException('Unable to match response to any known model') - def list_platforms( + async def list_platforms( self, queries: Optional[List[str]] = None, total: Optional[bool] = None, @@ -3959,7 +3959,7 @@ def list_platforms( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -3971,7 +3971,7 @@ def list_platforms( return self._parse_response(response, model=PlatformList) - def create_android_platform( + async def create_android_platform( self, platform_id: str, name: str, @@ -4016,7 +4016,7 @@ def create_android_platform( if fingerprints is not None: api_params['fingerprints'] = self._normalize_value(fingerprints) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -4029,7 +4029,7 @@ def create_android_platform( return self._parse_response(response, model=PlatformAndroid) - def update_android_platform( + async def update_android_platform( self, platform_id: str, name: str, @@ -4074,7 +4074,7 @@ def update_android_platform( if fingerprints is not None: api_params['fingerprints'] = self._normalize_value(fingerprints) - response = self.client.call( + response = await self.client.call( 'put', api_path, { @@ -4087,7 +4087,7 @@ def update_android_platform( return self._parse_response(response, model=PlatformAndroid) - def create_apple_platform( + async def create_apple_platform( self, platform_id: str, name: str, @@ -4127,7 +4127,7 @@ def create_apple_platform( api_params['name'] = self._normalize_value(name) api_params['bundleIdentifier'] = self._normalize_value(bundle_identifier) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -4140,7 +4140,7 @@ def create_apple_platform( return self._parse_response(response, model=PlatformApple) - def update_apple_platform( + async def update_apple_platform( self, platform_id: str, name: str, @@ -4180,7 +4180,7 @@ def update_apple_platform( api_params['name'] = self._normalize_value(name) api_params['bundleIdentifier'] = self._normalize_value(bundle_identifier) - response = self.client.call( + response = await self.client.call( 'put', api_path, { @@ -4193,7 +4193,7 @@ def update_apple_platform( return self._parse_response(response, model=PlatformApple) - def create_linux_platform( + async def create_linux_platform( self, platform_id: str, name: str, @@ -4233,7 +4233,7 @@ def create_linux_platform( api_params['name'] = self._normalize_value(name) api_params['packageName'] = self._normalize_value(package_name) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -4246,7 +4246,7 @@ def create_linux_platform( return self._parse_response(response, model=PlatformLinux) - def update_linux_platform( + async def update_linux_platform( self, platform_id: str, name: str, @@ -4286,7 +4286,7 @@ def update_linux_platform( api_params['name'] = self._normalize_value(name) api_params['packageName'] = self._normalize_value(package_name) - response = self.client.call( + response = await self.client.call( 'put', api_path, { @@ -4299,7 +4299,7 @@ def update_linux_platform( return self._parse_response(response, model=PlatformLinux) - def create_web_platform( + async def create_web_platform( self, platform_id: str, name: str, @@ -4339,7 +4339,7 @@ def create_web_platform( api_params['name'] = self._normalize_value(name) api_params['hostname'] = self._normalize_value(hostname) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -4352,7 +4352,7 @@ def create_web_platform( return self._parse_response(response, model=PlatformWeb) - def update_web_platform( + async def update_web_platform( self, platform_id: str, name: str, @@ -4392,7 +4392,7 @@ def update_web_platform( api_params['name'] = self._normalize_value(name) api_params['hostname'] = self._normalize_value(hostname) - response = self.client.call( + response = await self.client.call( 'put', api_path, { @@ -4405,7 +4405,7 @@ def update_web_platform( return self._parse_response(response, model=PlatformWeb) - def create_windows_platform( + async def create_windows_platform( self, platform_id: str, name: str, @@ -4445,7 +4445,7 @@ def create_windows_platform( api_params['name'] = self._normalize_value(name) api_params['packageIdentifierName'] = self._normalize_value(package_identifier_name) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -4458,7 +4458,7 @@ def create_windows_platform( return self._parse_response(response, model=PlatformWindows) - def update_windows_platform( + async def update_windows_platform( self, platform_id: str, name: str, @@ -4498,7 +4498,7 @@ def update_windows_platform( api_params['name'] = self._normalize_value(name) api_params['packageIdentifierName'] = self._normalize_value(package_identifier_name) - response = self.client.call( + response = await self.client.call( 'put', api_path, { @@ -4511,7 +4511,7 @@ def update_windows_platform( return self._parse_response(response, model=PlatformWindows) - def get_platform( + async def get_platform( self, platform_id: str, ) -> Union[ @@ -4545,7 +4545,7 @@ def get_platform( raise AppwriteException('Missing required parameter: "platform_id"') api_path = api_path.replace('{platformId}', str(self._normalize_value(platform_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -4574,7 +4574,7 @@ def get_platform( raise AppwriteException('Unable to match response to any known model') - def delete_platform( + async def delete_platform( self, platform_id: str, ) -> Dict[str, Any]: @@ -4602,7 +4602,7 @@ def delete_platform( raise AppwriteException('Missing required parameter: "platform_id"') api_path = api_path.replace('{platformId}', str(self._normalize_value(platform_id))) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -4615,7 +4615,7 @@ def delete_platform( return response - def list_policies( + async def list_policies( self, queries: Optional[List[str]] = None, total: Optional[bool] = None, @@ -4647,7 +4647,7 @@ def list_policies( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -4659,7 +4659,7 @@ def list_policies( return self._parse_response(response, model=PolicyList) - def update_deny_aliased_email_policy( + async def update_deny_aliased_email_policy( self, enabled: bool, ) -> ProjectModel: @@ -4687,7 +4687,7 @@ def update_deny_aliased_email_policy( raise AppwriteException('Missing required parameter: "enabled"') api_params['enabled'] = self._normalize_value(enabled) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -4700,7 +4700,7 @@ def update_deny_aliased_email_policy( return self._parse_response(response, model=ProjectModel) - def update_deny_corporate_email_policy( + async def update_deny_corporate_email_policy( self, enabled: bool, ) -> ProjectModel: @@ -4728,7 +4728,7 @@ def update_deny_corporate_email_policy( raise AppwriteException('Missing required parameter: "enabled"') api_params['enabled'] = self._normalize_value(enabled) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -4741,7 +4741,7 @@ def update_deny_corporate_email_policy( return self._parse_response(response, model=ProjectModel) - def update_deny_disposable_email_policy( + async def update_deny_disposable_email_policy( self, enabled: bool, ) -> ProjectModel: @@ -4769,7 +4769,7 @@ def update_deny_disposable_email_policy( raise AppwriteException('Missing required parameter: "enabled"') api_params['enabled'] = self._normalize_value(enabled) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -4782,7 +4782,7 @@ def update_deny_disposable_email_policy( return self._parse_response(response, model=ProjectModel) - def update_deny_free_email_policy( + async def update_deny_free_email_policy( self, enabled: bool, ) -> ProjectModel: @@ -4810,7 +4810,7 @@ def update_deny_free_email_policy( raise AppwriteException('Missing required parameter: "enabled"') api_params['enabled'] = self._normalize_value(enabled) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -4823,7 +4823,7 @@ def update_deny_free_email_policy( return self._parse_response(response, model=ProjectModel) - def update_membership_privacy_policy( + async def update_membership_privacy_policy( self, user_id: Optional[bool] = None, user_email: Optional[bool] = None, @@ -4875,7 +4875,7 @@ def update_membership_privacy_policy( if user_accessed_at is not None: api_params['userAccessedAt'] = self._normalize_value(user_accessed_at) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -4888,7 +4888,7 @@ def update_membership_privacy_policy( return self._parse_response(response, model=ProjectModel) - def update_mfa_factors_policy( + async def update_mfa_factors_policy( self, totp: Optional[bool] = None, email: Optional[bool] = None, @@ -4930,7 +4930,7 @@ def update_mfa_factors_policy( if custom is not None: api_params['custom'] = self._normalize_value(custom) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -4943,7 +4943,7 @@ def update_mfa_factors_policy( return self._parse_response(response, model=ProjectModel) - def update_passkey_policy( + async def update_passkey_policy( self, rp_id: str, ) -> ProjectModel: @@ -4971,7 +4971,7 @@ def update_passkey_policy( raise AppwriteException('Missing required parameter: "rp_id"') api_params['rpId'] = self._normalize_value(rp_id) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -4984,7 +4984,7 @@ def update_passkey_policy( return self._parse_response(response, model=ProjectModel) - def update_password_dictionary_policy( + async def update_password_dictionary_policy( self, enabled: bool, deny_list: Optional[List[str]] = None, @@ -5019,7 +5019,7 @@ def update_password_dictionary_policy( if deny_list is not None: api_params['denyList'] = self._normalize_value(deny_list) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -5032,7 +5032,7 @@ def update_password_dictionary_policy( return self._parse_response(response, model=ProjectModel) - def update_password_history_policy( + async def update_password_history_policy( self, total: Optional[float], ) -> ProjectModel: @@ -5060,7 +5060,7 @@ def update_password_history_policy( api_params = {} api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -5073,7 +5073,7 @@ def update_password_history_policy( return self._parse_response(response, model=ProjectModel) - def update_password_personal_data_policy( + async def update_password_personal_data_policy( self, enabled: bool, deny_list: Optional[List[str]] = None, @@ -5109,7 +5109,7 @@ def update_password_personal_data_policy( if deny_list is not None: api_params['denyList'] = self._normalize_value(deny_list) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -5122,7 +5122,7 @@ def update_password_personal_data_policy( return self._parse_response(response, model=ProjectModel) - def update_password_pwned_policy( + async def update_password_pwned_policy( self, enabled: Optional[bool] = None, sessions: Optional[bool] = None, @@ -5159,7 +5159,7 @@ def update_password_pwned_policy( if users is not None: api_params['users'] = self._normalize_value(users) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -5172,7 +5172,7 @@ def update_password_pwned_policy( return self._parse_response(response, model=ProjectModel) - def update_password_rotation_policy( + async def update_password_rotation_policy( self, enabled: Optional[bool] = None, max_age: Optional[float] = None, @@ -5204,7 +5204,7 @@ def update_password_rotation_policy( if max_age is not None: api_params['maxAge'] = self._normalize_value(max_age) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -5217,7 +5217,7 @@ def update_password_rotation_policy( return self._parse_response(response, model=ProjectModel) - def update_password_strength_policy( + async def update_password_strength_policy( self, min: Optional[float] = None, uppercase: Optional[bool] = None, @@ -5264,7 +5264,7 @@ def update_password_strength_policy( if symbols is not None: api_params['symbols'] = self._normalize_value(symbols) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -5277,7 +5277,7 @@ def update_password_strength_policy( return self._parse_response(response, model=PolicyPasswordStrength) - def update_session_alert_policy( + async def update_session_alert_policy( self, enabled: bool, ) -> ProjectModel: @@ -5305,7 +5305,7 @@ def update_session_alert_policy( raise AppwriteException('Missing required parameter: "enabled"') api_params['enabled'] = self._normalize_value(enabled) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -5318,7 +5318,7 @@ def update_session_alert_policy( return self._parse_response(response, model=ProjectModel) - def update_session_duration_policy( + async def update_session_duration_policy( self, duration: float, ) -> ProjectModel: @@ -5346,7 +5346,7 @@ def update_session_duration_policy( raise AppwriteException('Missing required parameter: "duration"') api_params['duration'] = self._normalize_value(duration) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -5359,7 +5359,7 @@ def update_session_duration_policy( return self._parse_response(response, model=ProjectModel) - def update_session_invalidation_policy( + async def update_session_invalidation_policy( self, enabled: bool, ) -> ProjectModel: @@ -5387,7 +5387,7 @@ def update_session_invalidation_policy( raise AppwriteException('Missing required parameter: "enabled"') api_params['enabled'] = self._normalize_value(enabled) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -5400,7 +5400,7 @@ def update_session_invalidation_policy( return self._parse_response(response, model=ProjectModel) - def update_session_limit_policy( + async def update_session_limit_policy( self, total: float, ) -> ProjectModel: @@ -5428,7 +5428,7 @@ def update_session_limit_policy( raise AppwriteException('Missing required parameter: "total"') api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -5441,7 +5441,7 @@ def update_session_limit_policy( return self._parse_response(response, model=ProjectModel) - def update_user_limit_policy( + async def update_user_limit_policy( self, total: Optional[float], ) -> ProjectModel: @@ -5467,7 +5467,7 @@ def update_user_limit_policy( api_params = {} api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -5480,7 +5480,7 @@ def update_user_limit_policy( return self._parse_response(response, model=ProjectModel) - def get_policy( + async def get_policy( self, policy_id: ProjectPolicyId, ) -> Union[ @@ -5527,7 +5527,7 @@ def get_policy( raise AppwriteException('Missing required parameter: "policy_id"') api_path = api_path.replace('{policyId}', str(self._normalize_value(policy_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -5595,7 +5595,7 @@ def get_policy( raise AppwriteException('Unable to match response to any known model') - def update_protocol( + async def update_protocol( self, protocol_id: ProjectProtocolId, enabled: bool, @@ -5629,7 +5629,7 @@ def update_protocol( api_path = api_path.replace('{protocolId}', str(self._normalize_value(protocol_id))) api_params['enabled'] = self._normalize_value(enabled) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -5642,7 +5642,7 @@ def update_protocol( return self._parse_response(response, model=ProjectModel) - def update_service( + async def update_service( self, service_id: ProjectServiceId, enabled: bool, @@ -5676,7 +5676,7 @@ def update_service( api_path = api_path.replace('{serviceId}', str(self._normalize_value(service_id))) api_params['enabled'] = self._normalize_value(enabled) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -5689,7 +5689,7 @@ def update_service( return self._parse_response(response, model=ProjectModel) - def update_smtp( + async def update_smtp( self, host: Optional[str] = None, port: Optional[float] = None, @@ -5761,7 +5761,7 @@ def update_smtp( if enabled is not None: api_params['enabled'] = self._normalize_value(enabled) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -5774,7 +5774,7 @@ def update_smtp( return self._parse_response(response, model=ProjectModel) - def create_smtp_test( + async def create_smtp_test( self, emails: List[str], ) -> Dict[str, Any]: @@ -5802,7 +5802,7 @@ def create_smtp_test( raise AppwriteException('Missing required parameter: "emails"') api_params['emails'] = self._normalize_value(emails) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -5815,7 +5815,7 @@ def create_smtp_test( return response - def list_email_templates( + async def list_email_templates( self, queries: Optional[List[str]] = None, total: Optional[bool] = None, @@ -5847,7 +5847,7 @@ def list_email_templates( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -5859,7 +5859,7 @@ def list_email_templates( return self._parse_response(response, model=EmailTemplateList) - def update_email_template( + async def update_email_template( self, template_id: ProjectEmailTemplateId, locale: Optional[ProjectEmailTemplateLocale] = None, @@ -5922,7 +5922,7 @@ def update_email_template( if reply_to_name is not None: api_params['replyToName'] = self._normalize_value(reply_to_name) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -5935,7 +5935,7 @@ def update_email_template( return self._parse_response(response, model=EmailTemplate) - def get_email_template( + async def get_email_template( self, template_id: ProjectEmailTemplateId, locale: Optional[ProjectEmailTemplateLocale] = None, @@ -5968,7 +5968,7 @@ def get_email_template( if locale is not None: api_params['locale'] = self._normalize_value(locale) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -5980,7 +5980,7 @@ def get_email_template( return self._parse_response(response, model=EmailTemplate) - def list_variables( + async def list_variables( self, queries: Optional[List[str]] = None, total: Optional[bool] = None, @@ -6012,7 +6012,7 @@ def list_variables( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -6024,7 +6024,7 @@ def list_variables( return self._parse_response(response, model=VariableList) - def create_variable( + async def create_variable( self, variable_id: str, key: str, @@ -6074,7 +6074,7 @@ def create_variable( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -6087,7 +6087,7 @@ def create_variable( return self._parse_response(response, model=Variable) - def get_variable( + async def get_variable( self, variable_id: str, ) -> Variable: @@ -6115,7 +6115,7 @@ def get_variable( raise AppwriteException('Missing required parameter: "variable_id"') api_path = api_path.replace('{variableId}', str(self._normalize_value(variable_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -6127,7 +6127,7 @@ def get_variable( return self._parse_response(response, model=Variable) - def update_variable( + async def update_variable( self, variable_id: str, key: Optional[str] = None, @@ -6175,7 +6175,7 @@ def update_variable( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'put', api_path, { @@ -6188,7 +6188,7 @@ def update_variable( return self._parse_response(response, model=Variable) - def delete_variable( + async def delete_variable( self, variable_id: str, ) -> Dict[str, Any]: @@ -6216,7 +6216,7 @@ def delete_variable( raise AppwriteException('Missing required parameter: "variable_id"') api_path = api_path.replace('{variableId}', str(self._normalize_value(variable_id))) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { diff --git a/appwrite/services/proxy.py b/appwrite/services/proxy.py index 5f4e5c68..3f50e593 100644 --- a/appwrite/services/proxy.py +++ b/appwrite/services/proxy.py @@ -16,7 +16,7 @@ class Proxy(Service): def __init__(self, client) -> None: super(Proxy, self).__init__(client) - def create_invalidation( + async def create_invalidation( self, domain: str, type: InvalidationType, @@ -59,7 +59,7 @@ def create_invalidation( if reference is not None: api_params['reference'] = self._normalize_value(reference) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -72,7 +72,7 @@ def create_invalidation( return self._parse_response(response, model=ProxyInvalidation) - def list_rules( + async def list_rules( self, queries: Optional[List[str]] = None, total: Optional[bool] = None, @@ -104,7 +104,7 @@ def list_rules( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -116,7 +116,7 @@ def list_rules( return self._parse_response(response, model=ProxyRuleList) - def create_api_rule( + async def create_api_rule( self, domain: str, ) -> ProxyRule: @@ -146,7 +146,7 @@ def create_api_rule( raise AppwriteException('Missing required parameter: "domain"') api_params['domain'] = self._normalize_value(domain) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -159,7 +159,7 @@ def create_api_rule( return self._parse_response(response, model=ProxyRule) - def create_function_rule( + async def create_function_rule( self, domain: str, function_id: str, @@ -200,7 +200,7 @@ def create_function_rule( if branch is not None: api_params['branch'] = self._normalize_value(branch) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -213,7 +213,7 @@ def create_function_rule( return self._parse_response(response, model=ProxyRule) - def create_redirect_rule( + async def create_redirect_rule( self, domain: str, url: str, @@ -267,7 +267,7 @@ def create_redirect_rule( api_params['resourceId'] = self._normalize_value(resource_id) api_params['resourceType'] = self._normalize_value(resource_type) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -280,7 +280,7 @@ def create_redirect_rule( return self._parse_response(response, model=ProxyRule) - def create_site_rule( + async def create_site_rule( self, domain: str, site_id: str, @@ -321,7 +321,7 @@ def create_site_rule( if branch is not None: api_params['branch'] = self._normalize_value(branch) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -334,7 +334,7 @@ def create_site_rule( return self._parse_response(response, model=ProxyRule) - def create_smtp_rule( + async def create_smtp_rule( self, domain: str, function_id: str, @@ -373,7 +373,7 @@ def create_smtp_rule( if branch is not None: api_params['branch'] = self._normalize_value(branch) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -386,7 +386,7 @@ def create_smtp_rule( return self._parse_response(response, model=ProxyRule) - def get_rule( + async def get_rule( self, rule_id: str, ) -> ProxyRule: @@ -414,7 +414,7 @@ def get_rule( raise AppwriteException('Missing required parameter: "rule_id"') api_path = api_path.replace('{ruleId}', str(self._normalize_value(rule_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -426,7 +426,7 @@ def get_rule( return self._parse_response(response, model=ProxyRule) - def delete_rule( + async def delete_rule( self, rule_id: str, ) -> Dict[str, Any]: @@ -454,7 +454,7 @@ def delete_rule( raise AppwriteException('Missing required parameter: "rule_id"') api_path = api_path.replace('{ruleId}', str(self._normalize_value(rule_id))) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -467,7 +467,7 @@ def delete_rule( return response - def update_rule_status( + async def update_rule_status( self, rule_id: str, ) -> ProxyRule: @@ -495,7 +495,7 @@ def update_rule_status( raise AppwriteException('Missing required parameter: "rule_id"') api_path = api_path.replace('{ruleId}', str(self._normalize_value(rule_id))) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { diff --git a/appwrite/services/sites.py b/appwrite/services/sites.py index f3320934..2c8fed21 100644 --- a/appwrite/services/sites.py +++ b/appwrite/services/sites.py @@ -28,7 +28,7 @@ class Sites(Service): def __init__(self, client) -> None: super(Sites, self).__init__(client) - def list( + async def list( self, queries: Optional[List[str]] = None, search: Optional[str] = None, @@ -65,7 +65,7 @@ def list( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -77,7 +77,7 @@ def list( return self._parse_response(response, model=SiteList) - def create( + async def create( self, site_id: str, name: str, @@ -228,7 +228,7 @@ def create( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -241,7 +241,7 @@ def create( return self._parse_response(response, model=Site) - def list_frameworks( + async def list_frameworks( self, total: Optional[bool] = None, ) -> FrameworkList: @@ -268,7 +268,7 @@ def list_frameworks( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -280,7 +280,7 @@ def list_frameworks( return self._parse_response(response, model=FrameworkList) - def list_specifications( + async def list_specifications( self, type: Optional[str] = None, total: Optional[bool] = None, @@ -312,7 +312,7 @@ def list_specifications( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -324,7 +324,7 @@ def list_specifications( return self._parse_response(response, model=SpecificationList) - def get( + async def get( self, site_id: str, ) -> Site: @@ -352,7 +352,7 @@ def get( raise AppwriteException('Missing required parameter: "site_id"') api_path = api_path.replace('{siteId}', str(self._normalize_value(site_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -364,7 +364,7 @@ def get( return self._parse_response(response, model=Site) - def update( + async def update( self, site_id: str, name: str, @@ -514,7 +514,7 @@ def update( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'put', api_path, { @@ -527,7 +527,7 @@ def update( return self._parse_response(response, model=Site) - def delete( + async def delete( self, site_id: str, ) -> Dict[str, Any]: @@ -555,7 +555,7 @@ def delete( raise AppwriteException('Missing required parameter: "site_id"') api_path = api_path.replace('{siteId}', str(self._normalize_value(site_id))) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -568,7 +568,7 @@ def delete( return response - def update_site_deployment( + async def update_site_deployment( self, site_id: str, deployment_id: str, @@ -602,7 +602,7 @@ def update_site_deployment( api_path = api_path.replace('{siteId}', str(self._normalize_value(site_id))) api_params['deploymentId'] = self._normalize_value(deployment_id) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -615,7 +615,7 @@ def update_site_deployment( return self._parse_response(response, model=Site) - def list_deployments( + async def list_deployments( self, site_id: str, queries: Optional[List[str]] = None, @@ -658,7 +658,7 @@ def list_deployments( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -670,7 +670,7 @@ def list_deployments( return self._parse_response(response, model=DeploymentList) - def create_deployment( + async def create_deployment( self, site_id: str, code: InputFile, @@ -734,7 +734,7 @@ def create_deployment( upload_id = '' - response = self.client.chunked_upload( + response = await self.client.chunked_upload( api_path, { 'X-Appwrite-Project': self.client.get_config('project'), @@ -750,7 +750,7 @@ def create_deployment( return self._parse_response(response, model=Deployment) - def create_duplicate_deployment( + async def create_duplicate_deployment( self, site_id: str, deployment_id: str, @@ -784,7 +784,7 @@ def create_duplicate_deployment( api_path = api_path.replace('{siteId}', str(self._normalize_value(site_id))) api_params['deploymentId'] = self._normalize_value(deployment_id) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -797,7 +797,7 @@ def create_duplicate_deployment( return self._parse_response(response, model=Deployment) - def create_template_deployment( + async def create_template_deployment( self, site_id: str, repository: str, @@ -862,7 +862,7 @@ def create_template_deployment( if activate is not None: api_params['activate'] = self._normalize_value(activate) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -875,7 +875,7 @@ def create_template_deployment( return self._parse_response(response, model=Deployment) - def create_vcs_deployment( + async def create_vcs_deployment( self, site_id: str, type: VCSReferenceType, @@ -922,7 +922,7 @@ def create_vcs_deployment( if activate is not None: api_params['activate'] = self._normalize_value(activate) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -935,7 +935,7 @@ def create_vcs_deployment( return self._parse_response(response, model=Deployment) - def get_deployment( + async def get_deployment( self, site_id: str, deployment_id: str, @@ -969,7 +969,7 @@ def get_deployment( api_path = api_path.replace('{siteId}', str(self._normalize_value(site_id))) api_path = api_path.replace('{deploymentId}', str(self._normalize_value(deployment_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -981,7 +981,7 @@ def get_deployment( return self._parse_response(response, model=Deployment) - def delete_deployment( + async def delete_deployment( self, site_id: str, deployment_id: str, @@ -1015,7 +1015,7 @@ def delete_deployment( api_path = api_path.replace('{siteId}', str(self._normalize_value(site_id))) api_path = api_path.replace('{deploymentId}', str(self._normalize_value(deployment_id))) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -1028,7 +1028,7 @@ def delete_deployment( return response - def get_deployment_download( + async def get_deployment_download( self, site_id: str, deployment_id: str, @@ -1072,7 +1072,7 @@ def get_deployment_download( if token is not None: api_params['token'] = self._normalize_value(token) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -1084,7 +1084,7 @@ def get_deployment_download( return response - def update_deployment_status( + async def update_deployment_status( self, site_id: str, deployment_id: str, @@ -1118,7 +1118,7 @@ def update_deployment_status( api_path = api_path.replace('{siteId}', str(self._normalize_value(site_id))) api_path = api_path.replace('{deploymentId}', str(self._normalize_value(deployment_id))) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -1131,7 +1131,7 @@ def update_deployment_status( return self._parse_response(response, model=Deployment) - def list_logs( + async def list_logs( self, site_id: str, queries: Optional[List[str]] = None, @@ -1169,7 +1169,7 @@ def list_logs( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -1181,7 +1181,7 @@ def list_logs( return self._parse_response(response, model=ExecutionList) - def get_log( + async def get_log( self, site_id: str, log_id: str, @@ -1215,7 +1215,7 @@ def get_log( api_path = api_path.replace('{siteId}', str(self._normalize_value(site_id))) api_path = api_path.replace('{logId}', str(self._normalize_value(log_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -1227,7 +1227,7 @@ def get_log( return self._parse_response(response, model=Execution) - def delete_log( + async def delete_log( self, site_id: str, log_id: str, @@ -1261,7 +1261,7 @@ def delete_log( api_path = api_path.replace('{siteId}', str(self._normalize_value(site_id))) api_path = api_path.replace('{logId}', str(self._normalize_value(log_id))) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -1274,7 +1274,7 @@ def delete_log( return response - def list_variables( + async def list_variables( self, site_id: str, queries: Optional[List[str]] = None, @@ -1312,7 +1312,7 @@ def list_variables( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -1324,7 +1324,7 @@ def list_variables( return self._parse_response(response, model=VariableList) - def create_variable( + async def create_variable( self, site_id: str, variable_id: str, @@ -1380,7 +1380,7 @@ def create_variable( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -1393,7 +1393,7 @@ def create_variable( return self._parse_response(response, model=Variable) - def get_variable( + async def get_variable( self, site_id: str, variable_id: str, @@ -1427,7 +1427,7 @@ def get_variable( api_path = api_path.replace('{siteId}', str(self._normalize_value(site_id))) api_path = api_path.replace('{variableId}', str(self._normalize_value(variable_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -1439,7 +1439,7 @@ def get_variable( return self._parse_response(response, model=Variable) - def update_variable( + async def update_variable( self, site_id: str, variable_id: str, @@ -1493,7 +1493,7 @@ def update_variable( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'put', api_path, { @@ -1506,7 +1506,7 @@ def update_variable( return self._parse_response(response, model=Variable) - def delete_variable( + async def delete_variable( self, site_id: str, variable_id: str, @@ -1540,7 +1540,7 @@ def delete_variable( api_path = api_path.replace('{siteId}', str(self._normalize_value(site_id))) api_path = api_path.replace('{variableId}', str(self._normalize_value(variable_id))) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { diff --git a/appwrite/services/storage.py b/appwrite/services/storage.py index 2981f526..0245fe07 100644 --- a/appwrite/services/storage.py +++ b/appwrite/services/storage.py @@ -18,7 +18,7 @@ class Storage(Service): def __init__(self, client) -> None: super(Storage, self).__init__(client) - def list_buckets( + async def list_buckets( self, queries: Optional[List[str]] = None, search: Optional[str] = None, @@ -55,7 +55,7 @@ def list_buckets( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -67,7 +67,7 @@ def list_buckets( return self._parse_response(response, model=BucketList) - def create_bucket( + async def create_bucket( self, bucket_id: str, name: str, @@ -156,7 +156,7 @@ def create_bucket( if strip_metadata is not None: api_params['stripMetadata'] = self._normalize_value(strip_metadata) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -169,7 +169,7 @@ def create_bucket( return self._parse_response(response, model=Bucket) - def get_bucket( + async def get_bucket( self, bucket_id: str, ) -> Bucket: @@ -197,7 +197,7 @@ def get_bucket( raise AppwriteException('Missing required parameter: "bucket_id"') api_path = api_path.replace('{bucketId}', str(self._normalize_value(bucket_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -209,7 +209,7 @@ def get_bucket( return self._parse_response(response, model=Bucket) - def update_bucket( + async def update_bucket( self, bucket_id: str, name: str, @@ -298,7 +298,7 @@ def update_bucket( if strip_metadata is not None: api_params['stripMetadata'] = self._normalize_value(strip_metadata) - response = self.client.call( + response = await self.client.call( 'put', api_path, { @@ -311,7 +311,7 @@ def update_bucket( return self._parse_response(response, model=Bucket) - def delete_bucket( + async def delete_bucket( self, bucket_id: str, ) -> Dict[str, Any]: @@ -339,7 +339,7 @@ def delete_bucket( raise AppwriteException('Missing required parameter: "bucket_id"') api_path = api_path.replace('{bucketId}', str(self._normalize_value(bucket_id))) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -352,7 +352,7 @@ def delete_bucket( return response - def list_files( + async def list_files( self, bucket_id: str, queries: Optional[List[str]] = None, @@ -395,7 +395,7 @@ def list_files( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -407,7 +407,7 @@ def list_files( return self._parse_response(response, model=FileList) - def create_file( + async def create_file( self, bucket_id: str, file_id: str, @@ -472,7 +472,7 @@ def create_file( upload_id = '' upload_id = file_id - response = self.client.chunked_upload( + response = await self.client.chunked_upload( api_path, { 'X-Appwrite-Project': self.client.get_config('project'), @@ -488,7 +488,7 @@ def create_file( return self._parse_response(response, model=File) - def get_file( + async def get_file( self, bucket_id: str, file_id: str, @@ -522,7 +522,7 @@ def get_file( api_path = api_path.replace('{bucketId}', str(self._normalize_value(bucket_id))) api_path = api_path.replace('{fileId}', str(self._normalize_value(file_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -534,7 +534,7 @@ def get_file( return self._parse_response(response, model=File) - def update_file( + async def update_file( self, bucket_id: str, file_id: str, @@ -578,7 +578,7 @@ def update_file( if permissions is not None: api_params['permissions'] = self._normalize_value(permissions) - response = self.client.call( + response = await self.client.call( 'put', api_path, { @@ -591,7 +591,7 @@ def update_file( return self._parse_response(response, model=File) - def delete_file( + async def delete_file( self, bucket_id: str, file_id: str, @@ -625,7 +625,7 @@ def delete_file( api_path = api_path.replace('{bucketId}', str(self._normalize_value(bucket_id))) api_path = api_path.replace('{fileId}', str(self._normalize_value(file_id))) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -638,7 +638,7 @@ def delete_file( return response - def get_file_download( + async def get_file_download( self, bucket_id: str, file_id: str, @@ -677,7 +677,7 @@ def get_file_download( if token is not None: api_params['token'] = self._normalize_value(token) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -689,7 +689,7 @@ def get_file_download( return response - def get_file_preview( + async def get_file_preview( self, bucket_id: str, file_id: str, @@ -783,7 +783,7 @@ def get_file_preview( if token is not None: api_params['token'] = self._normalize_value(token) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -795,7 +795,7 @@ def get_file_preview( return response - def get_file_view( + async def get_file_view( self, bucket_id: str, file_id: str, @@ -834,7 +834,7 @@ def get_file_view( if token is not None: api_params['token'] = self._normalize_value(token) - response = self.client.call( + response = await self.client.call( 'get', api_path, { diff --git a/appwrite/services/tables_db.py b/appwrite/services/tables_db.py index 19f181a5..da8fa180 100644 --- a/appwrite/services/tables_db.py +++ b/appwrite/services/tables_db.py @@ -52,7 +52,7 @@ class TablesDB(Service): def __init__(self, client) -> None: super(TablesDB, self).__init__(client) - def list( + async def list( self, queries: Optional[List[str]] = None, search: Optional[str] = None, @@ -89,7 +89,7 @@ def list( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -101,7 +101,7 @@ def list( return self._parse_response(response, model=DatabaseList) - def create( + async def create( self, database_id: str, name: str, @@ -160,7 +160,7 @@ def create( if sync_mode is not None: api_params['syncMode'] = self._normalize_value(sync_mode) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -173,7 +173,7 @@ def create( return self._parse_response(response, model=Database) - def list_specifications( + async def list_specifications( self, ) -> DedicatedDatabaseSpecificationList: """ @@ -192,7 +192,7 @@ def list_specifications( api_path = '/tablesdb/specifications' api_params = {} - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -204,7 +204,7 @@ def list_specifications( return self._parse_response(response, model=DedicatedDatabaseSpecificationList) - def list_transactions( + async def list_transactions( self, queries: Optional[List[str]] = None, total: Optional[bool] = None, @@ -236,7 +236,7 @@ def list_transactions( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -248,7 +248,7 @@ def list_transactions( return self._parse_response(response, model=TransactionList) - def create_transaction( + async def create_transaction( self, ttl: Optional[float] = None, ) -> Transaction: @@ -275,7 +275,7 @@ def create_transaction( if ttl is not None: api_params['ttl'] = self._normalize_value(ttl) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -288,7 +288,7 @@ def create_transaction( return self._parse_response(response, model=Transaction) - def get_transaction( + async def get_transaction( self, transaction_id: str, ) -> Transaction: @@ -316,7 +316,7 @@ def get_transaction( raise AppwriteException('Missing required parameter: "transaction_id"') api_path = api_path.replace('{transactionId}', str(self._normalize_value(transaction_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -328,7 +328,7 @@ def get_transaction( return self._parse_response(response, model=Transaction) - def update_transaction( + async def update_transaction( self, transaction_id: str, commit: Optional[bool] = None, @@ -366,7 +366,7 @@ def update_transaction( if rollback is not None: api_params['rollback'] = self._normalize_value(rollback) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -379,7 +379,7 @@ def update_transaction( return self._parse_response(response, model=Transaction) - def delete_transaction( + async def delete_transaction( self, transaction_id: str, ) -> Dict[str, Any]: @@ -407,7 +407,7 @@ def delete_transaction( raise AppwriteException('Missing required parameter: "transaction_id"') api_path = api_path.replace('{transactionId}', str(self._normalize_value(transaction_id))) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -420,7 +420,7 @@ def delete_transaction( return response - def create_operations( + async def create_operations( self, transaction_id: str, operations: Optional[List[Dict[str, Any]]] = None, @@ -453,7 +453,7 @@ def create_operations( if operations is not None: api_params['operations'] = self._normalize_value(operations) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -466,7 +466,7 @@ def create_operations( return self._parse_response(response, model=Transaction) - def get( + async def get( self, database_id: str, ) -> Database: @@ -494,7 +494,7 @@ def get( raise AppwriteException('Missing required parameter: "database_id"') api_path = api_path.replace('{databaseId}', str(self._normalize_value(database_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -506,7 +506,7 @@ def get( return self._parse_response(response, model=Database) - def update( + async def update( self, database_id: str, name: Optional[str] = None, @@ -564,7 +564,7 @@ def update( if sync_mode is not None: api_params['syncMode'] = self._normalize_value(sync_mode) - response = self.client.call( + response = await self.client.call( 'put', api_path, { @@ -577,7 +577,7 @@ def update( return self._parse_response(response, model=Database) - def delete( + async def delete( self, database_id: str, ) -> Dict[str, Any]: @@ -605,7 +605,7 @@ def delete( raise AppwriteException('Missing required parameter: "database_id"') api_path = api_path.replace('{databaseId}', str(self._normalize_value(database_id))) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -618,7 +618,7 @@ def delete( return response - def create_failover( + async def create_failover( self, database_id: str, target_replica_id: Optional[str] = None, @@ -651,7 +651,7 @@ def create_failover( if target_replica_id is not None: api_params['targetReplicaId'] = self._normalize_value(target_replica_id) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -664,7 +664,7 @@ def create_failover( return self._parse_response(response, model=DedicatedDatabase) - def list_migrations( + async def list_migrations( self, database_id: str, ) -> DatabaseMigrationList: @@ -692,7 +692,7 @@ def list_migrations( raise AppwriteException('Missing required parameter: "database_id"') api_path = api_path.replace('{databaseId}', str(self._normalize_value(database_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -704,7 +704,7 @@ def list_migrations( return self._parse_response(response, model=DatabaseMigrationList) - def create_migration( + async def create_migration( self, database_id: str, specification: str, @@ -743,7 +743,7 @@ def create_migration( if auto_cutover is not None: api_params['autoCutover'] = self._normalize_value(auto_cutover) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -756,7 +756,7 @@ def create_migration( return self._parse_response(response, model=DatabaseMigration) - def get_migration( + async def get_migration( self, database_id: str, migration_id: str, @@ -790,7 +790,7 @@ def get_migration( api_path = api_path.replace('{databaseId}', str(self._normalize_value(database_id))) api_path = api_path.replace('{migrationId}', str(self._normalize_value(migration_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -802,7 +802,7 @@ def get_migration( return self._parse_response(response, model=DatabaseMigration) - def delete_migration( + async def delete_migration( self, database_id: str, migration_id: str, @@ -836,7 +836,7 @@ def delete_migration( api_path = api_path.replace('{databaseId}', str(self._normalize_value(database_id))) api_path = api_path.replace('{migrationId}', str(self._normalize_value(migration_id))) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -849,7 +849,7 @@ def delete_migration( return response - def create_cutover( + async def create_cutover( self, database_id: str, migration_id: str, @@ -883,7 +883,7 @@ def create_cutover( api_path = api_path.replace('{databaseId}', str(self._normalize_value(database_id))) api_path = api_path.replace('{migrationId}', str(self._normalize_value(migration_id))) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -896,7 +896,7 @@ def create_cutover( return self._parse_response(response, model=DatabaseMigration) - def list_operations( + async def list_operations( self, database_id: str, status: Optional[str] = None, @@ -939,7 +939,7 @@ def list_operations( if offset is not None: api_params['offset'] = self._normalize_value(offset) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -951,7 +951,7 @@ def list_operations( return self._parse_response(response, model=DedicatedDatabaseOperationList) - def get_replicas( + async def get_replicas( self, database_id: str, ) -> DedicatedDatabaseReplicas: @@ -979,7 +979,7 @@ def get_replicas( raise AppwriteException('Missing required parameter: "database_id"') api_path = api_path.replace('{databaseId}', str(self._normalize_value(database_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -991,7 +991,7 @@ def get_replicas( return self._parse_response(response, model=DedicatedDatabaseReplicas) - def get_status( + async def get_status( self, database_id: str, ) -> DatabaseStatus: @@ -1019,7 +1019,7 @@ def get_status( raise AppwriteException('Missing required parameter: "database_id"') api_path = api_path.replace('{databaseId}', str(self._normalize_value(database_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -1031,7 +1031,7 @@ def get_status( return self._parse_response(response, model=DatabaseStatus) - def list_tables( + async def list_tables( self, database_id: str, queries: Optional[List[str]] = None, @@ -1074,7 +1074,7 @@ def list_tables( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -1086,7 +1086,7 @@ def list_tables( return self._parse_response(response, model=TableList) - def create_table( + async def create_table( self, database_id: str, table_id: str, @@ -1156,7 +1156,7 @@ def create_table( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -1169,7 +1169,7 @@ def create_table( return self._parse_response(response, model=Table) - def get_table( + async def get_table( self, database_id: str, table_id: str, @@ -1203,7 +1203,7 @@ def get_table( api_path = api_path.replace('{databaseId}', str(self._normalize_value(database_id))) api_path = api_path.replace('{tableId}', str(self._normalize_value(table_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -1215,7 +1215,7 @@ def get_table( return self._parse_response(response, model=Table) - def update_table( + async def update_table( self, database_id: str, table_id: str, @@ -1279,7 +1279,7 @@ def update_table( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'put', api_path, { @@ -1292,7 +1292,7 @@ def update_table( return self._parse_response(response, model=Table) - def delete_table( + async def delete_table( self, database_id: str, table_id: str, @@ -1326,7 +1326,7 @@ def delete_table( api_path = api_path.replace('{databaseId}', str(self._normalize_value(database_id))) api_path = api_path.replace('{tableId}', str(self._normalize_value(table_id))) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -1339,7 +1339,7 @@ def delete_table( return response - def list_columns( + async def list_columns( self, database_id: str, table_id: str, @@ -1383,7 +1383,7 @@ def list_columns( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -1395,7 +1395,7 @@ def list_columns( return self._parse_response(response, model=ColumnList) - def create_big_int_column( + async def create_big_int_column( self, database_id: str, table_id: str, @@ -1466,7 +1466,7 @@ def create_big_int_column( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -1479,7 +1479,7 @@ def create_big_int_column( return self._parse_response(response, model=ColumnBigint) - def update_big_int_column( + async def update_big_int_column( self, database_id: str, table_id: str, @@ -1549,7 +1549,7 @@ def update_big_int_column( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -1562,7 +1562,7 @@ def update_big_int_column( return self._parse_response(response, model=ColumnBigint) - def create_boolean_column( + async def create_boolean_column( self, database_id: str, table_id: str, @@ -1623,7 +1623,7 @@ def create_boolean_column( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -1636,7 +1636,7 @@ def create_boolean_column( return self._parse_response(response, model=ColumnBoolean) - def update_boolean_column( + async def update_boolean_column( self, database_id: str, table_id: str, @@ -1696,7 +1696,7 @@ def update_boolean_column( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -1709,7 +1709,7 @@ def update_boolean_column( return self._parse_response(response, model=ColumnBoolean) - def create_datetime_column( + async def create_datetime_column( self, database_id: str, table_id: str, @@ -1770,7 +1770,7 @@ def create_datetime_column( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -1783,7 +1783,7 @@ def create_datetime_column( return self._parse_response(response, model=ColumnDatetime) - def update_datetime_column( + async def update_datetime_column( self, database_id: str, table_id: str, @@ -1843,7 +1843,7 @@ def update_datetime_column( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -1856,7 +1856,7 @@ def update_datetime_column( return self._parse_response(response, model=ColumnDatetime) - def create_email_column( + async def create_email_column( self, database_id: str, table_id: str, @@ -1917,7 +1917,7 @@ def create_email_column( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -1930,7 +1930,7 @@ def create_email_column( return self._parse_response(response, model=ColumnEmail) - def update_email_column( + async def update_email_column( self, database_id: str, table_id: str, @@ -1990,7 +1990,7 @@ def update_email_column( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -2003,7 +2003,7 @@ def update_email_column( return self._parse_response(response, model=ColumnEmail) - def create_enum_column( + async def create_enum_column( self, database_id: str, table_id: str, @@ -2070,7 +2070,7 @@ def create_enum_column( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -2083,7 +2083,7 @@ def create_enum_column( return self._parse_response(response, model=ColumnEnum) - def update_enum_column( + async def update_enum_column( self, database_id: str, table_id: str, @@ -2149,7 +2149,7 @@ def update_enum_column( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -2162,7 +2162,7 @@ def update_enum_column( return self._parse_response(response, model=ColumnEnum) - def create_float_column( + async def create_float_column( self, database_id: str, table_id: str, @@ -2233,7 +2233,7 @@ def create_float_column( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -2246,7 +2246,7 @@ def create_float_column( return self._parse_response(response, model=ColumnFloat) - def update_float_column( + async def update_float_column( self, database_id: str, table_id: str, @@ -2316,7 +2316,7 @@ def update_float_column( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -2329,7 +2329,7 @@ def update_float_column( return self._parse_response(response, model=ColumnFloat) - def create_integer_column( + async def create_integer_column( self, database_id: str, table_id: str, @@ -2400,7 +2400,7 @@ def create_integer_column( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -2413,7 +2413,7 @@ def create_integer_column( return self._parse_response(response, model=ColumnInteger) - def update_integer_column( + async def update_integer_column( self, database_id: str, table_id: str, @@ -2483,7 +2483,7 @@ def update_integer_column( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -2496,7 +2496,7 @@ def update_integer_column( return self._parse_response(response, model=ColumnInteger) - def create_ip_column( + async def create_ip_column( self, database_id: str, table_id: str, @@ -2557,7 +2557,7 @@ def create_ip_column( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -2570,7 +2570,7 @@ def create_ip_column( return self._parse_response(response, model=ColumnIp) - def update_ip_column( + async def update_ip_column( self, database_id: str, table_id: str, @@ -2630,7 +2630,7 @@ def update_ip_column( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -2643,7 +2643,7 @@ def update_ip_column( return self._parse_response(response, model=ColumnIp) - def create_line_column( + async def create_line_column( self, database_id: str, table_id: str, @@ -2699,7 +2699,7 @@ def create_line_column( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -2712,7 +2712,7 @@ def create_line_column( return self._parse_response(response, model=ColumnLine) - def update_line_column( + async def update_line_column( self, database_id: str, table_id: str, @@ -2773,7 +2773,7 @@ def update_line_column( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -2786,7 +2786,7 @@ def update_line_column( return self._parse_response(response, model=ColumnLine) - def create_longtext_column( + async def create_longtext_column( self, database_id: str, table_id: str, @@ -2852,7 +2852,7 @@ def create_longtext_column( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -2865,7 +2865,7 @@ def create_longtext_column( return self._parse_response(response, model=ColumnLongtext) - def update_longtext_column( + async def update_longtext_column( self, database_id: str, table_id: str, @@ -2925,7 +2925,7 @@ def update_longtext_column( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -2938,7 +2938,7 @@ def update_longtext_column( return self._parse_response(response, model=ColumnLongtext) - def create_mediumtext_column( + async def create_mediumtext_column( self, database_id: str, table_id: str, @@ -3004,7 +3004,7 @@ def create_mediumtext_column( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -3017,7 +3017,7 @@ def create_mediumtext_column( return self._parse_response(response, model=ColumnMediumtext) - def update_mediumtext_column( + async def update_mediumtext_column( self, database_id: str, table_id: str, @@ -3077,7 +3077,7 @@ def update_mediumtext_column( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -3090,7 +3090,7 @@ def update_mediumtext_column( return self._parse_response(response, model=ColumnMediumtext) - def create_point_column( + async def create_point_column( self, database_id: str, table_id: str, @@ -3146,7 +3146,7 @@ def create_point_column( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -3159,7 +3159,7 @@ def create_point_column( return self._parse_response(response, model=ColumnPoint) - def update_point_column( + async def update_point_column( self, database_id: str, table_id: str, @@ -3220,7 +3220,7 @@ def update_point_column( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -3233,7 +3233,7 @@ def update_point_column( return self._parse_response(response, model=ColumnPoint) - def create_polygon_column( + async def create_polygon_column( self, database_id: str, table_id: str, @@ -3289,7 +3289,7 @@ def create_polygon_column( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -3302,7 +3302,7 @@ def create_polygon_column( return self._parse_response(response, model=ColumnPolygon) - def update_polygon_column( + async def update_polygon_column( self, database_id: str, table_id: str, @@ -3363,7 +3363,7 @@ def update_polygon_column( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -3376,7 +3376,7 @@ def update_polygon_column( return self._parse_response(response, model=ColumnPolygon) - def create_relationship_column( + async def create_relationship_column( self, database_id: str, table_id: str, @@ -3447,7 +3447,7 @@ def create_relationship_column( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -3460,7 +3460,7 @@ def create_relationship_column( return self._parse_response(response, model=ColumnRelationship) - def update_relationship_column( + async def update_relationship_column( self, database_id: str, table_id: str, @@ -3515,7 +3515,7 @@ def update_relationship_column( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -3529,7 +3529,7 @@ def update_relationship_column( return self._parse_response(response, model=ColumnRelationship) @deprecated("This API has been deprecated since 1.9.0. Please use `tablesDB.create_text_column` instead.") - def create_string_column( + async def create_string_column( self, database_id: str, table_id: str, @@ -3603,7 +3603,7 @@ def create_string_column( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -3617,7 +3617,7 @@ def create_string_column( return self._parse_response(response, model=ColumnString) @deprecated("This API has been deprecated since 1.8.0. Please use `tablesDB.update_text_column` instead.") - def update_string_column( + async def update_string_column( self, database_id: str, table_id: str, @@ -3684,7 +3684,7 @@ def update_string_column( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -3697,7 +3697,7 @@ def update_string_column( return self._parse_response(response, model=ColumnString) - def create_text_column( + async def create_text_column( self, database_id: str, table_id: str, @@ -3763,7 +3763,7 @@ def create_text_column( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -3776,7 +3776,7 @@ def create_text_column( return self._parse_response(response, model=ColumnText) - def update_text_column( + async def update_text_column( self, database_id: str, table_id: str, @@ -3836,7 +3836,7 @@ def update_text_column( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -3849,7 +3849,7 @@ def update_text_column( return self._parse_response(response, model=ColumnText) - def create_url_column( + async def create_url_column( self, database_id: str, table_id: str, @@ -3910,7 +3910,7 @@ def create_url_column( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -3923,7 +3923,7 @@ def create_url_column( return self._parse_response(response, model=ColumnUrl) - def update_url_column( + async def update_url_column( self, database_id: str, table_id: str, @@ -3983,7 +3983,7 @@ def update_url_column( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -3996,7 +3996,7 @@ def update_url_column( return self._parse_response(response, model=ColumnUrl) - def create_varchar_column( + async def create_varchar_column( self, database_id: str, table_id: str, @@ -4068,7 +4068,7 @@ def create_varchar_column( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -4081,7 +4081,7 @@ def create_varchar_column( return self._parse_response(response, model=ColumnVarchar) - def update_varchar_column( + async def update_varchar_column( self, database_id: str, table_id: str, @@ -4146,7 +4146,7 @@ def update_varchar_column( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -4159,7 +4159,7 @@ def update_varchar_column( return self._parse_response(response, model=ColumnVarchar) - def get_column( + async def get_column( self, database_id: str, table_id: str, @@ -4218,7 +4218,7 @@ def get_column( api_path = api_path.replace('{tableId}', str(self._normalize_value(table_id))) api_path = api_path.replace('{key}', str(self._normalize_value(key))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -4286,7 +4286,7 @@ def get_column( raise AppwriteException('Unable to match response to any known model') - def delete_column( + async def delete_column( self, database_id: str, table_id: str, @@ -4326,7 +4326,7 @@ def delete_column( api_path = api_path.replace('{tableId}', str(self._normalize_value(table_id))) api_path = api_path.replace('{key}', str(self._normalize_value(key))) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -4339,7 +4339,7 @@ def delete_column( return response - def list_indexes( + async def list_indexes( self, database_id: str, table_id: str, @@ -4383,7 +4383,7 @@ def list_indexes( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -4395,7 +4395,7 @@ def list_indexes( return self._parse_response(response, model=ColumnIndexList) - def create_index( + async def create_index( self, database_id: str, table_id: str, @@ -4463,7 +4463,7 @@ def create_index( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -4476,7 +4476,7 @@ def create_index( return self._parse_response(response, model=ColumnIndex) - def get_index( + async def get_index( self, database_id: str, table_id: str, @@ -4516,7 +4516,7 @@ def get_index( api_path = api_path.replace('{tableId}', str(self._normalize_value(table_id))) api_path = api_path.replace('{key}', str(self._normalize_value(key))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -4528,7 +4528,7 @@ def get_index( return self._parse_response(response, model=ColumnIndex) - def delete_index( + async def delete_index( self, database_id: str, table_id: str, @@ -4568,7 +4568,7 @@ def delete_index( api_path = api_path.replace('{tableId}', str(self._normalize_value(table_id))) api_path = api_path.replace('{key}', str(self._normalize_value(key))) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -4581,7 +4581,7 @@ def delete_index( return response - def list_rows( + async def list_rows( self, database_id: str, table_id: str, @@ -4641,7 +4641,7 @@ def list_rows( if ttl is not None: api_params['ttl'] = self._normalize_value(ttl) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -4653,7 +4653,7 @@ def list_rows( return RowList.with_data(response, model_type) - def create_row( + async def create_row( self, database_id: str, table_id: str, @@ -4713,7 +4713,7 @@ def create_row( if transaction_id is not None: api_params['transactionId'] = self._normalize_value(transaction_id) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -4726,7 +4726,7 @@ def create_row( return Row.with_data(response, model_type) - def create_rows( + async def create_rows( self, database_id: str, table_id: str, @@ -4775,7 +4775,7 @@ def create_rows( if transaction_id is not None: api_params['transactionId'] = self._normalize_value(transaction_id) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -4788,7 +4788,7 @@ def create_rows( return RowList.with_data(response, model_type) - def upsert_rows( + async def upsert_rows( self, database_id: str, table_id: str, @@ -4837,7 +4837,7 @@ def upsert_rows( if transaction_id is not None: api_params['transactionId'] = self._normalize_value(transaction_id) - response = self.client.call( + response = await self.client.call( 'put', api_path, { @@ -4850,7 +4850,7 @@ def upsert_rows( return RowList.with_data(response, model_type) - def update_rows( + async def update_rows( self, database_id: str, table_id: str, @@ -4903,7 +4903,7 @@ def update_rows( if transaction_id is not None: api_params['transactionId'] = self._normalize_value(transaction_id) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -4916,7 +4916,7 @@ def update_rows( return RowList.with_data(response, model_type) - def delete_rows( + async def delete_rows( self, database_id: str, table_id: str, @@ -4964,7 +4964,7 @@ def delete_rows( if transaction_id is not None: api_params['transactionId'] = self._normalize_value(transaction_id) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -4977,7 +4977,7 @@ def delete_rows( return RowList.with_data(response, model_type) - def create_query( + async def create_query( self, database_id: str, table_id: str, @@ -5035,7 +5035,7 @@ def create_query( if ttl is not None: api_params['ttl'] = self._normalize_value(ttl) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -5048,7 +5048,7 @@ def create_query( return RowList.with_data(response, model_type) - def get_row( + async def get_row( self, database_id: str, table_id: str, @@ -5102,7 +5102,7 @@ def get_row( if transaction_id is not None: api_params['transactionId'] = self._normalize_value(transaction_id) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -5114,7 +5114,7 @@ def get_row( return Row.with_data(response, model_type) - def upsert_row( + async def upsert_row( self, database_id: str, table_id: str, @@ -5173,7 +5173,7 @@ def upsert_row( if transaction_id is not None: api_params['transactionId'] = self._normalize_value(transaction_id) - response = self.client.call( + response = await self.client.call( 'put', api_path, { @@ -5186,7 +5186,7 @@ def upsert_row( return Row.with_data(response, model_type) - def update_row( + async def update_row( self, database_id: str, table_id: str, @@ -5245,7 +5245,7 @@ def update_row( if transaction_id is not None: api_params['transactionId'] = self._normalize_value(transaction_id) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -5258,7 +5258,7 @@ def update_row( return Row.with_data(response, model_type) - def delete_row( + async def delete_row( self, database_id: str, table_id: str, @@ -5303,7 +5303,7 @@ def delete_row( if transaction_id is not None: api_params['transactionId'] = self._normalize_value(transaction_id) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -5316,7 +5316,7 @@ def delete_row( return response - def decrement_row_column( + async def decrement_row_column( self, database_id: str, table_id: str, @@ -5381,7 +5381,7 @@ def decrement_row_column( if transaction_id is not None: api_params['transactionId'] = self._normalize_value(transaction_id) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -5394,7 +5394,7 @@ def decrement_row_column( return Row.with_data(response, model_type) - def increment_row_column( + async def increment_row_column( self, database_id: str, table_id: str, @@ -5459,7 +5459,7 @@ def increment_row_column( if transaction_id is not None: api_params['transactionId'] = self._normalize_value(transaction_id) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { diff --git a/appwrite/services/teams.py b/appwrite/services/teams.py index 00a695d3..93488b0e 100644 --- a/appwrite/services/teams.py +++ b/appwrite/services/teams.py @@ -19,7 +19,7 @@ class Teams(Service): def __init__(self, client) -> None: super(Teams, self).__init__(client) - def list( + async def list( self, queries: Optional[List[str]] = None, search: Optional[str] = None, @@ -60,7 +60,7 @@ def list( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -72,7 +72,7 @@ def list( return TeamList.with_data(response, model_type) - def create( + async def create( self, team_id: str, name: str, @@ -115,7 +115,7 @@ def create( if roles is not None: api_params['roles'] = self._normalize_value(roles) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -128,7 +128,7 @@ def create( return Team.with_data(response, model_type) - def get( + async def get( self, team_id: str, model_type: Type[T] = dict, @@ -160,7 +160,7 @@ def get( raise AppwriteException('Missing required parameter: "team_id"') api_path = api_path.replace('{teamId}', str(self._normalize_value(team_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -172,7 +172,7 @@ def get( return Team.with_data(response, model_type) - def update_name( + async def update_name( self, team_id: str, name: str, @@ -210,7 +210,7 @@ def update_name( api_path = api_path.replace('{teamId}', str(self._normalize_value(team_id))) api_params['name'] = self._normalize_value(name) - response = self.client.call( + response = await self.client.call( 'put', api_path, { @@ -223,7 +223,7 @@ def update_name( return Team.with_data(response, model_type) - def delete( + async def delete( self, team_id: str, ) -> Dict[str, Any]: @@ -251,7 +251,7 @@ def delete( raise AppwriteException('Missing required parameter: "team_id"') api_path = api_path.replace('{teamId}', str(self._normalize_value(team_id))) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -264,7 +264,7 @@ def delete( return response - def list_installations( + async def list_installations( self, team_id: str, queries: Optional[List[str]] = None, @@ -302,7 +302,7 @@ def list_installations( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -314,7 +314,7 @@ def list_installations( return self._parse_response(response, model=AppInstallationList) - def create_installation( + async def create_installation( self, team_id: str, app_id: str, @@ -353,7 +353,7 @@ def create_installation( if authorization_details is not None: api_params['authorizationDetails'] = self._normalize_value(authorization_details) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -366,7 +366,7 @@ def create_installation( return self._parse_response(response, model=AppInstallation) - def get_installation( + async def get_installation( self, team_id: str, installation_id: str, @@ -400,7 +400,7 @@ def get_installation( api_path = api_path.replace('{teamId}', str(self._normalize_value(team_id))) api_path = api_path.replace('{installationId}', str(self._normalize_value(installation_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -412,7 +412,7 @@ def get_installation( return self._parse_response(response, model=AppInstallation) - def update_installation( + async def update_installation( self, team_id: str, installation_id: str, @@ -451,7 +451,7 @@ def update_installation( if authorization_details is not None: api_params['authorizationDetails'] = self._normalize_value(authorization_details) - response = self.client.call( + response = await self.client.call( 'put', api_path, { @@ -464,7 +464,7 @@ def update_installation( return self._parse_response(response, model=AppInstallation) - def delete_installation( + async def delete_installation( self, team_id: str, installation_id: str, @@ -498,7 +498,7 @@ def delete_installation( api_path = api_path.replace('{teamId}', str(self._normalize_value(team_id))) api_path = api_path.replace('{installationId}', str(self._normalize_value(installation_id))) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -511,7 +511,7 @@ def delete_installation( return response - def list_memberships( + async def list_memberships( self, team_id: str, queries: Optional[List[str]] = None, @@ -554,7 +554,7 @@ def list_memberships( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -566,7 +566,7 @@ def list_memberships( return self._parse_response(response, model=MembershipList) - def create_membership( + async def create_membership( self, team_id: str, roles: List[str], @@ -636,7 +636,7 @@ def create_membership( if membership_id is not None: api_params['membershipId'] = self._normalize_value(membership_id) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -649,7 +649,7 @@ def create_membership( return self._parse_response(response, model=Membership) - def get_membership( + async def get_membership( self, team_id: str, membership_id: str, @@ -683,7 +683,7 @@ def get_membership( api_path = api_path.replace('{teamId}', str(self._normalize_value(team_id))) api_path = api_path.replace('{membershipId}', str(self._normalize_value(membership_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -695,7 +695,7 @@ def get_membership( return self._parse_response(response, model=Membership) - def update_membership( + async def update_membership( self, team_id: str, membership_id: str, @@ -735,7 +735,7 @@ def update_membership( api_path = api_path.replace('{membershipId}', str(self._normalize_value(membership_id))) api_params['roles'] = self._normalize_value(roles) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -748,7 +748,7 @@ def update_membership( return self._parse_response(response, model=Membership) - def delete_membership( + async def delete_membership( self, team_id: str, membership_id: str, @@ -782,7 +782,7 @@ def delete_membership( api_path = api_path.replace('{teamId}', str(self._normalize_value(team_id))) api_path = api_path.replace('{membershipId}', str(self._normalize_value(membership_id))) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -795,7 +795,7 @@ def delete_membership( return response - def update_membership_status( + async def update_membership_status( self, team_id: str, membership_id: str, @@ -843,7 +843,7 @@ def update_membership_status( api_params['userId'] = self._normalize_value(user_id) api_params['secret'] = self._normalize_value(secret) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -856,7 +856,7 @@ def update_membership_status( return self._parse_response(response, model=Membership) - def get_prefs( + async def get_prefs( self, team_id: str, model_type: Type[T] = dict, @@ -888,7 +888,7 @@ def get_prefs( raise AppwriteException('Missing required parameter: "team_id"') api_path = api_path.replace('{teamId}', str(self._normalize_value(team_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -900,7 +900,7 @@ def get_prefs( return Preferences.with_data(response, model_type) - def update_prefs( + async def update_prefs( self, team_id: str, prefs: Dict[str, Any], @@ -938,7 +938,7 @@ def update_prefs( api_path = api_path.replace('{teamId}', str(self._normalize_value(team_id))) api_params['prefs'] = self._normalize_value(prefs) - response = self.client.call( + response = await self.client.call( 'put', api_path, { diff --git a/appwrite/services/tokens.py b/appwrite/services/tokens.py index b3edf492..20cc01fd 100644 --- a/appwrite/services/tokens.py +++ b/appwrite/services/tokens.py @@ -12,7 +12,7 @@ class Tokens(Service): def __init__(self, client) -> None: super(Tokens, self).__init__(client) - def list( + async def list( self, bucket_id: str, file_id: str, @@ -56,7 +56,7 @@ def list( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -68,7 +68,7 @@ def list( return self._parse_response(response, model=ResourceTokenList) - def create_file_token( + async def create_file_token( self, bucket_id: str, file_id: str, @@ -107,7 +107,7 @@ def create_file_token( if expire is not None: api_params['expire'] = self._normalize_value(expire) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -120,7 +120,7 @@ def create_file_token( return self._parse_response(response, model=ResourceToken) - def get( + async def get( self, token_id: str, ) -> ResourceToken: @@ -148,7 +148,7 @@ def get( raise AppwriteException('Missing required parameter: "token_id"') api_path = api_path.replace('{tokenId}', str(self._normalize_value(token_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -160,7 +160,7 @@ def get( return self._parse_response(response, model=ResourceToken) - def update( + async def update( self, token_id: str, expire: Optional[str] = None, @@ -193,7 +193,7 @@ def update( if expire is not None: api_params['expire'] = self._normalize_value(expire) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -206,7 +206,7 @@ def update( return self._parse_response(response, model=ResourceToken) - def delete( + async def delete( self, token_id: str, ) -> Dict[str, Any]: @@ -234,7 +234,7 @@ def delete( raise AppwriteException('Missing required parameter: "token_id"') api_path = api_path.replace('{tokenId}', str(self._normalize_value(token_id))) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { diff --git a/appwrite/services/users.py b/appwrite/services/users.py index 6e89654b..32df1f7b 100644 --- a/appwrite/services/users.py +++ b/appwrite/services/users.py @@ -31,7 +31,7 @@ class Users(Service): def __init__(self, client) -> None: super(Users, self).__init__(client) - def list( + async def list( self, queries: Optional[List[str]] = None, search: Optional[str] = None, @@ -72,7 +72,7 @@ def list( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -84,7 +84,7 @@ def list( return UserList.with_data(response, model_type) - def create( + async def create( self, user_id: str, email: Optional[str] = None, @@ -136,7 +136,7 @@ def create( if name is not None: api_params['name'] = self._normalize_value(name) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -149,7 +149,7 @@ def create( return User.with_data(response, model_type) - def create_argon2_user( + async def create_argon2_user( self, user_id: str, email: str, @@ -198,7 +198,7 @@ def create_argon2_user( if name is not None: api_params['name'] = self._normalize_value(name) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -211,7 +211,7 @@ def create_argon2_user( return User.with_data(response, model_type) - def create_bcrypt_user( + async def create_bcrypt_user( self, user_id: str, email: str, @@ -260,7 +260,7 @@ def create_bcrypt_user( if name is not None: api_params['name'] = self._normalize_value(name) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -273,7 +273,7 @@ def create_bcrypt_user( return User.with_data(response, model_type) - def list_identities( + async def list_identities( self, queries: Optional[List[str]] = None, search: Optional[str] = None, @@ -310,7 +310,7 @@ def list_identities( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -322,7 +322,7 @@ def list_identities( return self._parse_response(response, model=IdentityList) - def delete_identity( + async def delete_identity( self, identity_id: str, ) -> Dict[str, Any]: @@ -350,7 +350,7 @@ def delete_identity( raise AppwriteException('Missing required parameter: "identity_id"') api_path = api_path.replace('{identityId}', str(self._normalize_value(identity_id))) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -363,7 +363,7 @@ def delete_identity( return response - def create_md5_user( + async def create_md5_user( self, user_id: str, email: str, @@ -412,7 +412,7 @@ def create_md5_user( if name is not None: api_params['name'] = self._normalize_value(name) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -425,7 +425,7 @@ def create_md5_user( return User.with_data(response, model_type) - def create_ph_pass_user( + async def create_ph_pass_user( self, user_id: str, email: str, @@ -474,7 +474,7 @@ def create_ph_pass_user( if name is not None: api_params['name'] = self._normalize_value(name) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -487,7 +487,7 @@ def create_ph_pass_user( return User.with_data(response, model_type) - def create_scrypt_user( + async def create_scrypt_user( self, user_id: str, email: str, @@ -566,7 +566,7 @@ def create_scrypt_user( if name is not None: api_params['name'] = self._normalize_value(name) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -579,7 +579,7 @@ def create_scrypt_user( return User.with_data(response, model_type) - def create_scrypt_modified_user( + async def create_scrypt_modified_user( self, user_id: str, email: str, @@ -646,7 +646,7 @@ def create_scrypt_modified_user( if name is not None: api_params['name'] = self._normalize_value(name) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -659,7 +659,7 @@ def create_scrypt_modified_user( return User.with_data(response, model_type) - def create_sha_user( + async def create_sha_user( self, user_id: str, email: str, @@ -713,7 +713,7 @@ def create_sha_user( if name is not None: api_params['name'] = self._normalize_value(name) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -726,7 +726,7 @@ def create_sha_user( return User.with_data(response, model_type) - def get( + async def get( self, user_id: str, model_type: Type[T] = dict, @@ -758,7 +758,7 @@ def get( raise AppwriteException('Missing required parameter: "user_id"') api_path = api_path.replace('{userId}', str(self._normalize_value(user_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -770,7 +770,7 @@ def get( return User.with_data(response, model_type) - def delete( + async def delete( self, user_id: str, ) -> Dict[str, Any]: @@ -798,7 +798,7 @@ def delete( raise AppwriteException('Missing required parameter: "user_id"') api_path = api_path.replace('{userId}', str(self._normalize_value(user_id))) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -811,7 +811,7 @@ def delete( return response - def update_email( + async def update_email( self, user_id: str, email: str, @@ -849,7 +849,7 @@ def update_email( api_path = api_path.replace('{userId}', str(self._normalize_value(user_id))) api_params['email'] = self._normalize_value(email) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -862,7 +862,7 @@ def update_email( return User.with_data(response, model_type) - def update_impersonator( + async def update_impersonator( self, user_id: str, impersonator: bool, @@ -900,7 +900,7 @@ def update_impersonator( api_path = api_path.replace('{userId}', str(self._normalize_value(user_id))) api_params['impersonator'] = self._normalize_value(impersonator) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -913,7 +913,7 @@ def update_impersonator( return User.with_data(response, model_type) - def create_jwt( + async def create_jwt( self, user_id: str, session_id: Optional[str] = None, @@ -951,7 +951,7 @@ def create_jwt( if duration is not None: api_params['duration'] = self._normalize_value(duration) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -964,7 +964,7 @@ def create_jwt( return self._parse_response(response, model=Jwt) - def update_labels( + async def update_labels( self, user_id: str, labels: List[str], @@ -1004,7 +1004,7 @@ def update_labels( api_path = api_path.replace('{userId}', str(self._normalize_value(user_id))) api_params['labels'] = self._normalize_value(labels) - response = self.client.call( + response = await self.client.call( 'put', api_path, { @@ -1017,7 +1017,7 @@ def update_labels( return User.with_data(response, model_type) - def list_memberships( + async def list_memberships( self, user_id: str, queries: Optional[List[str]] = None, @@ -1060,7 +1060,7 @@ def list_memberships( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -1072,7 +1072,7 @@ def list_memberships( return self._parse_response(response, model=MembershipList) - def update_mfa( + async def update_mfa( self, user_id: str, mfa: bool, @@ -1110,7 +1110,7 @@ def update_mfa( api_path = api_path.replace('{userId}', str(self._normalize_value(user_id))) api_params['mfa'] = self._normalize_value(mfa) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -1123,7 +1123,7 @@ def update_mfa( return User.with_data(response, model_type) - def delete_mfa_authenticator( + async def delete_mfa_authenticator( self, user_id: str, type: AuthenticatorType, @@ -1157,7 +1157,7 @@ def delete_mfa_authenticator( api_path = api_path.replace('{userId}', str(self._normalize_value(user_id))) api_path = api_path.replace('{type}', str(self._normalize_value(type))) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -1170,7 +1170,7 @@ def delete_mfa_authenticator( return response - def get_mfa_challenge( + async def get_mfa_challenge( self, user_id: str, challenge_id: str, @@ -1204,7 +1204,7 @@ def get_mfa_challenge( api_path = api_path.replace('{userId}', str(self._normalize_value(user_id))) api_path = api_path.replace('{challengeId}', str(self._normalize_value(challenge_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -1216,7 +1216,7 @@ def get_mfa_challenge( return self._parse_response(response, model=MfaChallengeSecret) - def list_mfa_factors( + async def list_mfa_factors( self, user_id: str, ) -> MfaFactors: @@ -1244,7 +1244,7 @@ def list_mfa_factors( raise AppwriteException('Missing required parameter: "user_id"') api_path = api_path.replace('{userId}', str(self._normalize_value(user_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -1256,7 +1256,7 @@ def list_mfa_factors( return self._parse_response(response, model=MfaFactors) - def get_mfa_recovery_codes( + async def get_mfa_recovery_codes( self, user_id: str, ) -> MfaRecoveryCodes: @@ -1284,7 +1284,7 @@ def get_mfa_recovery_codes( raise AppwriteException('Missing required parameter: "user_id"') api_path = api_path.replace('{userId}', str(self._normalize_value(user_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -1296,7 +1296,7 @@ def get_mfa_recovery_codes( return self._parse_response(response, model=MfaRecoveryCodes) - def update_mfa_recovery_codes( + async def update_mfa_recovery_codes( self, user_id: str, ) -> MfaRecoveryCodes: @@ -1324,7 +1324,7 @@ def update_mfa_recovery_codes( raise AppwriteException('Missing required parameter: "user_id"') api_path = api_path.replace('{userId}', str(self._normalize_value(user_id))) - response = self.client.call( + response = await self.client.call( 'put', api_path, { @@ -1337,7 +1337,7 @@ def update_mfa_recovery_codes( return self._parse_response(response, model=MfaRecoveryCodes) - def create_mfa_recovery_codes( + async def create_mfa_recovery_codes( self, user_id: str, ) -> MfaRecoveryCodes: @@ -1365,7 +1365,7 @@ def create_mfa_recovery_codes( raise AppwriteException('Missing required parameter: "user_id"') api_path = api_path.replace('{userId}', str(self._normalize_value(user_id))) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -1378,7 +1378,7 @@ def create_mfa_recovery_codes( return self._parse_response(response, model=MfaRecoveryCodes) - def update_name( + async def update_name( self, user_id: str, name: str, @@ -1416,7 +1416,7 @@ def update_name( api_path = api_path.replace('{userId}', str(self._normalize_value(user_id))) api_params['name'] = self._normalize_value(name) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -1429,7 +1429,7 @@ def update_name( return User.with_data(response, model_type) - def list_passkeys( + async def list_passkeys( self, user_id: str, queries: Optional[List[str]] = None, @@ -1467,7 +1467,7 @@ def list_passkeys( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -1479,7 +1479,7 @@ def list_passkeys( return self._parse_response(response, model=PasskeyList) - def get_passkey( + async def get_passkey( self, user_id: str, passkey_id: str, @@ -1513,7 +1513,7 @@ def get_passkey( api_path = api_path.replace('{userId}', str(self._normalize_value(user_id))) api_path = api_path.replace('{passkeyId}', str(self._normalize_value(passkey_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -1525,7 +1525,7 @@ def get_passkey( return self._parse_response(response, model=Passkey) - def update_passkey( + async def update_passkey( self, user_id: str, passkey_id: str, @@ -1565,7 +1565,7 @@ def update_passkey( api_path = api_path.replace('{passkeyId}', str(self._normalize_value(passkey_id))) api_params['name'] = self._normalize_value(name) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -1578,7 +1578,7 @@ def update_passkey( return self._parse_response(response, model=Passkey) - def delete_passkey( + async def delete_passkey( self, user_id: str, passkey_id: str, @@ -1612,7 +1612,7 @@ def delete_passkey( api_path = api_path.replace('{userId}', str(self._normalize_value(user_id))) api_path = api_path.replace('{passkeyId}', str(self._normalize_value(passkey_id))) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -1625,7 +1625,7 @@ def delete_passkey( return response - def update_password( + async def update_password( self, user_id: str, password: str, @@ -1663,7 +1663,7 @@ def update_password( api_path = api_path.replace('{userId}', str(self._normalize_value(user_id))) api_params['password'] = self._normalize_value(password) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -1676,7 +1676,7 @@ def update_password( return User.with_data(response, model_type) - def update_phone( + async def update_phone( self, user_id: str, number: str, @@ -1714,7 +1714,7 @@ def update_phone( api_path = api_path.replace('{userId}', str(self._normalize_value(user_id))) api_params['number'] = self._normalize_value(number) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -1727,7 +1727,7 @@ def update_phone( return User.with_data(response, model_type) - def get_prefs( + async def get_prefs( self, user_id: str, model_type: Type[T] = dict, @@ -1759,7 +1759,7 @@ def get_prefs( raise AppwriteException('Missing required parameter: "user_id"') api_path = api_path.replace('{userId}', str(self._normalize_value(user_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -1771,7 +1771,7 @@ def get_prefs( return Preferences.with_data(response, model_type) - def update_prefs( + async def update_prefs( self, user_id: str, prefs: Dict[str, Any], @@ -1809,7 +1809,7 @@ def update_prefs( api_path = api_path.replace('{userId}', str(self._normalize_value(user_id))) api_params['prefs'] = self._normalize_value(prefs) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -1822,7 +1822,7 @@ def update_prefs( return Preferences.with_data(response, model_type) - def list_sessions( + async def list_sessions( self, user_id: str, total: Optional[bool] = None, @@ -1855,7 +1855,7 @@ def list_sessions( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -1867,7 +1867,7 @@ def list_sessions( return self._parse_response(response, model=SessionList) - def create_session( + async def create_session( self, user_id: str, ) -> Session: @@ -1897,7 +1897,7 @@ def create_session( raise AppwriteException('Missing required parameter: "user_id"') api_path = api_path.replace('{userId}', str(self._normalize_value(user_id))) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -1910,7 +1910,7 @@ def create_session( return self._parse_response(response, model=Session) - def delete_sessions( + async def delete_sessions( self, user_id: str, ) -> Dict[str, Any]: @@ -1938,7 +1938,7 @@ def delete_sessions( raise AppwriteException('Missing required parameter: "user_id"') api_path = api_path.replace('{userId}', str(self._normalize_value(user_id))) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -1951,7 +1951,7 @@ def delete_sessions( return response - def delete_session( + async def delete_session( self, user_id: str, session_id: str, @@ -1985,7 +1985,7 @@ def delete_session( api_path = api_path.replace('{userId}', str(self._normalize_value(user_id))) api_path = api_path.replace('{sessionId}', str(self._normalize_value(session_id))) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -1998,7 +1998,7 @@ def delete_session( return response - def update_status( + async def update_status( self, user_id: str, status: bool, @@ -2036,7 +2036,7 @@ def update_status( api_path = api_path.replace('{userId}', str(self._normalize_value(user_id))) api_params['status'] = self._normalize_value(status) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -2049,7 +2049,7 @@ def update_status( return User.with_data(response, model_type) - def list_targets( + async def list_targets( self, user_id: str, queries: Optional[List[str]] = None, @@ -2087,7 +2087,7 @@ def list_targets( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -2099,7 +2099,7 @@ def list_targets( return self._parse_response(response, model=TargetList) - def create_target( + async def create_target( self, user_id: str, target_id: str, @@ -2155,7 +2155,7 @@ def create_target( if name is not None: api_params['name'] = self._normalize_value(name) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -2168,7 +2168,7 @@ def create_target( return self._parse_response(response, model=Target) - def get_target( + async def get_target( self, user_id: str, target_id: str, @@ -2202,7 +2202,7 @@ def get_target( api_path = api_path.replace('{userId}', str(self._normalize_value(user_id))) api_path = api_path.replace('{targetId}', str(self._normalize_value(target_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -2214,7 +2214,7 @@ def get_target( return self._parse_response(response, model=Target) - def update_target( + async def update_target( self, user_id: str, target_id: str, @@ -2263,7 +2263,7 @@ def update_target( if name is not None: api_params['name'] = self._normalize_value(name) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -2276,7 +2276,7 @@ def update_target( return self._parse_response(response, model=Target) - def delete_target( + async def delete_target( self, user_id: str, target_id: str, @@ -2310,7 +2310,7 @@ def delete_target( api_path = api_path.replace('{userId}', str(self._normalize_value(user_id))) api_path = api_path.replace('{targetId}', str(self._normalize_value(target_id))) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -2323,7 +2323,7 @@ def delete_target( return response - def create_token( + async def create_token( self, user_id: str, length: Optional[float] = None, @@ -2361,7 +2361,7 @@ def create_token( if expire is not None: api_params['expire'] = self._normalize_value(expire) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -2374,7 +2374,7 @@ def create_token( return self._parse_response(response, model=Token) - def update_email_verification( + async def update_email_verification( self, user_id: str, email_verification: bool, @@ -2412,7 +2412,7 @@ def update_email_verification( api_path = api_path.replace('{userId}', str(self._normalize_value(user_id))) api_params['emailVerification'] = self._normalize_value(email_verification) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -2425,7 +2425,7 @@ def update_email_verification( return User.with_data(response, model_type) - def update_phone_verification( + async def update_phone_verification( self, user_id: str, phone_verification: bool, @@ -2463,7 +2463,7 @@ def update_phone_verification( api_path = api_path.replace('{userId}', str(self._normalize_value(user_id))) api_params['phoneVerification'] = self._normalize_value(phone_verification) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { diff --git a/appwrite/services/vectors_db.py b/appwrite/services/vectors_db.py index eda5f00d..f49408a0 100644 --- a/appwrite/services/vectors_db.py +++ b/appwrite/services/vectors_db.py @@ -29,7 +29,7 @@ class VectorsDB(Service): def __init__(self, client) -> None: super(VectorsDB, self).__init__(client) - def list( + async def list( self, queries: Optional[List[str]] = None, total: Optional[bool] = None, @@ -61,7 +61,7 @@ def list( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -73,7 +73,7 @@ def list( return self._parse_response(response, model=DatabaseList) - def create( + async def create( self, database_id: str, name: str, @@ -132,7 +132,7 @@ def create( if sync_mode is not None: api_params['syncMode'] = self._normalize_value(sync_mode) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -145,7 +145,7 @@ def create( return self._parse_response(response, model=Database) - def list_specifications( + async def list_specifications( self, ) -> DedicatedDatabaseSpecificationList: """ @@ -164,7 +164,7 @@ def list_specifications( api_path = '/vectorsdb/specifications' api_params = {} - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -176,7 +176,7 @@ def list_specifications( return self._parse_response(response, model=DedicatedDatabaseSpecificationList) - def list_transactions( + async def list_transactions( self, queries: Optional[List[str]] = None, total: Optional[bool] = None, @@ -208,7 +208,7 @@ def list_transactions( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -220,7 +220,7 @@ def list_transactions( return self._parse_response(response, model=TransactionList) - def create_transaction( + async def create_transaction( self, ttl: Optional[float] = None, ) -> Transaction: @@ -247,7 +247,7 @@ def create_transaction( if ttl is not None: api_params['ttl'] = self._normalize_value(ttl) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -260,7 +260,7 @@ def create_transaction( return self._parse_response(response, model=Transaction) - def get_transaction( + async def get_transaction( self, transaction_id: str, ) -> Transaction: @@ -288,7 +288,7 @@ def get_transaction( raise AppwriteException('Missing required parameter: "transaction_id"') api_path = api_path.replace('{transactionId}', str(self._normalize_value(transaction_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -300,7 +300,7 @@ def get_transaction( return self._parse_response(response, model=Transaction) - def update_transaction( + async def update_transaction( self, transaction_id: str, commit: Optional[bool] = None, @@ -338,7 +338,7 @@ def update_transaction( if rollback is not None: api_params['rollback'] = self._normalize_value(rollback) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -351,7 +351,7 @@ def update_transaction( return self._parse_response(response, model=Transaction) - def delete_transaction( + async def delete_transaction( self, transaction_id: str, ) -> Dict[str, Any]: @@ -379,7 +379,7 @@ def delete_transaction( raise AppwriteException('Missing required parameter: "transaction_id"') api_path = api_path.replace('{transactionId}', str(self._normalize_value(transaction_id))) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -392,7 +392,7 @@ def delete_transaction( return response - def create_operations( + async def create_operations( self, transaction_id: str, operations: Optional[List[Dict[str, Any]]] = None, @@ -425,7 +425,7 @@ def create_operations( if operations is not None: api_params['operations'] = self._normalize_value(operations) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -438,7 +438,7 @@ def create_operations( return self._parse_response(response, model=Transaction) - def get( + async def get( self, database_id: str, ) -> Database: @@ -466,7 +466,7 @@ def get( raise AppwriteException('Missing required parameter: "database_id"') api_path = api_path.replace('{databaseId}', str(self._normalize_value(database_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -478,7 +478,7 @@ def get( return self._parse_response(response, model=Database) - def update( + async def update( self, database_id: str, name: str, @@ -537,7 +537,7 @@ def update( if sync_mode is not None: api_params['syncMode'] = self._normalize_value(sync_mode) - response = self.client.call( + response = await self.client.call( 'put', api_path, { @@ -550,7 +550,7 @@ def update( return self._parse_response(response, model=Database) - def delete( + async def delete( self, database_id: str, ) -> Dict[str, Any]: @@ -578,7 +578,7 @@ def delete( raise AppwriteException('Missing required parameter: "database_id"') api_path = api_path.replace('{databaseId}', str(self._normalize_value(database_id))) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -591,7 +591,7 @@ def delete( return response - def list_collections( + async def list_collections( self, database_id: str, queries: Optional[List[str]] = None, @@ -634,7 +634,7 @@ def list_collections( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -646,7 +646,7 @@ def list_collections( return self._parse_response(response, model=VectorsdbCollectionList) - def create_collection( + async def create_collection( self, database_id: str, collection_id: str, @@ -712,7 +712,7 @@ def create_collection( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -725,7 +725,7 @@ def create_collection( return self._parse_response(response, model=VectorsdbCollection) - def get_collection( + async def get_collection( self, database_id: str, collection_id: str, @@ -759,7 +759,7 @@ def get_collection( api_path = api_path.replace('{databaseId}', str(self._normalize_value(database_id))) api_path = api_path.replace('{collectionId}', str(self._normalize_value(collection_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -771,7 +771,7 @@ def get_collection( return self._parse_response(response, model=VectorsdbCollection) - def update_collection( + async def update_collection( self, database_id: str, collection_id: str, @@ -836,7 +836,7 @@ def update_collection( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'put', api_path, { @@ -849,7 +849,7 @@ def update_collection( return self._parse_response(response, model=VectorsdbCollection) - def delete_collection( + async def delete_collection( self, database_id: str, collection_id: str, @@ -883,7 +883,7 @@ def delete_collection( api_path = api_path.replace('{databaseId}', str(self._normalize_value(database_id))) api_path = api_path.replace('{collectionId}', str(self._normalize_value(collection_id))) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -896,7 +896,7 @@ def delete_collection( return response - def list_documents( + async def list_documents( self, database_id: str, collection_id: str, @@ -954,7 +954,7 @@ def list_documents( if ttl is not None: api_params['ttl'] = self._normalize_value(ttl) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -966,7 +966,7 @@ def list_documents( return DocumentList.with_data(response, model_type) - def create_document( + async def create_document( self, database_id: str, collection_id: str, @@ -1026,7 +1026,7 @@ def create_document( if transaction_id is not None: api_params['transactionId'] = self._normalize_value(transaction_id) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -1039,7 +1039,7 @@ def create_document( return Document.with_data(response, model_type) - def create_documents( + async def create_documents( self, database_id: str, collection_id: str, @@ -1088,7 +1088,7 @@ def create_documents( if transaction_id is not None: api_params['transactionId'] = self._normalize_value(transaction_id) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -1101,7 +1101,7 @@ def create_documents( return DocumentList.with_data(response, model_type) - def upsert_documents( + async def upsert_documents( self, database_id: str, collection_id: str, @@ -1150,7 +1150,7 @@ def upsert_documents( if transaction_id is not None: api_params['transactionId'] = self._normalize_value(transaction_id) - response = self.client.call( + response = await self.client.call( 'put', api_path, { @@ -1163,7 +1163,7 @@ def upsert_documents( return DocumentList.with_data(response, model_type) - def update_documents( + async def update_documents( self, database_id: str, collection_id: str, @@ -1216,7 +1216,7 @@ def update_documents( if transaction_id is not None: api_params['transactionId'] = self._normalize_value(transaction_id) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -1229,7 +1229,7 @@ def update_documents( return DocumentList.with_data(response, model_type) - def delete_documents( + async def delete_documents( self, database_id: str, collection_id: str, @@ -1277,7 +1277,7 @@ def delete_documents( if transaction_id is not None: api_params['transactionId'] = self._normalize_value(transaction_id) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -1290,7 +1290,7 @@ def delete_documents( return DocumentList.with_data(response, model_type) - def create_query( + async def create_query( self, database_id: str, collection_id: str, @@ -1348,7 +1348,7 @@ def create_query( if ttl is not None: api_params['ttl'] = self._normalize_value(ttl) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -1361,7 +1361,7 @@ def create_query( return DocumentList.with_data(response, model_type) - def get_document( + async def get_document( self, database_id: str, collection_id: str, @@ -1415,7 +1415,7 @@ def get_document( if transaction_id is not None: api_params['transactionId'] = self._normalize_value(transaction_id) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -1427,7 +1427,7 @@ def get_document( return Document.with_data(response, model_type) - def upsert_document( + async def upsert_document( self, database_id: str, collection_id: str, @@ -1486,7 +1486,7 @@ def upsert_document( if transaction_id is not None: api_params['transactionId'] = self._normalize_value(transaction_id) - response = self.client.call( + response = await self.client.call( 'put', api_path, { @@ -1499,7 +1499,7 @@ def upsert_document( return Document.with_data(response, model_type) - def update_document( + async def update_document( self, database_id: str, collection_id: str, @@ -1558,7 +1558,7 @@ def update_document( if transaction_id is not None: api_params['transactionId'] = self._normalize_value(transaction_id) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -1571,7 +1571,7 @@ def update_document( return Document.with_data(response, model_type) - def delete_document( + async def delete_document( self, database_id: str, collection_id: str, @@ -1616,7 +1616,7 @@ def delete_document( if transaction_id is not None: api_params['transactionId'] = self._normalize_value(transaction_id) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -1629,7 +1629,7 @@ def delete_document( return response - def list_indexes( + async def list_indexes( self, database_id: str, collection_id: str, @@ -1673,7 +1673,7 @@ def list_indexes( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -1685,7 +1685,7 @@ def list_indexes( return self._parse_response(response, model=IndexList) - def create_index( + async def create_index( self, database_id: str, collection_id: str, @@ -1753,7 +1753,7 @@ def create_index( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -1766,7 +1766,7 @@ def create_index( return self._parse_response(response, model=Index) - def get_index( + async def get_index( self, database_id: str, collection_id: str, @@ -1806,7 +1806,7 @@ def get_index( api_path = api_path.replace('{collectionId}', str(self._normalize_value(collection_id))) api_path = api_path.replace('{key}', str(self._normalize_value(key))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -1818,7 +1818,7 @@ def get_index( return self._parse_response(response, model=Index) - def delete_index( + async def delete_index( self, database_id: str, collection_id: str, @@ -1858,7 +1858,7 @@ def delete_index( api_path = api_path.replace('{collectionId}', str(self._normalize_value(collection_id))) api_path = api_path.replace('{key}', str(self._normalize_value(key))) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -1871,7 +1871,7 @@ def delete_index( return response - def create_failover( + async def create_failover( self, database_id: str, target_replica_id: Optional[str] = None, @@ -1904,7 +1904,7 @@ def create_failover( if target_replica_id is not None: api_params['targetReplicaId'] = self._normalize_value(target_replica_id) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -1917,7 +1917,7 @@ def create_failover( return self._parse_response(response, model=DedicatedDatabase) - def list_operations( + async def list_operations( self, database_id: str, status: Optional[str] = None, @@ -1960,7 +1960,7 @@ def list_operations( if offset is not None: api_params['offset'] = self._normalize_value(offset) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -1972,7 +1972,7 @@ def list_operations( return self._parse_response(response, model=DedicatedDatabaseOperationList) - def get_replicas( + async def get_replicas( self, database_id: str, ) -> DedicatedDatabaseReplicas: @@ -2000,7 +2000,7 @@ def get_replicas( raise AppwriteException('Missing required parameter: "database_id"') api_path = api_path.replace('{databaseId}', str(self._normalize_value(database_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -2012,7 +2012,7 @@ def get_replicas( return self._parse_response(response, model=DedicatedDatabaseReplicas) - def get_status( + async def get_status( self, database_id: str, ) -> DatabaseStatus: @@ -2040,7 +2040,7 @@ def get_status( raise AppwriteException('Missing required parameter: "database_id"') api_path = api_path.replace('{databaseId}', str(self._normalize_value(database_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { diff --git a/appwrite/services/waf.py b/appwrite/services/waf.py index 8aaa3ebc..184434d5 100644 --- a/appwrite/services/waf.py +++ b/appwrite/services/waf.py @@ -16,7 +16,7 @@ class Waf(Service): def __init__(self, client) -> None: super(Waf, self).__init__(client) - def list_rules( + async def list_rules( self, queries: Optional[List[str]] = None, search: Optional[str] = None, @@ -53,7 +53,7 @@ def list_rules( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -65,7 +65,7 @@ def list_rules( return self._parse_response(response, model=WafRuleList) - def create_bypass_rule( + async def create_bypass_rule( self, rule_id: str, resource_type: str, @@ -130,7 +130,7 @@ def create_bypass_rule( if conditions is not None: api_params['conditions'] = self._normalize_value(conditions) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -143,7 +143,7 @@ def create_bypass_rule( return self._parse_response(response, model=WafRuleBypass) - def update_bypass_rule( + async def update_bypass_rule( self, rule_id: str, resource_type: Optional[str] = None, @@ -206,7 +206,7 @@ def update_bypass_rule( if conditions is not None: api_params['conditions'] = self._normalize_value(conditions) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -219,7 +219,7 @@ def update_bypass_rule( return self._parse_response(response, model=WafRuleBypass) - def create_challenge_rule( + async def create_challenge_rule( self, rule_id: str, resource_type: str, @@ -299,7 +299,7 @@ def create_challenge_rule( if ttl is not None: api_params['ttl'] = self._normalize_value(ttl) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -312,7 +312,7 @@ def create_challenge_rule( return self._parse_response(response, model=WafRuleChallenge) - def update_challenge_rule( + async def update_challenge_rule( self, rule_id: str, resource_type: Optional[str] = None, @@ -390,7 +390,7 @@ def update_challenge_rule( if ttl is not None: api_params['ttl'] = self._normalize_value(ttl) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -403,7 +403,7 @@ def update_challenge_rule( return self._parse_response(response, model=WafRuleChallenge) - def create_deny_rule( + async def create_deny_rule( self, rule_id: str, resource_type: str, @@ -468,7 +468,7 @@ def create_deny_rule( if conditions is not None: api_params['conditions'] = self._normalize_value(conditions) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -481,7 +481,7 @@ def create_deny_rule( return self._parse_response(response, model=WafRuleDeny) - def update_deny_rule( + async def update_deny_rule( self, rule_id: str, resource_type: Optional[str] = None, @@ -544,7 +544,7 @@ def update_deny_rule( if conditions is not None: api_params['conditions'] = self._normalize_value(conditions) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -557,7 +557,7 @@ def update_deny_rule( return self._parse_response(response, model=WafRuleDeny) - def create_rate_limit_rule( + async def create_rate_limit_rule( self, rule_id: str, resource_type: str, @@ -649,7 +649,7 @@ def create_rate_limit_rule( if conditions is not None: api_params['conditions'] = self._normalize_value(conditions) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -662,7 +662,7 @@ def create_rate_limit_rule( return self._parse_response(response, model=WafRuleRateLimit) - def update_rate_limit_rule( + async def update_rate_limit_rule( self, rule_id: str, resource_type: Optional[str] = None, @@ -745,7 +745,7 @@ def update_rate_limit_rule( if conditions is not None: api_params['conditions'] = self._normalize_value(conditions) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -758,7 +758,7 @@ def update_rate_limit_rule( return self._parse_response(response, model=WafRuleRateLimit) - def create_redirect_rule( + async def create_redirect_rule( self, rule_id: str, resource_type: str, @@ -835,7 +835,7 @@ def create_redirect_rule( if conditions is not None: api_params['conditions'] = self._normalize_value(conditions) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -848,7 +848,7 @@ def create_redirect_rule( return self._parse_response(response, model=WafRuleRedirect) - def update_redirect_rule( + async def update_redirect_rule( self, rule_id: str, resource_type: Optional[str] = None, @@ -921,7 +921,7 @@ def update_redirect_rule( if conditions is not None: api_params['conditions'] = self._normalize_value(conditions) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { @@ -934,7 +934,7 @@ def update_redirect_rule( return self._parse_response(response, model=WafRuleRedirect) - def get_rule( + async def get_rule( self, rule_id: str, ) -> Union[ @@ -968,7 +968,7 @@ def get_rule( raise AppwriteException('Missing required parameter: "rule_id"') api_path = api_path.replace('{ruleId}', str(self._normalize_value(rule_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -997,7 +997,7 @@ def get_rule( raise AppwriteException('Unable to match response to any known model') - def delete_rule( + async def delete_rule( self, rule_id: str, ) -> Dict[str, Any]: @@ -1025,7 +1025,7 @@ def delete_rule( raise AppwriteException('Missing required parameter: "rule_id"') api_path = api_path.replace('{ruleId}', str(self._normalize_value(rule_id))) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { diff --git a/appwrite/services/webhooks.py b/appwrite/services/webhooks.py index 41f4ef49..ba00688c 100644 --- a/appwrite/services/webhooks.py +++ b/appwrite/services/webhooks.py @@ -12,7 +12,7 @@ class Webhooks(Service): def __init__(self, client) -> None: super(Webhooks, self).__init__(client) - def list( + async def list( self, queries: Optional[List[str]] = None, total: Optional[bool] = None, @@ -44,7 +44,7 @@ def list( if total is not None: api_params['total'] = self._normalize_value(total) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -56,7 +56,7 @@ def list( return self._parse_response(response, model=WebhookList) - def create( + async def create( self, webhook_id: str, url: str, @@ -132,7 +132,7 @@ def create( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'post', api_path, { @@ -145,7 +145,7 @@ def create( return self._parse_response(response, model=Webhook) - def get( + async def get( self, webhook_id: str, ) -> Webhook: @@ -173,7 +173,7 @@ def get( raise AppwriteException('Missing required parameter: "webhook_id"') api_path = api_path.replace('{webhookId}', str(self._normalize_value(webhook_id))) - response = self.client.call( + response = await self.client.call( 'get', api_path, { @@ -185,7 +185,7 @@ def get( return self._parse_response(response, model=Webhook) - def update( + async def update( self, webhook_id: str, name: str, @@ -256,7 +256,7 @@ def update( if description is not None: api_params['description'] = self._normalize_value(description) - response = self.client.call( + response = await self.client.call( 'put', api_path, { @@ -269,7 +269,7 @@ def update( return self._parse_response(response, model=Webhook) - def delete( + async def delete( self, webhook_id: str, ) -> Dict[str, Any]: @@ -297,7 +297,7 @@ def delete( raise AppwriteException('Missing required parameter: "webhook_id"') api_path = api_path.replace('{webhookId}', str(self._normalize_value(webhook_id))) - response = self.client.call( + response = await self.client.call( 'delete', api_path, { @@ -310,7 +310,7 @@ def delete( return response - def update_secret( + async def update_secret( self, webhook_id: str, secret: Optional[str] = None, @@ -343,7 +343,7 @@ def update_secret( if secret is not None: api_params['secret'] = self._normalize_value(secret) - response = self.client.call( + response = await self.client.call( 'patch', api_path, { diff --git a/appwrite/utils/deprecated.py b/appwrite/utils/deprecated.py index d384ec0d..61d1cdef 100644 --- a/appwrite/utils/deprecated.py +++ b/appwrite/utils/deprecated.py @@ -6,8 +6,34 @@ """ import functools +import inspect +import threading import warnings +# `warnings.filters` is process global, so the temporary filter used to show the +# deprecation warning on every call is guarded by a lock. Without it, two +# threads calling a deprecated function at the same time could restore each +# other's filters and leak the `always` filter into the process. +_filter_lock = threading.RLock() + + +def _warn_deprecated(message, stacklevel=3): + """ + Emit a deprecation warning that is shown on every call. + + The `always` filter is only installed while the warning is emitted and the + filters configured by the caller are restored right after, so concurrent + tasks and threads are never affected by it. + + Args: + message (str): The warning message. + stacklevel (int): Stack level of the frame to blame for the warning. + """ + with _filter_lock: + with warnings.catch_warnings(): + warnings.simplefilter('always', DeprecationWarning) # show warning every time + warnings.warn(message, category=DeprecationWarning, stacklevel=stacklevel) + def deprecated(reason=None): """ @@ -26,14 +52,19 @@ def old_function(...): def decorator(func): message = "Call to deprecated function '{}'.{}".format(func.__name__, " " + reason if reason else "") + if inspect.iscoroutinefunction(func): + + @functools.wraps(func) + async def wrapped(*args, **kwargs): + _warn_deprecated(message) + return await func(*args, **kwargs) + + return wrapped + @functools.wraps(func) def wrapped(*args, **kwargs): - warnings.simplefilter('always', DeprecationWarning) # show warning every time - try: - warnings.warn(message, category=DeprecationWarning, stacklevel=2) - return func(*args, **kwargs) - finally: - warnings.simplefilter('default', DeprecationWarning) # reset filter + _warn_deprecated(message) + return func(*args, **kwargs) return wrapped diff --git a/pyproject.toml b/pyproject.toml index a963b294..0da1053c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,7 +7,7 @@ name = "appwrite" version = "26.0.0" description = "Appwrite is an open-source self-hosted backend server that abstracts and simplifies complex and repetitive development tasks behind a very simple REST API" readme = "README.md" -requires-python = ">=3.9" +requires-python = ">=3.11" license = { text = "BSD-3-Clause" } authors = [ { name = "Appwrite Team", email = "team@appwrite.io" } @@ -16,8 +16,9 @@ maintainers = [ { name = "Appwrite Team", email = "team@appwrite.io" } ] dependencies = [ - "requests", + "httpx2>=2.0,<3", "pydantic>=2,<3", + "anyio>=4,<5", ] classifiers = [ "Development Status :: 5 - Production/Stable", @@ -26,8 +27,6 @@ classifiers = [ "Topic :: Software Development", "License :: OSI Approved :: BSD License", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.9", - "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", "Programming Language :: Python :: 3.13", @@ -35,8 +34,8 @@ classifiers = [ [project.optional-dependencies] test = [ - "black==26.10.1; python_version >= '3.10'", - "requests_mock==1.11.0", + "black==26.10.1", + "respx>=0.21,<1", ] [project.urls] @@ -46,7 +45,7 @@ Repository = "https://github.com/appwrite/sdk-for-python" [tool.black] line-length = 120 skip-string-normalization = true -target-version = ['py39'] +target-version = ['py311'] [tool.setuptools.packages.find] include = ["appwrite*"] diff --git a/requirements.txt b/requirements.txt index b3386211..eb7b2075 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ -requests>=2.31,<3 -requests_mock==1.12.1 +httpx2>=2.0,<3 +respx>=0.21,<1 pydantic>=2,<3 diff --git a/setup.py b/setup.py index 88f54765..741345aa 100644 --- a/setup.py +++ b/setup.py @@ -20,10 +20,10 @@ url='https://appwrite.io/support', download_url='https://github.com/appwrite/sdk-for-python/archive/26.0.0.tar.gz', install_requires=[ - 'requests', + 'httpx2>=2.0,<3', 'pydantic>=2,<3', ], - python_requires='>=3.9', + python_requires='>=3.11', classifiers=[ 'Development Status :: 5 - Production/Stable', 'Intended Audience :: Developers', @@ -31,8 +31,6 @@ 'Topic :: Software Development', 'License :: OSI Approved :: BSD License', 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.9', - 'Programming Language :: Python :: 3.10', 'Programming Language :: Python :: 3.11', 'Programming Language :: Python :: 3.12', 'Programming Language :: Python :: 3.13', diff --git a/test/__init__.py b/test/__init__.py index e69de29b..e4a4d0f4 100644 --- a/test/__init__.py +++ b/test/__init__.py @@ -0,0 +1,4 @@ +import httpx2 + +# Point `import httpx` at httpx2 so respx patches the transport the SDK actually uses. +httpx2.alias_httpx() diff --git a/test/services/test_account.py b/test/services/test_account.py index e37d5b47..271bbb98 100644 --- a/test/services/test_account.py +++ b/test/services/test_account.py @@ -1,5 +1,6 @@ import json -import requests_mock +import httpx2 +import respx import unittest from appwrite.client import Client @@ -8,14 +9,17 @@ from appwrite.services.account import Account -class AccountServiceTest(unittest.TestCase): +class AccountServiceTest(unittest.IsolatedAsyncioTestCase): - def setUp(self): + async def asyncSetUp(self): self.client = Client() self.account = Account(self.client) - @requests_mock.Mocker() - def test_get(self, m): + async def asyncTearDown(self): + await self.client.aclose() + + @respx.mock + async def test_get(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -35,17 +39,14 @@ def test_get(self, m): "accessedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.account.get() + response = await self.account.get() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create(self, m): + @respx.mock + async def test_create(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -65,37 +66,31 @@ def test_create(self, m): "accessedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.account.create( + response = await self.account.create( '', 'email@example.com', 'password', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_list_consents(self, m): + @respx.mock + async def test_list_consents(self): data = { "total": 5.0, "consents": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.account.list_consents() + response = await self.account.list_consents() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_consent(self, m): + @respx.mock + async def test_get_consent(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -109,52 +104,43 @@ def test_get_consent(self, m): "expire": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.account.get_consent( + response = await self.account.get_consent( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete_consent(self, m): + @respx.mock + async def test_delete_consent(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.account.delete_consent( + response = await self.account.delete_consent( '', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_list_consent_tokens(self, m): + @respx.mock + async def test_list_consent_tokens(self): data = { "total": 5.0, "tokens": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.account.list_consent_tokens( + response = await self.account.list_consent_tokens( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_consent_token(self, m): + @respx.mock + async def test_get_consent_token(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -169,36 +155,30 @@ def test_get_consent_token(self, m): "expire": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.account.get_consent_token( + response = await self.account.get_consent_token( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete_consent_token(self, m): + @respx.mock + async def test_delete_consent_token(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.account.delete_consent_token( + response = await self.account.delete_consent_token( '', '', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_update_email(self, m): + @respx.mock + async def test_update_email(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -218,67 +198,55 @@ def test_update_email(self, m): "accessedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.account.update_email( + response = await self.account.update_email( 'email@example.com', 'password', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_list_identities(self, m): + @respx.mock + async def test_list_identities(self): data = { "total": 5.0, "identities": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.account.list_identities() + response = await self.account.list_identities() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete_identity(self, m): + @respx.mock + async def test_delete_identity(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.account.delete_identity( + response = await self.account.delete_identity( '', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_list_memberships(self, m): + @respx.mock + async def test_list_memberships(self): data = { "total": 5.0, "memberships": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.account.list_memberships() + response = await self.account.list_memberships() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_mfa(self, m): + @respx.mock + async def test_update_mfa(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -298,55 +266,46 @@ def test_update_mfa(self, m): "accessedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.account.update_mfa( + response = await self.account.update_mfa( True, ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_mfa_authenticator(self, m): + @respx.mock + async def test_create_mfa_authenticator(self): data = { "secret": "[SHARED_SECRET]", "uri": "otpauth:\/\/totp\/appwrite:user@example.com?secret=[SHARED_SECRET]&issuer=appwrite", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.account.create_mfa_authenticator( + response = await self.account.create_mfa_authenticator( 'totp', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_mfa_authenticator(self, m): + @respx.mock + async def test_create_mfa_authenticator(self): data = { "secret": "[SHARED_SECRET]", "uri": "otpauth:\/\/totp\/appwrite:user@example.com?secret=[SHARED_SECRET]&issuer=appwrite", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.account.create_mfa_authenticator( + response = await self.account.create_mfa_authenticator( 'totp', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_mfa_authenticator(self, m): + @respx.mock + async def test_update_mfa_authenticator(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -366,20 +325,17 @@ def test_update_mfa_authenticator(self, m): "accessedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.account.update_mfa_authenticator( + response = await self.account.update_mfa_authenticator( 'totp', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_mfa_authenticator(self, m): + @respx.mock + async def test_update_mfa_authenticator(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -399,50 +355,41 @@ def test_update_mfa_authenticator(self, m): "accessedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.account.update_mfa_authenticator( + response = await self.account.update_mfa_authenticator( 'totp', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete_mfa_authenticator(self, m): + @respx.mock + async def test_delete_mfa_authenticator(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.account.delete_mfa_authenticator( + response = await self.account.delete_mfa_authenticator( 'totp', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_delete_mfa_authenticator(self, m): + @respx.mock + async def test_delete_mfa_authenticator(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.account.delete_mfa_authenticator( + response = await self.account.delete_mfa_authenticator( 'totp', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_create_mfa_challenge(self, m): + @respx.mock + async def test_create_mfa_challenge(self): data = { "$id": "bb8ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -450,19 +397,16 @@ def test_create_mfa_challenge(self, m): "expire": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.account.create_mfa_challenge( + response = await self.account.create_mfa_challenge( 'email', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_mfa_challenge(self, m): + @respx.mock + async def test_create_mfa_challenge(self): data = { "$id": "bb8ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -470,19 +414,16 @@ def test_create_mfa_challenge(self, m): "expire": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.account.create_mfa_challenge( + response = await self.account.create_mfa_challenge( 'email', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_mfa_challenge(self, m): + @respx.mock + async def test_update_mfa_challenge(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -515,20 +456,17 @@ def test_update_mfa_challenge(self, m): "mfaUpdatedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.account.update_mfa_challenge( + response = await self.account.update_mfa_challenge( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_mfa_challenge(self, m): + @respx.mock + async def test_update_mfa_challenge(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -561,20 +499,17 @@ def test_update_mfa_challenge(self, m): "mfaUpdatedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.account.update_mfa_challenge( + response = await self.account.update_mfa_challenge( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_list_mfa_factors(self, m): + @respx.mock + async def test_list_mfa_factors(self): data = { "totp": True, "phone": True, @@ -583,17 +518,14 @@ def test_list_mfa_factors(self, m): "custom": True, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.account.list_mfa_factors() + response = await self.account.list_mfa_factors() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_list_mfa_factors(self, m): + @respx.mock + async def test_list_mfa_factors(self): data = { "totp": True, "phone": True, @@ -602,107 +534,86 @@ def test_list_mfa_factors(self, m): "custom": True, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.account.list_mfa_factors() + response = await self.account.list_mfa_factors() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_mfa_recovery_codes(self, m): + @respx.mock + async def test_get_mfa_recovery_codes(self): data = { "recoveryCodes": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.account.get_mfa_recovery_codes() + response = await self.account.get_mfa_recovery_codes() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_mfa_recovery_codes(self, m): + @respx.mock + async def test_get_mfa_recovery_codes(self): data = { "recoveryCodes": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.account.get_mfa_recovery_codes() + response = await self.account.get_mfa_recovery_codes() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_mfa_recovery_codes(self, m): + @respx.mock + async def test_create_mfa_recovery_codes(self): data = { "recoveryCodes": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.account.create_mfa_recovery_codes() + response = await self.account.create_mfa_recovery_codes() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_mfa_recovery_codes(self, m): + @respx.mock + async def test_create_mfa_recovery_codes(self): data = { "recoveryCodes": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.account.create_mfa_recovery_codes() + response = await self.account.create_mfa_recovery_codes() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_mfa_recovery_codes(self, m): + @respx.mock + async def test_update_mfa_recovery_codes(self): data = { "recoveryCodes": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.account.update_mfa_recovery_codes() + response = await self.account.update_mfa_recovery_codes() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_mfa_recovery_codes(self, m): + @respx.mock + async def test_update_mfa_recovery_codes(self): data = { "recoveryCodes": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.account.update_mfa_recovery_codes() + response = await self.account.update_mfa_recovery_codes() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_name(self, m): + @respx.mock + async def test_update_name(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -722,35 +633,29 @@ def test_update_name(self, m): "accessedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.account.update_name( + response = await self.account.update_name( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_list_passkeys(self, m): + @respx.mock + async def test_list_passkeys(self): data = { "total": 5.0, "passkeys": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.account.list_passkeys() + response = await self.account.list_passkeys() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_passkey(self, m): + @respx.mock + async def test_create_passkey(self): data = { "$id": "bb8ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -759,17 +664,14 @@ def test_create_passkey(self, m): "publicKey": {}, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.account.create_passkey() + response = await self.account.create_passkey() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_passkey(self, m): + @respx.mock + async def test_get_passkey(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -778,19 +680,16 @@ def test_get_passkey(self, m): "accessedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.account.get_passkey( + response = await self.account.get_passkey( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_passkey(self, m): + @respx.mock + async def test_update_passkey(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -799,35 +698,29 @@ def test_update_passkey(self, m): "accessedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.account.update_passkey( + response = await self.account.update_passkey( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete_passkey(self, m): + @respx.mock + async def test_delete_passkey(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.account.delete_passkey( + response = await self.account.delete_passkey( '', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_update_passkey_verification(self, m): + @respx.mock + async def test_update_passkey_verification(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -836,20 +729,17 @@ def test_update_passkey_verification(self, m): "accessedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.account.update_passkey_verification( + response = await self.account.update_passkey_verification( '', {}, ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_password(self, m): + @respx.mock + async def test_update_password(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -869,19 +759,16 @@ def test_update_password(self, m): "accessedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.account.update_password( + response = await self.account.update_password( 'password', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_phone(self, m): + @respx.mock + async def test_update_phone(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -901,33 +788,27 @@ def test_update_phone(self, m): "accessedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.account.update_phone( + response = await self.account.update_phone( '+12065550100', 'password', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_prefs(self, m): + @respx.mock + async def test_get_prefs(self): data = {} headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.account.get_prefs() + response = await self.account.get_prefs() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_prefs(self, m): + @respx.mock + async def test_update_prefs(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -947,19 +828,16 @@ def test_update_prefs(self, m): "accessedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.account.update_prefs( + response = await self.account.update_prefs( {}, ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_recovery(self, m): + @respx.mock + async def test_create_recovery(self): data = { "$id": "bb8ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -969,20 +847,17 @@ def test_create_recovery(self, m): "phrase": "Golden Fox", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.account.create_recovery( + response = await self.account.create_recovery( 'email@example.com', 'https://example.com', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_recovery(self, m): + @respx.mock + async def test_update_recovery(self): data = { "$id": "bb8ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -992,21 +867,18 @@ def test_update_recovery(self, m): "phrase": "Golden Fox", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.account.update_recovery( + response = await self.account.update_recovery( '', '', 'password', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_recovery_otp(self, m): + @respx.mock + async def test_create_recovery_otp(self): data = { "$id": "bb8ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -1016,19 +888,16 @@ def test_create_recovery_otp(self, m): "phrase": "Golden Fox", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.account.create_recovery_otp( + response = await self.account.create_recovery_otp( 'email@example.com', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_recovery_otp(self, m): + @respx.mock + async def test_update_recovery_otp(self): data = { "$id": "bb8ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -1038,50 +907,41 @@ def test_update_recovery_otp(self, m): "phrase": "Golden Fox", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.account.update_recovery_otp( + response = await self.account.update_recovery_otp( '', '', 'password', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_list_sessions(self, m): + @respx.mock + async def test_list_sessions(self): data = { "total": 5.0, "sessions": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.account.list_sessions() + response = await self.account.list_sessions() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete_sessions(self, m): + @respx.mock + async def test_delete_sessions(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.account.delete_sessions() + response = await self.account.delete_sessions() self.assertEqual(response, data) - @requests_mock.Mocker() - def test_create_anonymous_session(self, m): + @respx.mock + async def test_create_anonymous_session(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -1114,17 +974,14 @@ def test_create_anonymous_session(self, m): "mfaUpdatedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.account.create_anonymous_session() + response = await self.account.create_anonymous_session() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_email_password_session(self, m): + @respx.mock + async def test_create_email_password_session(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -1157,20 +1014,17 @@ def test_create_email_password_session(self, m): "mfaUpdatedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.account.create_email_password_session( + response = await self.account.create_email_password_session( 'email@example.com', 'password', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_id_token_session(self, m): + @respx.mock + async def test_create_id_token_session(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -1203,20 +1057,17 @@ def test_create_id_token_session(self, m): "mfaUpdatedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.account.create_id_token_session( + response = await self.account.create_id_token_session( 'apple', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_magic_url_session(self, m): + @respx.mock + async def test_update_magic_url_session(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -1249,20 +1100,17 @@ def test_update_magic_url_session(self, m): "mfaUpdatedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.account.update_magic_url_session( + response = await self.account.update_magic_url_session( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_phone_session(self, m): + @respx.mock + async def test_update_phone_session(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -1295,20 +1143,17 @@ def test_update_phone_session(self, m): "mfaUpdatedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.account.update_phone_session( + response = await self.account.update_phone_session( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_session(self, m): + @respx.mock + async def test_create_session(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -1341,20 +1186,17 @@ def test_create_session(self, m): "mfaUpdatedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.account.create_session( + response = await self.account.create_session( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_session(self, m): + @respx.mock + async def test_get_session(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -1387,19 +1229,16 @@ def test_get_session(self, m): "mfaUpdatedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.account.get_session( + response = await self.account.get_session( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_session(self, m): + @respx.mock + async def test_update_session(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -1432,34 +1271,28 @@ def test_update_session(self, m): "mfaUpdatedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.account.update_session( + response = await self.account.update_session( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete_session(self, m): + @respx.mock + async def test_delete_session(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.account.delete_session( + response = await self.account.delete_session( '', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_update_status(self, m): + @respx.mock + async def test_update_status(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -1479,17 +1312,14 @@ def test_update_status(self, m): "accessedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.account.update_status() + response = await self.account.update_status() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_email_token(self, m): + @respx.mock + async def test_create_email_token(self): data = { "$id": "bb8ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -1499,20 +1329,17 @@ def test_create_email_token(self, m): "phrase": "Golden Fox", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.account.create_email_token( + response = await self.account.create_email_token( '', 'email@example.com', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_magic_url_token(self, m): + @respx.mock + async def test_create_magic_url_token(self): data = { "$id": "bb8ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -1522,35 +1349,29 @@ def test_create_magic_url_token(self, m): "phrase": "Golden Fox", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.account.create_magic_url_token( + response = await self.account.create_magic_url_token( '', 'email@example.com', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_o_auth2_token(self, m): + @respx.mock + async def test_create_o_auth2_token(self): data = None headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.account.create_o_auth2_token( + response = await self.account.create_o_auth2_token( 'amazon', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_create_passkey_token(self, m): + @respx.mock + async def test_create_passkey_token(self): data = { "$id": "bb8ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -1559,17 +1380,14 @@ def test_create_passkey_token(self, m): "publicKey": {}, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.account.create_passkey_token() + response = await self.account.create_passkey_token() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_passkey_token(self, m): + @respx.mock + async def test_update_passkey_token(self): data = { "$id": "bb8ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -1579,20 +1397,17 @@ def test_update_passkey_token(self, m): "phrase": "Golden Fox", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.account.update_passkey_token( + response = await self.account.update_passkey_token( '', {}, ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_phone_token(self, m): + @respx.mock + async def test_create_phone_token(self): data = { "$id": "bb8ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -1602,20 +1417,17 @@ def test_create_phone_token(self, m): "phrase": "Golden Fox", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.account.create_phone_token( + response = await self.account.create_phone_token( '', '+12065550100', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_email_verification(self, m): + @respx.mock + async def test_create_email_verification(self): data = { "$id": "bb8ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -1625,19 +1437,16 @@ def test_create_email_verification(self, m): "phrase": "Golden Fox", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.account.create_email_verification( + response = await self.account.create_email_verification( 'https://example.com', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_verification(self, m): + @respx.mock + async def test_create_verification(self): data = { "$id": "bb8ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -1647,19 +1456,16 @@ def test_create_verification(self, m): "phrase": "Golden Fox", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.account.create_verification( + response = await self.account.create_verification( 'https://example.com', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_email_verification(self, m): + @respx.mock + async def test_update_email_verification(self): data = { "$id": "bb8ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -1669,20 +1475,17 @@ def test_update_email_verification(self, m): "phrase": "Golden Fox", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.account.update_email_verification( + response = await self.account.update_email_verification( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_verification(self, m): + @respx.mock + async def test_update_verification(self): data = { "$id": "bb8ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -1692,20 +1495,17 @@ def test_update_verification(self, m): "phrase": "Golden Fox", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.account.update_verification( + response = await self.account.update_verification( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_email_verification_otp(self, m): + @respx.mock + async def test_create_email_verification_otp(self): data = { "$id": "bb8ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -1715,17 +1515,14 @@ def test_create_email_verification_otp(self, m): "phrase": "Golden Fox", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.account.create_email_verification_otp() + response = await self.account.create_email_verification_otp() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_email_verification_otp(self, m): + @respx.mock + async def test_update_email_verification_otp(self): data = { "$id": "bb8ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -1735,20 +1532,17 @@ def test_update_email_verification_otp(self, m): "phrase": "Golden Fox", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.account.update_email_verification_otp( + response = await self.account.update_email_verification_otp( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_phone_verification(self, m): + @respx.mock + async def test_create_phone_verification(self): data = { "$id": "bb8ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -1758,17 +1552,14 @@ def test_create_phone_verification(self, m): "phrase": "Golden Fox", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.account.create_phone_verification() + response = await self.account.create_phone_verification() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_phone_verification(self, m): + @respx.mock + async def test_update_phone_verification(self): data = { "$id": "bb8ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -1778,13 +1569,10 @@ def test_update_phone_verification(self, m): "phrase": "Golden Fox", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.account.update_phone_verification( + response = await self.account.update_phone_verification( '', '', ) diff --git a/test/services/test_activities.py b/test/services/test_activities.py index d9d1e662..074ad5dd 100644 --- a/test/services/test_activities.py +++ b/test/services/test_activities.py @@ -1,5 +1,6 @@ import json -import requests_mock +import httpx2 +import respx import unittest from appwrite.client import Client @@ -8,30 +9,30 @@ from appwrite.services.activities import Activities -class ActivitiesServiceTest(unittest.TestCase): +class ActivitiesServiceTest(unittest.IsolatedAsyncioTestCase): - def setUp(self): + async def asyncSetUp(self): self.client = Client() self.activities = Activities(self.client) - @requests_mock.Mocker() - def test_list_events(self, m): + async def asyncTearDown(self): + await self.client.aclose() + + @respx.mock + async def test_list_events(self): data = { "total": 5.0, "events": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.activities.list_events() + response = await self.activities.list_events() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_event(self, m): + @respx.mock + async def test_get_event(self): data = { "$id": "5e5ea5c16897e", "actorType": "user", @@ -64,13 +65,10 @@ def test_get_event(self, m): "sdkVersion": "14.0.0", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.activities.get_event( + response = await self.activities.get_event( '', ) self.assertEqual(response.to_dict(), data) diff --git a/test/services/test_advisor.py b/test/services/test_advisor.py index 74d8eb1d..63c1e880 100644 --- a/test/services/test_advisor.py +++ b/test/services/test_advisor.py @@ -1,5 +1,6 @@ import json -import requests_mock +import httpx2 +import respx import unittest from appwrite.client import Client @@ -8,30 +9,30 @@ from appwrite.services.advisor import Advisor -class AdvisorServiceTest(unittest.TestCase): +class AdvisorServiceTest(unittest.IsolatedAsyncioTestCase): - def setUp(self): + async def asyncSetUp(self): self.client = Client() self.advisor = Advisor(self.client) - @requests_mock.Mocker() - def test_list_reports(self, m): + async def asyncTearDown(self): + await self.client.aclose() + + @respx.mock + async def test_list_reports(self): data = { "total": 5.0, "reports": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.advisor.list_reports() + response = await self.advisor.list_reports() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_report(self, m): + @respx.mock + async def test_get_report(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -46,52 +47,43 @@ def test_get_report(self, m): "insights": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.advisor.get_report( + response = await self.advisor.get_report( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete_report(self, m): + @respx.mock + async def test_delete_report(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.advisor.delete_report( + response = await self.advisor.delete_report( '', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_list_insights(self, m): + @respx.mock + async def test_list_insights(self): data = { "total": 5.0, "insights": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.advisor.list_insights( + response = await self.advisor.list_insights( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_insight(self, m): + @respx.mock + async def test_get_insight(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -109,13 +101,10 @@ def test_get_insight(self, m): "ctas": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.advisor.get_insight( + response = await self.advisor.get_insight( '', '', ) diff --git a/test/services/test_apps.py b/test/services/test_apps.py index 0e6c2628..97da3d21 100644 --- a/test/services/test_apps.py +++ b/test/services/test_apps.py @@ -1,5 +1,6 @@ import json -import requests_mock +import httpx2 +import respx import unittest from appwrite.client import Client @@ -8,30 +9,30 @@ from appwrite.services.apps import Apps -class AppsServiceTest(unittest.TestCase): +class AppsServiceTest(unittest.IsolatedAsyncioTestCase): - def setUp(self): + async def asyncSetUp(self): self.client = Client() self.apps = Apps(self.client) - @requests_mock.Mocker() - def test_list(self, m): + async def asyncTearDown(self): + await self.client.aclose() + + @respx.mock + async def test_list(self): data = { "total": 5.0, "apps": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.apps.list() + response = await self.apps.list() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create(self, m): + @respx.mock + async def test_create(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -61,53 +62,44 @@ def test_create(self, m): "secrets": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.apps.create( + response = await self.apps.create( '', '', [], ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_list_installation_scopes(self, m): + @respx.mock + async def test_list_installation_scopes(self): data = { "total": 5.0, "scopes": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.apps.list_installation_scopes() + response = await self.apps.list_installation_scopes() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_list_o_auth2_scopes(self, m): + @respx.mock + async def test_list_o_auth2_scopes(self): data = { "total": 5.0, "scopes": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.apps.list_o_auth2_scopes() + response = await self.apps.list_o_auth2_scopes() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get(self, m): + @respx.mock + async def test_get(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -137,19 +129,16 @@ def test_get(self, m): "secrets": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.apps.get( + response = await self.apps.get( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update(self, m): + @respx.mock + async def test_update(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -179,53 +168,44 @@ def test_update(self, m): "secrets": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.apps.update( + response = await self.apps.update( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete(self, m): + @respx.mock + async def test_delete(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.apps.delete( + response = await self.apps.delete( '', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_list_installations(self, m): + @respx.mock + async def test_list_installations(self): data = { "total": 5.0, "installations": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.apps.list_installations( + response = await self.apps.list_installations( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_installation(self, m): + @respx.mock + async def test_get_installation(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -238,36 +218,30 @@ def test_get_installation(self, m): "createdByName": "Walter White", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.apps.get_installation( + response = await self.apps.get_installation( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete_installation(self, m): + @respx.mock + async def test_delete_installation(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.apps.delete_installation( + response = await self.apps.delete_installation( '', '', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_create_installation_token(self, m): + @respx.mock + async def test_create_installation_token(self): data = { "access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9...", "token_type": "Bearer", @@ -276,38 +250,32 @@ def test_create_installation_token(self, m): "scope": "openid email profile", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.apps.create_installation_token( + response = await self.apps.create_installation_token( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_list_keys(self, m): + @respx.mock + async def test_list_keys(self): data = { "total": 5.0, "keys": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.apps.list_keys( + response = await self.apps.list_keys( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_key(self, m): + @respx.mock + async def test_create_key(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -319,19 +287,16 @@ def test_create_key(self, m): "createdByName": "Walter White", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.apps.create_key( + response = await self.apps.create_key( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_key(self, m): + @respx.mock + async def test_get_key(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -343,36 +308,30 @@ def test_get_key(self, m): "createdByName": "Walter White", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.apps.get_key( + response = await self.apps.get_key( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete_key(self, m): + @respx.mock + async def test_delete_key(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.apps.delete_key( + response = await self.apps.delete_key( '', '', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_update_labels(self, m): + @respx.mock + async def test_update_labels(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -402,38 +361,32 @@ def test_update_labels(self, m): "secrets": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.apps.update_labels( + response = await self.apps.update_labels( '', [], ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_list_secrets(self, m): + @respx.mock + async def test_list_secrets(self): data = { "total": 5.0, "secrets": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.apps.list_secrets( + response = await self.apps.list_secrets( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_secret(self, m): + @respx.mock + async def test_create_secret(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -445,19 +398,16 @@ def test_create_secret(self, m): "createdByName": "Walter White", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.apps.create_secret( + response = await self.apps.create_secret( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_secret(self, m): + @respx.mock + async def test_get_secret(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -469,36 +419,30 @@ def test_get_secret(self, m): "createdByName": "Walter White", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.apps.get_secret( + response = await self.apps.get_secret( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete_secret(self, m): + @respx.mock + async def test_delete_secret(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.apps.delete_secret( + response = await self.apps.delete_secret( '', '', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_update_team(self, m): + @respx.mock + async def test_update_team(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -528,29 +472,23 @@ def test_update_team(self, m): "secrets": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.apps.update_team( + response = await self.apps.update_team( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete_tokens(self, m): + @respx.mock + async def test_delete_tokens(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.apps.delete_tokens( + response = await self.apps.delete_tokens( '', ) self.assertEqual(response, data) diff --git a/test/services/test_avatars.py b/test/services/test_avatars.py index c54fe183..fc584443 100644 --- a/test/services/test_avatars.py +++ b/test/services/test_avatars.py @@ -1,5 +1,6 @@ import json -import requests_mock +import httpx2 +import respx import unittest from appwrite.client import Client @@ -8,115 +9,97 @@ from appwrite.services.avatars import Avatars -class AvatarsServiceTest(unittest.TestCase): +class AvatarsServiceTest(unittest.IsolatedAsyncioTestCase): - def setUp(self): + async def asyncSetUp(self): self.client = Client() self.avatars = Avatars(self.client) - @requests_mock.Mocker() - def test_get_browser(self, m): + async def asyncTearDown(self): + await self.client.aclose() + + @respx.mock + async def test_get_browser(self): data = bytearray() headers = {'Content-Type': 'application/octet-stream'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - body=data, - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, content=bytes(data), headers=headers), ) - response = self.avatars.get_browser( + response = await self.avatars.get_browser( 'aa', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_get_credit_card(self, m): + @respx.mock + async def test_get_credit_card(self): data = bytearray() headers = {'Content-Type': 'application/octet-stream'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - body=data, - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, content=bytes(data), headers=headers), ) - response = self.avatars.get_credit_card( + response = await self.avatars.get_credit_card( 'amex', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_get_favicon(self, m): + @respx.mock + async def test_get_favicon(self): data = bytearray() headers = {'Content-Type': 'application/octet-stream'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - body=data, - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, content=bytes(data), headers=headers), ) - response = self.avatars.get_favicon( + response = await self.avatars.get_favicon( 'https://example.com', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_get_flag(self, m): + @respx.mock + async def test_get_flag(self): data = bytearray() headers = {'Content-Type': 'application/octet-stream'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - body=data, - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, content=bytes(data), headers=headers), ) - response = self.avatars.get_flag( + response = await self.avatars.get_flag( 'af', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_get_image(self, m): + @respx.mock + async def test_get_image(self): data = bytearray() headers = {'Content-Type': 'application/octet-stream'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - body=data, - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, content=bytes(data), headers=headers), ) - response = self.avatars.get_image( + response = await self.avatars.get_image( 'https://example.com', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_get_initials(self, m): + @respx.mock + async def test_get_initials(self): data = bytearray() headers = {'Content-Type': 'application/octet-stream'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - body=data, - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, content=bytes(data), headers=headers), ) - response = self.avatars.get_initials() + response = await self.avatars.get_initials() self.assertEqual(response, data) - @requests_mock.Mocker() - def test_get_photo(self, m): + @respx.mock + async def test_get_photo(self): data = bytearray() headers = {'Content-Type': 'application/octet-stream'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - body=data, - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, content=bytes(data), headers=headers), ) - response = self.avatars.get_photo() + response = await self.avatars.get_photo() self.assertEqual(response, data) - @requests_mock.Mocker() - def test_update_photo(self, m): + @respx.mock + async def test_update_photo(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -136,56 +119,44 @@ def test_update_photo(self, m): "accessedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.avatars.update_photo( + response = await self.avatars.update_photo( InputFile.from_bytes(bytearray(), "example.file"), ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete_photo(self, m): + @respx.mock + async def test_delete_photo(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.avatars.delete_photo() + response = await self.avatars.delete_photo() self.assertEqual(response, data) - @requests_mock.Mocker() - def test_get_qr(self, m): + @respx.mock + async def test_get_qr(self): data = bytearray() headers = {'Content-Type': 'application/octet-stream'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - body=data, - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, content=bytes(data), headers=headers), ) - response = self.avatars.get_qr( + response = await self.avatars.get_qr( '', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_get_screenshot(self, m): + @respx.mock + async def test_get_screenshot(self): data = bytearray() headers = {'Content-Type': 'application/octet-stream'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - body=data, - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, content=bytes(data), headers=headers), ) - response = self.avatars.get_screenshot( + response = await self.avatars.get_screenshot( 'https://example.com', ) self.assertEqual(response, data) diff --git a/test/services/test_backups.py b/test/services/test_backups.py index 175b3515..d92fae6c 100644 --- a/test/services/test_backups.py +++ b/test/services/test_backups.py @@ -1,5 +1,6 @@ import json -import requests_mock +import httpx2 +import respx import unittest from appwrite.client import Client @@ -8,30 +9,30 @@ from appwrite.services.backups import Backups -class BackupsServiceTest(unittest.TestCase): +class BackupsServiceTest(unittest.IsolatedAsyncioTestCase): - def setUp(self): + async def asyncSetUp(self): self.client = Client() self.backups = Backups(self.client) - @requests_mock.Mocker() - def test_list_archives(self, m): + async def asyncTearDown(self): + await self.client.aclose() + + @respx.mock + async def test_list_archives(self): data = { "total": 5.0, "archives": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.backups.list_archives() + response = await self.backups.list_archives() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_archive(self, m): + @respx.mock + async def test_create_archive(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -43,19 +44,16 @@ def test_create_archive(self, m): "resources": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.backups.create_archive( + response = await self.backups.create_archive( [], ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_archive(self, m): + @respx.mock + async def test_get_archive(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -67,50 +65,41 @@ def test_get_archive(self, m): "resources": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.backups.get_archive( + response = await self.backups.get_archive( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete_archive(self, m): + @respx.mock + async def test_delete_archive(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.backups.delete_archive( + response = await self.backups.delete_archive( '', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_list_policies(self, m): + @respx.mock + async def test_list_policies(self): data = { "total": 5.0, "policies": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.backups.list_policies() + response = await self.backups.list_policies() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_policy(self, m): + @respx.mock + async def test_create_policy(self): data = { "$id": "5e5ea5c16897e", "name": "Hourly backups", @@ -124,13 +113,10 @@ def test_create_policy(self, m): "enabled": True, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.backups.create_policy( + response = await self.backups.create_policy( '', [], 1, @@ -138,8 +124,8 @@ def test_create_policy(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_policy(self, m): + @respx.mock + async def test_get_policy(self): data = { "$id": "5e5ea5c16897e", "name": "Hourly backups", @@ -153,19 +139,16 @@ def test_get_policy(self, m): "enabled": True, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.backups.get_policy( + response = await self.backups.get_policy( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_policy(self, m): + @respx.mock + async def test_update_policy(self): data = { "$id": "5e5ea5c16897e", "name": "Hourly backups", @@ -179,34 +162,28 @@ def test_update_policy(self, m): "enabled": True, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.backups.update_policy( + response = await self.backups.update_policy( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete_policy(self, m): + @respx.mock + async def test_delete_policy(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.backups.delete_policy( + response = await self.backups.delete_policy( '', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_create_restoration(self, m): + @respx.mock + async def test_create_restoration(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -220,36 +197,30 @@ def test_create_restoration(self, m): "options": {}, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.backups.create_restoration( + response = await self.backups.create_restoration( '', [], ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_list_restorations(self, m): + @respx.mock + async def test_list_restorations(self): data = { "total": 5.0, "restorations": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.backups.list_restorations() + response = await self.backups.list_restorations() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_restoration(self, m): + @respx.mock + async def test_get_restoration(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -263,13 +234,10 @@ def test_get_restoration(self, m): "options": {}, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.backups.get_restoration( + response = await self.backups.get_restoration( '', ) self.assertEqual(response.to_dict(), data) diff --git a/test/services/test_databases.py b/test/services/test_databases.py index 14d81297..6b52f20b 100644 --- a/test/services/test_databases.py +++ b/test/services/test_databases.py @@ -1,5 +1,6 @@ import json -import requests_mock +import httpx2 +import respx import unittest from appwrite.client import Client @@ -8,30 +9,30 @@ from appwrite.services.databases import Databases -class DatabasesServiceTest(unittest.TestCase): +class DatabasesServiceTest(unittest.IsolatedAsyncioTestCase): - def setUp(self): + async def asyncSetUp(self): self.client = Client() self.databases = Databases(self.client) - @requests_mock.Mocker() - def test_list(self, m): + async def asyncTearDown(self): + await self.client.aclose() + + @respx.mock + async def test_list(self): data = { "total": 5.0, "databases": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.databases.list() + response = await self.databases.list() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create(self, m): + @respx.mock + async def test_create(self): data = { "$id": "5e5ea5c16897e", "name": "My Database", @@ -42,36 +43,30 @@ def test_create(self, m): "type": "legacy", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.databases.create( + response = await self.databases.create( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_list_transactions(self, m): + @respx.mock + async def test_list_transactions(self): data = { "total": 5.0, "transactions": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.databases.list_transactions() + response = await self.databases.list_transactions() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_transaction(self, m): + @respx.mock + async def test_create_transaction(self): data = { "$id": "259125845563242502", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -81,17 +76,14 @@ def test_create_transaction(self, m): "expiresAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.databases.create_transaction() + response = await self.databases.create_transaction() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_transaction(self, m): + @respx.mock + async def test_get_transaction(self): data = { "$id": "259125845563242502", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -101,19 +93,16 @@ def test_get_transaction(self, m): "expiresAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.databases.get_transaction( + response = await self.databases.get_transaction( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_transaction(self, m): + @respx.mock + async def test_update_transaction(self): data = { "$id": "259125845563242502", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -123,34 +112,28 @@ def test_update_transaction(self, m): "expiresAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.databases.update_transaction( + response = await self.databases.update_transaction( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete_transaction(self, m): + @respx.mock + async def test_delete_transaction(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.databases.delete_transaction( + response = await self.databases.delete_transaction( '', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_create_operations(self, m): + @respx.mock + async def test_create_operations(self): data = { "$id": "259125845563242502", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -160,19 +143,16 @@ def test_create_operations(self, m): "expiresAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.databases.create_operations( + response = await self.databases.create_operations( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get(self, m): + @respx.mock + async def test_get(self): data = { "$id": "5e5ea5c16897e", "name": "My Database", @@ -183,19 +163,16 @@ def test_get(self, m): "type": "legacy", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.databases.get( + response = await self.databases.get( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update(self, m): + @respx.mock + async def test_update(self): data = { "$id": "5e5ea5c16897e", "name": "My Database", @@ -206,52 +183,43 @@ def test_update(self, m): "type": "legacy", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.databases.update( + response = await self.databases.update( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete(self, m): + @respx.mock + async def test_delete(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.databases.delete( + response = await self.databases.delete( '', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_list_collections(self, m): + @respx.mock + async def test_list_collections(self): data = { "total": 5.0, "collections": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.databases.list_collections( + response = await self.databases.list_collections( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_collection(self, m): + @respx.mock + async def test_create_collection(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -268,21 +236,18 @@ def test_create_collection(self, m): "bytesUsed": 1500.0, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.databases.create_collection( + response = await self.databases.create_collection( '', '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_collection(self, m): + @respx.mock + async def test_get_collection(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -299,20 +264,17 @@ def test_get_collection(self, m): "bytesUsed": 1500.0, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.databases.get_collection( + response = await self.databases.get_collection( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_collection(self, m): + @respx.mock + async def test_update_collection(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -329,55 +291,46 @@ def test_update_collection(self, m): "bytesUsed": 1500.0, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.databases.update_collection( + response = await self.databases.update_collection( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete_collection(self, m): + @respx.mock + async def test_delete_collection(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.databases.delete_collection( + response = await self.databases.delete_collection( '', '', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_list_attributes(self, m): + @respx.mock + async def test_list_attributes(self): data = { "total": 5.0, "attributes": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.databases.list_attributes( + response = await self.databases.list_attributes( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_big_int_attribute(self, m): + @respx.mock + async def test_create_big_int_attribute(self): data = { "key": "count", "description": "Name shown on the public profile.", @@ -389,13 +342,10 @@ def test_create_big_int_attribute(self, m): "$updatedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.databases.create_big_int_attribute( + response = await self.databases.create_big_int_attribute( '', '', '', @@ -403,8 +353,8 @@ def test_create_big_int_attribute(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_big_int_attribute(self, m): + @respx.mock + async def test_update_big_int_attribute(self): data = { "key": "count", "description": "Name shown on the public profile.", @@ -416,13 +366,10 @@ def test_update_big_int_attribute(self, m): "$updatedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.databases.update_big_int_attribute( + response = await self.databases.update_big_int_attribute( '', '', '', @@ -431,8 +378,8 @@ def test_update_big_int_attribute(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_boolean_attribute(self, m): + @respx.mock + async def test_create_boolean_attribute(self): data = { "key": "isEnabled", "description": "Name shown on the public profile.", @@ -444,13 +391,10 @@ def test_create_boolean_attribute(self, m): "$updatedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.databases.create_boolean_attribute( + response = await self.databases.create_boolean_attribute( '', '', '', @@ -458,8 +402,8 @@ def test_create_boolean_attribute(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_boolean_attribute(self, m): + @respx.mock + async def test_update_boolean_attribute(self): data = { "key": "isEnabled", "description": "Name shown on the public profile.", @@ -471,13 +415,10 @@ def test_update_boolean_attribute(self, m): "$updatedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.databases.update_boolean_attribute( + response = await self.databases.update_boolean_attribute( '', '', '', @@ -486,8 +427,8 @@ def test_update_boolean_attribute(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_datetime_attribute(self, m): + @respx.mock + async def test_create_datetime_attribute(self): data = { "key": "birthDay", "description": "Name shown on the public profile.", @@ -500,13 +441,10 @@ def test_create_datetime_attribute(self, m): "format": "datetime", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.databases.create_datetime_attribute( + response = await self.databases.create_datetime_attribute( '', '', '', @@ -514,8 +452,8 @@ def test_create_datetime_attribute(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_datetime_attribute(self, m): + @respx.mock + async def test_update_datetime_attribute(self): data = { "key": "birthDay", "description": "Name shown on the public profile.", @@ -528,13 +466,10 @@ def test_update_datetime_attribute(self, m): "format": "datetime", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.databases.update_datetime_attribute( + response = await self.databases.update_datetime_attribute( '', '', '', @@ -543,8 +478,8 @@ def test_update_datetime_attribute(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_email_attribute(self, m): + @respx.mock + async def test_create_email_attribute(self): data = { "key": "userEmail", "description": "Name shown on the public profile.", @@ -557,13 +492,10 @@ def test_create_email_attribute(self, m): "format": "email", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.databases.create_email_attribute( + response = await self.databases.create_email_attribute( '', '', '', @@ -571,8 +503,8 @@ def test_create_email_attribute(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_email_attribute(self, m): + @respx.mock + async def test_update_email_attribute(self): data = { "key": "userEmail", "description": "Name shown on the public profile.", @@ -585,13 +517,10 @@ def test_update_email_attribute(self, m): "format": "email", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.databases.update_email_attribute( + response = await self.databases.update_email_attribute( '', '', '', @@ -600,8 +529,8 @@ def test_update_email_attribute(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_enum_attribute(self, m): + @respx.mock + async def test_create_enum_attribute(self): data = { "key": "status", "description": "Name shown on the public profile.", @@ -615,13 +544,10 @@ def test_create_enum_attribute(self, m): "format": "enum", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.databases.create_enum_attribute( + response = await self.databases.create_enum_attribute( '', '', '', @@ -630,8 +556,8 @@ def test_create_enum_attribute(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_enum_attribute(self, m): + @respx.mock + async def test_update_enum_attribute(self): data = { "key": "status", "description": "Name shown on the public profile.", @@ -645,13 +571,10 @@ def test_update_enum_attribute(self, m): "format": "enum", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.databases.update_enum_attribute( + response = await self.databases.update_enum_attribute( '', '', '', @@ -661,8 +584,8 @@ def test_update_enum_attribute(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_float_attribute(self, m): + @respx.mock + async def test_create_float_attribute(self): data = { "key": "percentageCompleted", "description": "Name shown on the public profile.", @@ -674,13 +597,10 @@ def test_create_float_attribute(self, m): "$updatedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.databases.create_float_attribute( + response = await self.databases.create_float_attribute( '', '', '', @@ -688,8 +608,8 @@ def test_create_float_attribute(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_float_attribute(self, m): + @respx.mock + async def test_update_float_attribute(self): data = { "key": "percentageCompleted", "description": "Name shown on the public profile.", @@ -701,13 +621,10 @@ def test_update_float_attribute(self, m): "$updatedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.databases.update_float_attribute( + response = await self.databases.update_float_attribute( '', '', '', @@ -716,8 +633,8 @@ def test_update_float_attribute(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_integer_attribute(self, m): + @respx.mock + async def test_create_integer_attribute(self): data = { "key": "count", "description": "Name shown on the public profile.", @@ -729,13 +646,10 @@ def test_create_integer_attribute(self, m): "$updatedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.databases.create_integer_attribute( + response = await self.databases.create_integer_attribute( '', '', '', @@ -743,8 +657,8 @@ def test_create_integer_attribute(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_integer_attribute(self, m): + @respx.mock + async def test_update_integer_attribute(self): data = { "key": "count", "description": "Name shown on the public profile.", @@ -756,13 +670,10 @@ def test_update_integer_attribute(self, m): "$updatedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.databases.update_integer_attribute( + response = await self.databases.update_integer_attribute( '', '', '', @@ -771,8 +682,8 @@ def test_update_integer_attribute(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_ip_attribute(self, m): + @respx.mock + async def test_create_ip_attribute(self): data = { "key": "ipAddress", "description": "Name shown on the public profile.", @@ -785,13 +696,10 @@ def test_create_ip_attribute(self, m): "format": "ip", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.databases.create_ip_attribute( + response = await self.databases.create_ip_attribute( '', '', '', @@ -799,8 +707,8 @@ def test_create_ip_attribute(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_ip_attribute(self, m): + @respx.mock + async def test_update_ip_attribute(self): data = { "key": "ipAddress", "description": "Name shown on the public profile.", @@ -813,13 +721,10 @@ def test_update_ip_attribute(self, m): "format": "ip", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.databases.update_ip_attribute( + response = await self.databases.update_ip_attribute( '', '', '', @@ -828,8 +733,8 @@ def test_update_ip_attribute(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_line_attribute(self, m): + @respx.mock + async def test_create_line_attribute(self): data = { "key": "fullName", "description": "Name shown on the public profile.", @@ -841,13 +746,10 @@ def test_create_line_attribute(self, m): "$updatedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.databases.create_line_attribute( + response = await self.databases.create_line_attribute( '', '', '', @@ -855,8 +757,8 @@ def test_create_line_attribute(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_line_attribute(self, m): + @respx.mock + async def test_update_line_attribute(self): data = { "key": "fullName", "description": "Name shown on the public profile.", @@ -868,13 +770,10 @@ def test_update_line_attribute(self, m): "$updatedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.databases.update_line_attribute( + response = await self.databases.update_line_attribute( '', '', '', @@ -882,8 +781,8 @@ def test_update_line_attribute(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_longtext_attribute(self, m): + @respx.mock + async def test_create_longtext_attribute(self): data = { "key": "fullName", "description": "Name shown on the public profile.", @@ -895,13 +794,10 @@ def test_create_longtext_attribute(self, m): "$updatedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.databases.create_longtext_attribute( + response = await self.databases.create_longtext_attribute( '', '', '', @@ -909,8 +805,8 @@ def test_create_longtext_attribute(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_longtext_attribute(self, m): + @respx.mock + async def test_update_longtext_attribute(self): data = { "key": "fullName", "description": "Name shown on the public profile.", @@ -922,13 +818,10 @@ def test_update_longtext_attribute(self, m): "$updatedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.databases.update_longtext_attribute( + response = await self.databases.update_longtext_attribute( '', '', '', @@ -937,8 +830,8 @@ def test_update_longtext_attribute(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_mediumtext_attribute(self, m): + @respx.mock + async def test_create_mediumtext_attribute(self): data = { "key": "fullName", "description": "Name shown on the public profile.", @@ -950,13 +843,10 @@ def test_create_mediumtext_attribute(self, m): "$updatedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.databases.create_mediumtext_attribute( + response = await self.databases.create_mediumtext_attribute( '', '', '', @@ -964,8 +854,8 @@ def test_create_mediumtext_attribute(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_mediumtext_attribute(self, m): + @respx.mock + async def test_update_mediumtext_attribute(self): data = { "key": "fullName", "description": "Name shown on the public profile.", @@ -977,13 +867,10 @@ def test_update_mediumtext_attribute(self, m): "$updatedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.databases.update_mediumtext_attribute( + response = await self.databases.update_mediumtext_attribute( '', '', '', @@ -992,8 +879,8 @@ def test_update_mediumtext_attribute(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_point_attribute(self, m): + @respx.mock + async def test_create_point_attribute(self): data = { "key": "fullName", "description": "Name shown on the public profile.", @@ -1005,13 +892,10 @@ def test_create_point_attribute(self, m): "$updatedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.databases.create_point_attribute( + response = await self.databases.create_point_attribute( '', '', '', @@ -1019,8 +903,8 @@ def test_create_point_attribute(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_point_attribute(self, m): + @respx.mock + async def test_update_point_attribute(self): data = { "key": "fullName", "description": "Name shown on the public profile.", @@ -1032,13 +916,10 @@ def test_update_point_attribute(self, m): "$updatedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.databases.update_point_attribute( + response = await self.databases.update_point_attribute( '', '', '', @@ -1046,8 +927,8 @@ def test_update_point_attribute(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_polygon_attribute(self, m): + @respx.mock + async def test_create_polygon_attribute(self): data = { "key": "fullName", "description": "Name shown on the public profile.", @@ -1059,13 +940,10 @@ def test_create_polygon_attribute(self, m): "$updatedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.databases.create_polygon_attribute( + response = await self.databases.create_polygon_attribute( '', '', '', @@ -1073,8 +951,8 @@ def test_create_polygon_attribute(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_polygon_attribute(self, m): + @respx.mock + async def test_update_polygon_attribute(self): data = { "key": "fullName", "description": "Name shown on the public profile.", @@ -1086,13 +964,10 @@ def test_update_polygon_attribute(self, m): "$updatedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.databases.update_polygon_attribute( + response = await self.databases.update_polygon_attribute( '', '', '', @@ -1100,8 +975,8 @@ def test_update_polygon_attribute(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_relationship_attribute(self, m): + @respx.mock + async def test_create_relationship_attribute(self): data = { "key": "fullName", "description": "Name shown on the public profile.", @@ -1119,13 +994,10 @@ def test_create_relationship_attribute(self, m): "side": "parent|child", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.databases.create_relationship_attribute( + response = await self.databases.create_relationship_attribute( '', '', '', @@ -1133,8 +1005,8 @@ def test_create_relationship_attribute(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_relationship_attribute(self, m): + @respx.mock + async def test_update_relationship_attribute(self): data = { "key": "fullName", "description": "Name shown on the public profile.", @@ -1152,21 +1024,18 @@ def test_update_relationship_attribute(self, m): "side": "parent|child", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.databases.update_relationship_attribute( + response = await self.databases.update_relationship_attribute( '', '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_string_attribute(self, m): + @respx.mock + async def test_create_string_attribute(self): data = { "key": "fullName", "description": "Name shown on the public profile.", @@ -1179,13 +1048,10 @@ def test_create_string_attribute(self, m): "size": 128.0, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.databases.create_string_attribute( + response = await self.databases.create_string_attribute( '', '', '', @@ -1194,8 +1060,8 @@ def test_create_string_attribute(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_string_attribute(self, m): + @respx.mock + async def test_update_string_attribute(self): data = { "key": "fullName", "description": "Name shown on the public profile.", @@ -1208,13 +1074,10 @@ def test_update_string_attribute(self, m): "size": 128.0, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.databases.update_string_attribute( + response = await self.databases.update_string_attribute( '', '', '', @@ -1223,8 +1086,8 @@ def test_update_string_attribute(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_text_attribute(self, m): + @respx.mock + async def test_create_text_attribute(self): data = { "key": "fullName", "description": "Name shown on the public profile.", @@ -1236,13 +1099,10 @@ def test_create_text_attribute(self, m): "$updatedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.databases.create_text_attribute( + response = await self.databases.create_text_attribute( '', '', '', @@ -1250,8 +1110,8 @@ def test_create_text_attribute(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_text_attribute(self, m): + @respx.mock + async def test_update_text_attribute(self): data = { "key": "fullName", "description": "Name shown on the public profile.", @@ -1263,13 +1123,10 @@ def test_update_text_attribute(self, m): "$updatedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.databases.update_text_attribute( + response = await self.databases.update_text_attribute( '', '', '', @@ -1278,8 +1135,8 @@ def test_update_text_attribute(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_url_attribute(self, m): + @respx.mock + async def test_create_url_attribute(self): data = { "key": "githubUrl", "description": "Name shown on the public profile.", @@ -1292,13 +1149,10 @@ def test_create_url_attribute(self, m): "format": "url", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.databases.create_url_attribute( + response = await self.databases.create_url_attribute( '', '', '', @@ -1306,8 +1160,8 @@ def test_create_url_attribute(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_url_attribute(self, m): + @respx.mock + async def test_update_url_attribute(self): data = { "key": "githubUrl", "description": "Name shown on the public profile.", @@ -1320,13 +1174,10 @@ def test_update_url_attribute(self, m): "format": "url", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.databases.update_url_attribute( + response = await self.databases.update_url_attribute( '', '', '', @@ -1335,8 +1186,8 @@ def test_update_url_attribute(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_varchar_attribute(self, m): + @respx.mock + async def test_create_varchar_attribute(self): data = { "key": "fullName", "description": "Name shown on the public profile.", @@ -1349,13 +1200,10 @@ def test_create_varchar_attribute(self, m): "size": 128.0, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.databases.create_varchar_attribute( + response = await self.databases.create_varchar_attribute( '', '', '', @@ -1364,8 +1212,8 @@ def test_create_varchar_attribute(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_varchar_attribute(self, m): + @respx.mock + async def test_update_varchar_attribute(self): data = { "key": "fullName", "description": "Name shown on the public profile.", @@ -1378,13 +1226,10 @@ def test_update_varchar_attribute(self, m): "size": 128.0, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.databases.update_varchar_attribute( + response = await self.databases.update_varchar_attribute( '', '', '', @@ -1393,8 +1238,8 @@ def test_update_varchar_attribute(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_attribute(self, m): + @respx.mock + async def test_get_attribute(self): data = { "key": "isEnabled", "description": "Name shown on the public profile.", @@ -1406,57 +1251,48 @@ def test_get_attribute(self, m): "$updatedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.databases.get_attribute( + response = await self.databases.get_attribute( '', '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete_attribute(self, m): + @respx.mock + async def test_delete_attribute(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.databases.delete_attribute( + response = await self.databases.delete_attribute( '', '', '', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_list_documents(self, m): + @respx.mock + async def test_list_documents(self): data = { "total": 5.0, "documents": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.databases.list_documents( + response = await self.databases.list_documents( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_document(self, m): + @respx.mock + async def test_create_document(self): data = { "$id": "5e5ea5c16897e", "$sequence": "1", @@ -1467,13 +1303,10 @@ def test_create_document(self, m): "$permissions": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.databases.create_document( + response = await self.databases.create_document( '', '', '', @@ -1482,105 +1315,90 @@ def test_create_document(self, m): data['data'] = {} self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_documents(self, m): + @respx.mock + async def test_create_documents(self): data = { "total": 5.0, "documents": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.databases.create_documents( + response = await self.databases.create_documents( '', '', [], ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_upsert_documents(self, m): + @respx.mock + async def test_upsert_documents(self): data = { "total": 5.0, "documents": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.databases.upsert_documents( + response = await self.databases.upsert_documents( '', '', [], ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_documents(self, m): + @respx.mock + async def test_update_documents(self): data = { "total": 5.0, "documents": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.databases.update_documents( + response = await self.databases.update_documents( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete_documents(self, m): + @respx.mock + async def test_delete_documents(self): data = { "total": 5.0, "documents": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.databases.delete_documents( + response = await self.databases.delete_documents( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_query(self, m): + @respx.mock + async def test_create_query(self): data = { "total": 5.0, "documents": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.databases.create_query( + response = await self.databases.create_query( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_document(self, m): + @respx.mock + async def test_get_document(self): data = { "$id": "5e5ea5c16897e", "$sequence": "1", @@ -1591,13 +1409,10 @@ def test_get_document(self, m): "$permissions": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.databases.get_document( + response = await self.databases.get_document( '', '', '', @@ -1605,8 +1420,8 @@ def test_get_document(self, m): data['data'] = {} self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_upsert_document(self, m): + @respx.mock + async def test_upsert_document(self): data = { "$id": "5e5ea5c16897e", "$sequence": "1", @@ -1617,13 +1432,10 @@ def test_upsert_document(self, m): "$permissions": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.databases.upsert_document( + response = await self.databases.upsert_document( '', '', '', @@ -1631,8 +1443,8 @@ def test_upsert_document(self, m): data['data'] = {} self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_document(self, m): + @respx.mock + async def test_update_document(self): data = { "$id": "5e5ea5c16897e", "$sequence": "1", @@ -1643,13 +1455,10 @@ def test_update_document(self, m): "$permissions": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.databases.update_document( + response = await self.databases.update_document( '', '', '', @@ -1657,25 +1466,22 @@ def test_update_document(self, m): data['data'] = {} self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete_document(self, m): + @respx.mock + async def test_delete_document(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.databases.delete_document( + response = await self.databases.delete_document( '', '', '', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_decrement_document_attribute(self, m): + @respx.mock + async def test_decrement_document_attribute(self): data = { "$id": "5e5ea5c16897e", "$sequence": "1", @@ -1686,13 +1492,10 @@ def test_decrement_document_attribute(self, m): "$permissions": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.databases.decrement_document_attribute( + response = await self.databases.decrement_document_attribute( '', '', '', @@ -1701,8 +1504,8 @@ def test_decrement_document_attribute(self, m): data['data'] = {} self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_increment_document_attribute(self, m): + @respx.mock + async def test_increment_document_attribute(self): data = { "$id": "5e5ea5c16897e", "$sequence": "1", @@ -1713,13 +1516,10 @@ def test_increment_document_attribute(self, m): "$permissions": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.databases.increment_document_attribute( + response = await self.databases.increment_document_attribute( '', '', '', @@ -1728,27 +1528,24 @@ def test_increment_document_attribute(self, m): data['data'] = {} self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_list_indexes(self, m): + @respx.mock + async def test_list_indexes(self): data = { "total": 5.0, "indexes": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.databases.list_indexes( + response = await self.databases.list_indexes( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_index(self, m): + @respx.mock + async def test_create_index(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -1762,13 +1559,10 @@ def test_create_index(self, m): "lengths": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.databases.create_index( + response = await self.databases.create_index( '', '', '', @@ -1777,8 +1571,8 @@ def test_create_index(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_index(self, m): + @respx.mock + async def test_get_index(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -1792,30 +1586,24 @@ def test_get_index(self, m): "lengths": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.databases.get_index( + response = await self.databases.get_index( '', '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete_index(self, m): + @respx.mock + async def test_delete_index(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.databases.delete_index( + response = await self.databases.delete_index( '', '', '', diff --git a/test/services/test_documents_db.py b/test/services/test_documents_db.py index c9840596..5de96e4f 100644 --- a/test/services/test_documents_db.py +++ b/test/services/test_documents_db.py @@ -1,5 +1,6 @@ import json -import requests_mock +import httpx2 +import respx import unittest from appwrite.client import Client @@ -8,30 +9,30 @@ from appwrite.services.documents_db import DocumentsDB -class DocumentsDBServiceTest(unittest.TestCase): +class DocumentsDBServiceTest(unittest.IsolatedAsyncioTestCase): - def setUp(self): + async def asyncSetUp(self): self.client = Client() self.documents_db = DocumentsDB(self.client) - @requests_mock.Mocker() - def test_list(self, m): + async def asyncTearDown(self): + await self.client.aclose() + + @respx.mock + async def test_list(self): data = { "total": 5.0, "databases": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.documents_db.list() + response = await self.documents_db.list() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create(self, m): + @respx.mock + async def test_create(self): data = { "$id": "5e5ea5c16897e", "name": "My Database", @@ -42,52 +43,43 @@ def test_create(self, m): "type": "legacy", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.documents_db.create( + response = await self.documents_db.create( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_list_specifications(self, m): + @respx.mock + async def test_list_specifications(self): data = { "specifications": [], "total": 9.0, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.documents_db.list_specifications() + response = await self.documents_db.list_specifications() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_list_transactions(self, m): + @respx.mock + async def test_list_transactions(self): data = { "total": 5.0, "transactions": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.documents_db.list_transactions() + response = await self.documents_db.list_transactions() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_transaction(self, m): + @respx.mock + async def test_create_transaction(self): data = { "$id": "259125845563242502", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -97,17 +89,14 @@ def test_create_transaction(self, m): "expiresAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.documents_db.create_transaction() + response = await self.documents_db.create_transaction() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_transaction(self, m): + @respx.mock + async def test_get_transaction(self): data = { "$id": "259125845563242502", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -117,19 +106,16 @@ def test_get_transaction(self, m): "expiresAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.documents_db.get_transaction( + response = await self.documents_db.get_transaction( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_transaction(self, m): + @respx.mock + async def test_update_transaction(self): data = { "$id": "259125845563242502", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -139,34 +125,28 @@ def test_update_transaction(self, m): "expiresAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.documents_db.update_transaction( + response = await self.documents_db.update_transaction( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete_transaction(self, m): + @respx.mock + async def test_delete_transaction(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.documents_db.delete_transaction( + response = await self.documents_db.delete_transaction( '', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_create_operations(self, m): + @respx.mock + async def test_create_operations(self): data = { "$id": "259125845563242502", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -176,19 +156,16 @@ def test_create_operations(self, m): "expiresAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.documents_db.create_operations( + response = await self.documents_db.create_operations( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get(self, m): + @respx.mock + async def test_get(self): data = { "$id": "5e5ea5c16897e", "name": "My Database", @@ -199,19 +176,16 @@ def test_get(self, m): "type": "legacy", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.documents_db.get( + response = await self.documents_db.get( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update(self, m): + @respx.mock + async def test_update(self): data = { "$id": "5e5ea5c16897e", "name": "My Database", @@ -222,53 +196,44 @@ def test_update(self, m): "type": "legacy", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.documents_db.update( + response = await self.documents_db.update( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete(self, m): + @respx.mock + async def test_delete(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.documents_db.delete( + response = await self.documents_db.delete( '', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_list_collections(self, m): + @respx.mock + async def test_list_collections(self): data = { "total": 5.0, "collections": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.documents_db.list_collections( + response = await self.documents_db.list_collections( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_collection(self, m): + @respx.mock + async def test_create_collection(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -285,21 +250,18 @@ def test_create_collection(self, m): "bytesUsed": 1500.0, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.documents_db.create_collection( + response = await self.documents_db.create_collection( '', '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_collection(self, m): + @respx.mock + async def test_get_collection(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -316,20 +278,17 @@ def test_get_collection(self, m): "bytesUsed": 1500.0, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.documents_db.get_collection( + response = await self.documents_db.get_collection( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_collection(self, m): + @respx.mock + async def test_update_collection(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -346,56 +305,47 @@ def test_update_collection(self, m): "bytesUsed": 1500.0, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.documents_db.update_collection( + response = await self.documents_db.update_collection( '', '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete_collection(self, m): + @respx.mock + async def test_delete_collection(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.documents_db.delete_collection( + response = await self.documents_db.delete_collection( '', '', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_list_documents(self, m): + @respx.mock + async def test_list_documents(self): data = { "total": 5.0, "documents": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.documents_db.list_documents( + response = await self.documents_db.list_documents( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_document(self, m): + @respx.mock + async def test_create_document(self): data = { "$id": "5e5ea5c16897e", "$sequence": "1", @@ -406,13 +356,10 @@ def test_create_document(self, m): "$permissions": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.documents_db.create_document( + response = await self.documents_db.create_document( '', '', '', @@ -421,105 +368,90 @@ def test_create_document(self, m): data['data'] = {} self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_documents(self, m): + @respx.mock + async def test_create_documents(self): data = { "total": 5.0, "documents": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.documents_db.create_documents( + response = await self.documents_db.create_documents( '', '', [], ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_upsert_documents(self, m): + @respx.mock + async def test_upsert_documents(self): data = { "total": 5.0, "documents": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.documents_db.upsert_documents( + response = await self.documents_db.upsert_documents( '', '', [], ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_documents(self, m): + @respx.mock + async def test_update_documents(self): data = { "total": 5.0, "documents": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.documents_db.update_documents( + response = await self.documents_db.update_documents( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete_documents(self, m): + @respx.mock + async def test_delete_documents(self): data = { "total": 5.0, "documents": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.documents_db.delete_documents( + response = await self.documents_db.delete_documents( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_query(self, m): + @respx.mock + async def test_create_query(self): data = { "total": 5.0, "documents": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.documents_db.create_query( + response = await self.documents_db.create_query( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_document(self, m): + @respx.mock + async def test_get_document(self): data = { "$id": "5e5ea5c16897e", "$sequence": "1", @@ -530,13 +462,10 @@ def test_get_document(self, m): "$permissions": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.documents_db.get_document( + response = await self.documents_db.get_document( '', '', '', @@ -544,8 +473,8 @@ def test_get_document(self, m): data['data'] = {} self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_upsert_document(self, m): + @respx.mock + async def test_upsert_document(self): data = { "$id": "5e5ea5c16897e", "$sequence": "1", @@ -556,13 +485,10 @@ def test_upsert_document(self, m): "$permissions": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.documents_db.upsert_document( + response = await self.documents_db.upsert_document( '', '', '', @@ -570,8 +496,8 @@ def test_upsert_document(self, m): data['data'] = {} self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_document(self, m): + @respx.mock + async def test_update_document(self): data = { "$id": "5e5ea5c16897e", "$sequence": "1", @@ -582,13 +508,10 @@ def test_update_document(self, m): "$permissions": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.documents_db.update_document( + response = await self.documents_db.update_document( '', '', '', @@ -596,25 +519,22 @@ def test_update_document(self, m): data['data'] = {} self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete_document(self, m): + @respx.mock + async def test_delete_document(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.documents_db.delete_document( + response = await self.documents_db.delete_document( '', '', '', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_decrement_document_attribute(self, m): + @respx.mock + async def test_decrement_document_attribute(self): data = { "$id": "5e5ea5c16897e", "$sequence": "1", @@ -625,13 +545,10 @@ def test_decrement_document_attribute(self, m): "$permissions": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.documents_db.decrement_document_attribute( + response = await self.documents_db.decrement_document_attribute( '', '', '', @@ -640,8 +557,8 @@ def test_decrement_document_attribute(self, m): data['data'] = {} self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_increment_document_attribute(self, m): + @respx.mock + async def test_increment_document_attribute(self): data = { "$id": "5e5ea5c16897e", "$sequence": "1", @@ -652,13 +569,10 @@ def test_increment_document_attribute(self, m): "$permissions": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.documents_db.increment_document_attribute( + response = await self.documents_db.increment_document_attribute( '', '', '', @@ -667,27 +581,24 @@ def test_increment_document_attribute(self, m): data['data'] = {} self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_list_indexes(self, m): + @respx.mock + async def test_list_indexes(self): data = { "total": 5.0, "indexes": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.documents_db.list_indexes( + response = await self.documents_db.list_indexes( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_index(self, m): + @respx.mock + async def test_create_index(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -701,13 +612,10 @@ def test_create_index(self, m): "lengths": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.documents_db.create_index( + response = await self.documents_db.create_index( '', '', '', @@ -716,8 +624,8 @@ def test_create_index(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_index(self, m): + @respx.mock + async def test_get_index(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -731,38 +639,32 @@ def test_get_index(self, m): "lengths": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.documents_db.get_index( + response = await self.documents_db.get_index( '', '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete_index(self, m): + @respx.mock + async def test_delete_index(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.documents_db.delete_index( + response = await self.documents_db.delete_index( '', '', '', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_create_failover(self, m): + @respx.mock + async def test_create_failover(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -811,37 +713,31 @@ def test_create_failover(self, m): "error": "", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.documents_db.create_failover( + response = await self.documents_db.create_failover( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_list_operations(self, m): + @respx.mock + async def test_list_operations(self): data = { "total": 5.0, "operations": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.documents_db.list_operations( + response = await self.documents_db.list_operations( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_replicas(self, m): + @respx.mock + async def test_get_replicas(self): data = { "replicas": 2.0, "syncMode": "async", @@ -851,19 +747,16 @@ def test_get_replicas(self, m): "members": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.documents_db.get_replicas( + response = await self.documents_db.get_replicas( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_status(self, m): + @respx.mock + async def test_get_status(self): data = { "health": "healthy", "ready": True, @@ -878,13 +771,10 @@ def test_get_status(self, m): "volumes": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.documents_db.get_status( + response = await self.documents_db.get_status( '', ) self.assertEqual(response.to_dict(), data) diff --git a/test/services/test_domains.py b/test/services/test_domains.py index 8ae6d3c4..6eca1e2f 100644 --- a/test/services/test_domains.py +++ b/test/services/test_domains.py @@ -1,5 +1,6 @@ import json -import requests_mock +import httpx2 +import respx import unittest from appwrite.client import Client @@ -8,30 +9,30 @@ from appwrite.services.domains import Domains -class DomainsServiceTest(unittest.TestCase): +class DomainsServiceTest(unittest.IsolatedAsyncioTestCase): - def setUp(self): + async def asyncSetUp(self): self.client = Client() self.domains = Domains(self.client) - @requests_mock.Mocker() - def test_list(self, m): + async def asyncTearDown(self): + await self.client.aclose() + + @respx.mock + async def test_list(self): data = { "total": 5.0, "domains": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.domains.list() + response = await self.domains.list() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create(self, m): + @respx.mock + async def test_create(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -47,20 +48,17 @@ def test_create(self, m): "dnsRecords": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.domains.create( + response = await self.domains.create( '', 'example.com', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_price(self, m): + @respx.mock + async def test_get_price(self): data = { "domain": "example.com", "tld": "com", @@ -70,37 +68,31 @@ def test_get_price(self, m): "renewalPeriodYears": 1.0, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.domains.get_price( + response = await self.domains.get_price( 'example.com', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_list_prices(self, m): + @respx.mock + async def test_list_prices(self): data = { "total": 5.0, "prices": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.domains.list_prices( + response = await self.domains.list_prices( [], ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get(self, m): + @respx.mock + async def test_get(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -116,34 +108,28 @@ def test_get(self, m): "dnsRecords": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.domains.get( + response = await self.domains.get( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete(self, m): + @respx.mock + async def test_delete(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.domains.delete( + response = await self.domains.delete( '', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_update_nameservers(self, m): + @respx.mock + async def test_update_nameservers(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -159,19 +145,16 @@ def test_update_nameservers(self, m): "dnsRecords": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.domains.update_nameservers( + response = await self.domains.update_nameservers( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_verify_nameservers(self, m): + @respx.mock + async def test_verify_nameservers(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -187,253 +170,211 @@ def test_verify_nameservers(self, m): "dnsRecords": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.domains.verify_nameservers( + response = await self.domains.verify_nameservers( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_preset_google_workspace(self, m): + @respx.mock + async def test_get_preset_google_workspace(self): data = { "total": 5.0, "dnsRecords": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.domains.get_preset_google_workspace( + response = await self.domains.get_preset_google_workspace( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_preset_google_workspace(self, m): + @respx.mock + async def test_create_preset_google_workspace(self): data = { "total": 5.0, "dnsRecords": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.domains.create_preset_google_workspace( + response = await self.domains.create_preset_google_workspace( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_preset_i_cloud(self, m): + @respx.mock + async def test_get_preset_i_cloud(self): data = { "total": 5.0, "dnsRecords": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.domains.get_preset_i_cloud( + response = await self.domains.get_preset_i_cloud( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_preset_i_cloud(self, m): + @respx.mock + async def test_create_preset_i_cloud(self): data = { "total": 5.0, "dnsRecords": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.domains.create_preset_i_cloud( + response = await self.domains.create_preset_i_cloud( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_preset_mailgun(self, m): + @respx.mock + async def test_get_preset_mailgun(self): data = { "total": 5.0, "dnsRecords": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.domains.get_preset_mailgun( + response = await self.domains.get_preset_mailgun( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_preset_mailgun(self, m): + @respx.mock + async def test_create_preset_mailgun(self): data = { "total": 5.0, "dnsRecords": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.domains.create_preset_mailgun( + response = await self.domains.create_preset_mailgun( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_preset_outlook(self, m): + @respx.mock + async def test_get_preset_outlook(self): data = { "total": 5.0, "dnsRecords": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.domains.get_preset_outlook( + response = await self.domains.get_preset_outlook( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_preset_outlook(self, m): + @respx.mock + async def test_create_preset_outlook(self): data = { "total": 5.0, "dnsRecords": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.domains.create_preset_outlook( + response = await self.domains.create_preset_outlook( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_preset_proton_mail(self, m): + @respx.mock + async def test_get_preset_proton_mail(self): data = { "total": 5.0, "dnsRecords": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.domains.get_preset_proton_mail( + response = await self.domains.get_preset_proton_mail( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_preset_proton_mail(self, m): + @respx.mock + async def test_create_preset_proton_mail(self): data = { "total": 5.0, "dnsRecords": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.domains.create_preset_proton_mail( + response = await self.domains.create_preset_proton_mail( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_preset_zoho(self, m): + @respx.mock + async def test_get_preset_zoho(self): data = { "total": 5.0, "dnsRecords": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.domains.get_preset_zoho( + response = await self.domains.get_preset_zoho( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_preset_zoho(self, m): + @respx.mock + async def test_create_preset_zoho(self): data = { "total": 5.0, "dnsRecords": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.domains.create_preset_zoho( + response = await self.domains.create_preset_zoho( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_list_records(self, m): + @respx.mock + async def test_list_records(self): data = { "total": 5.0, "dnsRecords": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.domains.list_records( + response = await self.domains.list_records( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_record_a(self, m): + @respx.mock + async def test_create_record_a(self): data = { "$id": "5f40a6e10c65e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -449,13 +390,10 @@ def test_create_record_a(self, m): "comment": "Mail server record", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.domains.create_record_a( + response = await self.domains.create_record_a( '', 'name', 'value', @@ -463,8 +401,8 @@ def test_create_record_a(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_record_a(self, m): + @respx.mock + async def test_update_record_a(self): data = { "$id": "5f40a6e10c65e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -480,13 +418,10 @@ def test_update_record_a(self, m): "comment": "Mail server record", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.domains.update_record_a( + response = await self.domains.update_record_a( '', '', 'name', @@ -495,8 +430,8 @@ def test_update_record_a(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_record_aaaa(self, m): + @respx.mock + async def test_create_record_aaaa(self): data = { "$id": "5f40a6e10c65e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -512,13 +447,10 @@ def test_create_record_aaaa(self, m): "comment": "Mail server record", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.domains.create_record_aaaa( + response = await self.domains.create_record_aaaa( '', 'name', 'value', @@ -526,8 +458,8 @@ def test_create_record_aaaa(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_record_aaaa(self, m): + @respx.mock + async def test_update_record_aaaa(self): data = { "$id": "5f40a6e10c65e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -543,13 +475,10 @@ def test_update_record_aaaa(self, m): "comment": "Mail server record", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.domains.update_record_aaaa( + response = await self.domains.update_record_aaaa( '', '', 'name', @@ -558,8 +487,8 @@ def test_update_record_aaaa(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_record_alias(self, m): + @respx.mock + async def test_create_record_alias(self): data = { "$id": "5f40a6e10c65e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -575,13 +504,10 @@ def test_create_record_alias(self, m): "comment": "Mail server record", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.domains.create_record_alias( + response = await self.domains.create_record_alias( '', 'name', '', @@ -589,8 +515,8 @@ def test_create_record_alias(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_record_alias(self, m): + @respx.mock + async def test_update_record_alias(self): data = { "$id": "5f40a6e10c65e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -606,13 +532,10 @@ def test_update_record_alias(self, m): "comment": "Mail server record", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.domains.update_record_alias( + response = await self.domains.update_record_alias( '', '', 'name', @@ -621,8 +544,8 @@ def test_update_record_alias(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_record_caa(self, m): + @respx.mock + async def test_create_record_caa(self): data = { "$id": "5f40a6e10c65e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -638,13 +561,10 @@ def test_create_record_caa(self, m): "comment": "Mail server record", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.domains.create_record_caa( + response = await self.domains.create_record_caa( '', 'name', 'value', @@ -652,8 +572,8 @@ def test_create_record_caa(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_record_caa(self, m): + @respx.mock + async def test_update_record_caa(self): data = { "$id": "5f40a6e10c65e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -669,13 +589,10 @@ def test_update_record_caa(self, m): "comment": "Mail server record", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.domains.update_record_caa( + response = await self.domains.update_record_caa( '', '', 'name', @@ -684,8 +601,8 @@ def test_update_record_caa(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_record_cname(self, m): + @respx.mock + async def test_create_record_cname(self): data = { "$id": "5f40a6e10c65e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -701,13 +618,10 @@ def test_create_record_cname(self, m): "comment": "Mail server record", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.domains.create_record_cname( + response = await self.domains.create_record_cname( '', 'name', '', @@ -715,8 +629,8 @@ def test_create_record_cname(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_record_cname(self, m): + @respx.mock + async def test_update_record_cname(self): data = { "$id": "5f40a6e10c65e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -732,13 +646,10 @@ def test_update_record_cname(self, m): "comment": "Mail server record", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.domains.update_record_cname( + response = await self.domains.update_record_cname( '', '', 'name', @@ -747,8 +658,8 @@ def test_update_record_cname(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_record_https(self, m): + @respx.mock + async def test_create_record_https(self): data = { "$id": "5f40a6e10c65e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -764,13 +675,10 @@ def test_create_record_https(self, m): "comment": "Mail server record", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.domains.create_record_https( + response = await self.domains.create_record_https( '', 'name', '', @@ -778,8 +686,8 @@ def test_create_record_https(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_record_https(self, m): + @respx.mock + async def test_update_record_https(self): data = { "$id": "5f40a6e10c65e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -795,13 +703,10 @@ def test_update_record_https(self, m): "comment": "Mail server record", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.domains.update_record_https( + response = await self.domains.update_record_https( '', '', 'name', @@ -810,8 +715,8 @@ def test_update_record_https(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_record_mx(self, m): + @respx.mock + async def test_create_record_mx(self): data = { "$id": "5f40a6e10c65e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -827,13 +732,10 @@ def test_create_record_mx(self, m): "comment": "Mail server record", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.domains.create_record_mx( + response = await self.domains.create_record_mx( '', 'name', '', @@ -842,8 +744,8 @@ def test_create_record_mx(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_record_mx(self, m): + @respx.mock + async def test_update_record_mx(self): data = { "$id": "5f40a6e10c65e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -859,13 +761,10 @@ def test_update_record_mx(self, m): "comment": "Mail server record", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.domains.update_record_mx( + response = await self.domains.update_record_mx( '', '', 'name', @@ -875,8 +774,8 @@ def test_update_record_mx(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_record_ns(self, m): + @respx.mock + async def test_create_record_ns(self): data = { "$id": "5f40a6e10c65e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -892,13 +791,10 @@ def test_create_record_ns(self, m): "comment": "Mail server record", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.domains.create_record_ns( + response = await self.domains.create_record_ns( '', 'name', '', @@ -906,8 +802,8 @@ def test_create_record_ns(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_record_ns(self, m): + @respx.mock + async def test_update_record_ns(self): data = { "$id": "5f40a6e10c65e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -923,13 +819,10 @@ def test_update_record_ns(self, m): "comment": "Mail server record", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.domains.update_record_ns( + response = await self.domains.update_record_ns( '', '', 'name', @@ -938,8 +831,8 @@ def test_update_record_ns(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_record_srv(self, m): + @respx.mock + async def test_create_record_srv(self): data = { "$id": "5f40a6e10c65e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -955,13 +848,10 @@ def test_create_record_srv(self, m): "comment": "Mail server record", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.domains.create_record_srv( + response = await self.domains.create_record_srv( '', 'name', '', @@ -972,8 +862,8 @@ def test_create_record_srv(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_record_srv(self, m): + @respx.mock + async def test_update_record_srv(self): data = { "$id": "5f40a6e10c65e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -989,13 +879,10 @@ def test_update_record_srv(self, m): "comment": "Mail server record", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.domains.update_record_srv( + response = await self.domains.update_record_srv( '', '', 'name', @@ -1007,8 +894,8 @@ def test_update_record_srv(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_record_txt(self, m): + @respx.mock + async def test_create_record_txt(self): data = { "$id": "5f40a6e10c65e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -1024,21 +911,18 @@ def test_create_record_txt(self, m): "comment": "Mail server record", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.domains.create_record_txt( + response = await self.domains.create_record_txt( '', 'name', 1, ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_record_txt(self, m): + @respx.mock + async def test_update_record_txt(self): data = { "$id": "5f40a6e10c65e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -1054,13 +938,10 @@ def test_update_record_txt(self, m): "comment": "Mail server record", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.domains.update_record_txt( + response = await self.domains.update_record_txt( '', '', 'name', @@ -1069,8 +950,8 @@ def test_update_record_txt(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_record(self, m): + @respx.mock + async def test_get_record(self): data = { "$id": "5f40a6e10c65e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -1086,36 +967,30 @@ def test_get_record(self, m): "comment": "Mail server record", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.domains.get_record( + response = await self.domains.get_record( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete_record(self, m): + @respx.mock + async def test_delete_record(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.domains.delete_record( + response = await self.domains.delete_record( '', '', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_update_team(self, m): + @respx.mock + async def test_update_team(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -1131,54 +1006,45 @@ def test_update_team(self, m): "dnsRecords": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.domains.update_team( + response = await self.domains.update_team( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_transfer_status(self, m): + @respx.mock + async def test_get_transfer_status(self): data = { "status": "pending_registry", "reason": "Transfer in progress", "timestamp": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.domains.get_transfer_status( + response = await self.domains.get_transfer_status( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_zone(self, m): + @respx.mock + async def test_get_zone(self): data = '; café zone\nwww 3600 IN A 192.0.2.1\n' headers = {'Content-Type': 'text/plain; charset=utf-8'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=data, - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=data, headers=headers), ) - response = self.domains.get_zone( + response = await self.domains.get_zone( '', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_update_zone(self, m): + @respx.mock + async def test_update_zone(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -1194,13 +1060,10 @@ def test_update_zone(self, m): "dnsRecords": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.domains.update_zone( + response = await self.domains.update_zone( '', '', ) diff --git a/test/services/test_embeddings.py b/test/services/test_embeddings.py index 4c37d10d..ca41ad23 100644 --- a/test/services/test_embeddings.py +++ b/test/services/test_embeddings.py @@ -1,5 +1,6 @@ import json -import requests_mock +import httpx2 +import respx import unittest from appwrite.client import Client @@ -8,26 +9,26 @@ from appwrite.services.embeddings import Embeddings -class EmbeddingsServiceTest(unittest.TestCase): +class EmbeddingsServiceTest(unittest.IsolatedAsyncioTestCase): - def setUp(self): + async def asyncSetUp(self): self.client = Client() self.embeddings = Embeddings(self.client) - @requests_mock.Mocker() - def test_create_text_embeddings(self, m): + async def asyncTearDown(self): + await self.client.aclose() + + @respx.mock + async def test_create_text_embeddings(self): data = { "total": 5.0, "embeddings": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.embeddings.create_text_embeddings( + response = await self.embeddings.create_text_embeddings( [], ) self.assertEqual(response.to_dict(), data) diff --git a/test/services/test_functions.py b/test/services/test_functions.py index 1f63e700..832d7b80 100644 --- a/test/services/test_functions.py +++ b/test/services/test_functions.py @@ -1,5 +1,6 @@ import json -import requests_mock +import httpx2 +import respx import unittest from appwrite.client import Client @@ -8,30 +9,30 @@ from appwrite.services.functions import Functions -class FunctionsServiceTest(unittest.TestCase): +class FunctionsServiceTest(unittest.IsolatedAsyncioTestCase): - def setUp(self): + async def asyncSetUp(self): self.client = Client() self.functions = Functions(self.client) - @requests_mock.Mocker() - def test_list(self, m): + async def asyncTearDown(self): + await self.client.aclose() + + @respx.mock + async def test_list(self): data = { "total": 5.0, "functions": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.functions.list() + response = await self.functions.list() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create(self, m): + @respx.mock + async def test_create(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -69,53 +70,44 @@ def test_create(self, m): "emailEnabled": True, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.functions.create( + response = await self.functions.create( '', '', 'node-14.5', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_list_runtimes(self, m): + @respx.mock + async def test_list_runtimes(self): data = { "total": 5.0, "runtimes": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.functions.list_runtimes() + response = await self.functions.list_runtimes() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_list_specifications(self, m): + @respx.mock + async def test_list_specifications(self): data = { "total": 5.0, "specifications": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.functions.list_specifications() + response = await self.functions.list_specifications() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get(self, m): + @respx.mock + async def test_get(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -153,19 +145,16 @@ def test_get(self, m): "emailEnabled": True, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.functions.get( + response = await self.functions.get( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update(self, m): + @respx.mock + async def test_update(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -203,35 +192,29 @@ def test_update(self, m): "emailEnabled": True, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.functions.update( + response = await self.functions.update( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete(self, m): + @respx.mock + async def test_delete(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.functions.delete( + response = await self.functions.delete( '', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_update_function_deployment(self, m): + @respx.mock + async def test_update_function_deployment(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -269,38 +252,32 @@ def test_update_function_deployment(self, m): "emailEnabled": True, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.functions.update_function_deployment( + response = await self.functions.update_function_deployment( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_list_deployments(self, m): + @respx.mock + async def test_list_deployments(self): data = { "total": 5.0, "deployments": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.functions.list_deployments( + response = await self.functions.list_deployments( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_deployment(self, m): + @respx.mock + async def test_create_deployment(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -331,21 +308,18 @@ def test_create_deployment(self, m): "providerBranchUrl": "https:\/\/github.com\/vermakhushboo\/appwrite\/tree\/0.7.x", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.functions.create_deployment( + response = await self.functions.create_deployment( '', InputFile.from_bytes(bytearray(), "example.file"), True, ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_duplicate_deployment(self, m): + @respx.mock + async def test_create_duplicate_deployment(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -376,20 +350,17 @@ def test_create_duplicate_deployment(self, m): "providerBranchUrl": "https:\/\/github.com\/vermakhushboo\/appwrite\/tree\/0.7.x", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.functions.create_duplicate_deployment( + response = await self.functions.create_duplicate_deployment( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_template_deployment(self, m): + @respx.mock + async def test_create_template_deployment(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -420,13 +391,10 @@ def test_create_template_deployment(self, m): "providerBranchUrl": "https:\/\/github.com\/vermakhushboo\/appwrite\/tree\/0.7.x", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.functions.create_template_deployment( + response = await self.functions.create_template_deployment( '', '', '', @@ -436,8 +404,8 @@ def test_create_template_deployment(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_vcs_deployment(self, m): + @respx.mock + async def test_create_vcs_deployment(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -468,21 +436,18 @@ def test_create_vcs_deployment(self, m): "providerBranchUrl": "https:\/\/github.com\/vermakhushboo\/appwrite\/tree\/0.7.x", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.functions.create_vcs_deployment( + response = await self.functions.create_vcs_deployment( '', 'branch', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_deployment(self, m): + @respx.mock + async def test_get_deployment(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -513,52 +478,43 @@ def test_get_deployment(self, m): "providerBranchUrl": "https:\/\/github.com\/vermakhushboo\/appwrite\/tree\/0.7.x", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.functions.get_deployment( + response = await self.functions.get_deployment( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete_deployment(self, m): + @respx.mock + async def test_delete_deployment(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.functions.delete_deployment( + response = await self.functions.delete_deployment( '', '', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_get_deployment_download(self, m): + @respx.mock + async def test_get_deployment_download(self): data = bytearray() headers = {'Content-Type': 'application/octet-stream'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - body=data, - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, content=bytes(data), headers=headers), ) - response = self.functions.get_deployment_download( + response = await self.functions.get_deployment_download( '', '', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_update_deployment_status(self, m): + @respx.mock + async def test_update_deployment_status(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -589,38 +545,32 @@ def test_update_deployment_status(self, m): "providerBranchUrl": "https:\/\/github.com\/vermakhushboo\/appwrite\/tree\/0.7.x", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.functions.update_deployment_status( + response = await self.functions.update_deployment_status( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_list_executions(self, m): + @respx.mock + async def test_list_executions(self): data = { "total": 5.0, "executions": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.functions.list_executions( + response = await self.functions.list_executions( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_execution(self, m): + @respx.mock + async def test_create_execution(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -642,19 +592,16 @@ def test_create_execution(self, m): "duration": 1.23, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.functions.create_execution( + response = await self.functions.create_execution( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_execution(self, m): + @respx.mock + async def test_get_execution(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -676,54 +623,45 @@ def test_get_execution(self, m): "duration": 1.23, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.functions.get_execution( + response = await self.functions.get_execution( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete_execution(self, m): + @respx.mock + async def test_delete_execution(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.functions.delete_execution( + response = await self.functions.delete_execution( '', '', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_list_variables(self, m): + @respx.mock + async def test_list_variables(self): data = { "total": 5.0, "variables": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.functions.list_variables( + response = await self.functions.list_variables( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_variable(self, m): + @respx.mock + async def test_create_variable(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -736,13 +674,10 @@ def test_create_variable(self, m): "resourceId": "myAwesomeFunction", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.functions.create_variable( + response = await self.functions.create_variable( '', '', '', @@ -750,8 +685,8 @@ def test_create_variable(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_variable(self, m): + @respx.mock + async def test_get_variable(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -764,20 +699,17 @@ def test_get_variable(self, m): "resourceId": "myAwesomeFunction", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.functions.get_variable( + response = await self.functions.get_variable( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_variable(self, m): + @respx.mock + async def test_update_variable(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -790,29 +722,23 @@ def test_update_variable(self, m): "resourceId": "myAwesomeFunction", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.functions.update_variable( + response = await self.functions.update_variable( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete_variable(self, m): + @respx.mock + async def test_delete_variable(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.functions.delete_variable( + response = await self.functions.delete_variable( '', '', ) diff --git a/test/services/test_graphql.py b/test/services/test_graphql.py index d9203da8..4e037993 100644 --- a/test/services/test_graphql.py +++ b/test/services/test_graphql.py @@ -1,5 +1,6 @@ import json -import requests_mock +import httpx2 +import respx import unittest from appwrite.client import Client @@ -8,38 +9,35 @@ from appwrite.services.graphql import Graphql -class GraphqlServiceTest(unittest.TestCase): +class GraphqlServiceTest(unittest.IsolatedAsyncioTestCase): - def setUp(self): + async def asyncSetUp(self): self.client = Client() self.graphql = Graphql(self.client) - @requests_mock.Mocker() - def test_query(self, m): + async def asyncTearDown(self): + await self.client.aclose() + + @respx.mock + async def test_query(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.graphql.query( + response = await self.graphql.query( {}, ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_mutation(self, m): + @respx.mock + async def test_mutation(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.graphql.mutation( + response = await self.graphql.mutation( {}, ) self.assertEqual(response, data) diff --git a/test/services/test_locale.py b/test/services/test_locale.py index 1438edfb..196eac93 100644 --- a/test/services/test_locale.py +++ b/test/services/test_locale.py @@ -1,5 +1,6 @@ import json -import requests_mock +import httpx2 +import respx import unittest from appwrite.client import Client @@ -8,14 +9,17 @@ from appwrite.services.locale import Locale -class LocaleServiceTest(unittest.TestCase): +class LocaleServiceTest(unittest.IsolatedAsyncioTestCase): - def setUp(self): + async def asyncSetUp(self): self.client = Client() self.locale = Locale(self.client) - @requests_mock.Mocker() - def test_get(self, m): + async def asyncTearDown(self): + await self.client.aclose() + + @respx.mock + async def test_get(self): data = { "ip": "127.0.0.1", "countryCode": "US", @@ -26,123 +30,99 @@ def test_get(self, m): "currency": "USD", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.locale.get() + response = await self.locale.get() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_list_codes(self, m): + @respx.mock + async def test_list_codes(self): data = { "total": 5.0, "localeCodes": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.locale.list_codes() + response = await self.locale.list_codes() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_list_continents(self, m): + @respx.mock + async def test_list_continents(self): data = { "total": 5.0, "continents": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.locale.list_continents() + response = await self.locale.list_continents() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_list_countries(self, m): + @respx.mock + async def test_list_countries(self): data = { "total": 5.0, "countries": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.locale.list_countries() + response = await self.locale.list_countries() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_list_countries_eu(self, m): + @respx.mock + async def test_list_countries_eu(self): data = { "total": 5.0, "countries": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.locale.list_countries_eu() + response = await self.locale.list_countries_eu() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_list_countries_phones(self, m): + @respx.mock + async def test_list_countries_phones(self): data = { "total": 5.0, "phones": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.locale.list_countries_phones() + response = await self.locale.list_countries_phones() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_list_currencies(self, m): + @respx.mock + async def test_list_currencies(self): data = { "total": 5.0, "currencies": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.locale.list_currencies() + response = await self.locale.list_currencies() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_list_languages(self, m): + @respx.mock + async def test_list_languages(self): data = { "total": 5.0, "languages": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.locale.list_languages() + response = await self.locale.list_languages() self.assertEqual(response.to_dict(), data) diff --git a/test/services/test_messaging.py b/test/services/test_messaging.py index d22f32d6..41f023a6 100644 --- a/test/services/test_messaging.py +++ b/test/services/test_messaging.py @@ -1,5 +1,6 @@ import json -import requests_mock +import httpx2 +import respx import unittest from appwrite.client import Client @@ -8,30 +9,30 @@ from appwrite.services.messaging import Messaging -class MessagingServiceTest(unittest.TestCase): +class MessagingServiceTest(unittest.IsolatedAsyncioTestCase): - def setUp(self): + async def asyncSetUp(self): self.client = Client() self.messaging = Messaging(self.client) - @requests_mock.Mocker() - def test_list_messages(self, m): + async def asyncTearDown(self): + await self.client.aclose() + + @respx.mock + async def test_list_messages(self): data = { "total": 5.0, "messages": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.messaging.list_messages() + response = await self.messaging.list_messages() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_email(self, m): + @respx.mock + async def test_create_email(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -45,21 +46,18 @@ def test_create_email(self, m): "status": "processing", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.messaging.create_email( + response = await self.messaging.create_email( '', '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_email(self, m): + @respx.mock + async def test_update_email(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -73,19 +71,16 @@ def test_update_email(self, m): "status": "processing", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.messaging.update_email( + response = await self.messaging.update_email( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_push(self, m): + @respx.mock + async def test_create_push(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -99,19 +94,16 @@ def test_create_push(self, m): "status": "processing", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.messaging.create_push( + response = await self.messaging.create_push( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_push(self, m): + @respx.mock + async def test_update_push(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -125,19 +117,16 @@ def test_update_push(self, m): "status": "processing", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.messaging.update_push( + response = await self.messaging.update_push( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_sms(self, m): + @respx.mock + async def test_create_sms(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -151,20 +140,17 @@ def test_create_sms(self, m): "status": "processing", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.messaging.create_sms( + response = await self.messaging.create_sms( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_sms(self, m): + @respx.mock + async def test_create_sms(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -178,20 +164,17 @@ def test_create_sms(self, m): "status": "processing", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.messaging.create_sms( + response = await self.messaging.create_sms( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_sms(self, m): + @respx.mock + async def test_update_sms(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -205,19 +188,16 @@ def test_update_sms(self, m): "status": "processing", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.messaging.update_sms( + response = await self.messaging.update_sms( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_sms(self, m): + @respx.mock + async def test_update_sms(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -231,19 +211,16 @@ def test_update_sms(self, m): "status": "processing", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.messaging.update_sms( + response = await self.messaging.update_sms( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_message(self, m): + @respx.mock + async def test_get_message(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -257,68 +234,56 @@ def test_get_message(self, m): "status": "processing", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.messaging.get_message( + response = await self.messaging.get_message( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete(self, m): + @respx.mock + async def test_delete(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.messaging.delete( + response = await self.messaging.delete( '', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_list_targets(self, m): + @respx.mock + async def test_list_targets(self): data = { "total": 5.0, "targets": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.messaging.list_targets( + response = await self.messaging.list_targets( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_list_providers(self, m): + @respx.mock + async def test_list_providers(self): data = { "total": 5.0, "providers": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.messaging.list_providers() + response = await self.messaging.list_providers() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_apns_provider(self, m): + @respx.mock + async def test_create_apns_provider(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -330,20 +295,17 @@ def test_create_apns_provider(self, m): "credentials": {}, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.messaging.create_apns_provider( + response = await self.messaging.create_apns_provider( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_apns_provider(self, m): + @respx.mock + async def test_create_apns_provider(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -355,20 +317,17 @@ def test_create_apns_provider(self, m): "credentials": {}, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.messaging.create_apns_provider( + response = await self.messaging.create_apns_provider( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_apns_provider(self, m): + @respx.mock + async def test_update_apns_provider(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -380,19 +339,16 @@ def test_update_apns_provider(self, m): "credentials": {}, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.messaging.update_apns_provider( + response = await self.messaging.update_apns_provider( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_apns_provider(self, m): + @respx.mock + async def test_update_apns_provider(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -404,19 +360,16 @@ def test_update_apns_provider(self, m): "credentials": {}, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.messaging.update_apns_provider( + response = await self.messaging.update_apns_provider( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_appwrite_provider(self, m): + @respx.mock + async def test_create_appwrite_provider(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -428,20 +381,17 @@ def test_create_appwrite_provider(self, m): "credentials": {}, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.messaging.create_appwrite_provider( + response = await self.messaging.create_appwrite_provider( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_appwrite_provider(self, m): + @respx.mock + async def test_update_appwrite_provider(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -453,19 +403,16 @@ def test_update_appwrite_provider(self, m): "credentials": {}, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.messaging.update_appwrite_provider( + response = await self.messaging.update_appwrite_provider( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_fcm_provider(self, m): + @respx.mock + async def test_create_fcm_provider(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -477,20 +424,17 @@ def test_create_fcm_provider(self, m): "credentials": {}, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.messaging.create_fcm_provider( + response = await self.messaging.create_fcm_provider( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_fcm_provider(self, m): + @respx.mock + async def test_create_fcm_provider(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -502,20 +446,17 @@ def test_create_fcm_provider(self, m): "credentials": {}, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.messaging.create_fcm_provider( + response = await self.messaging.create_fcm_provider( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_fcm_provider(self, m): + @respx.mock + async def test_update_fcm_provider(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -527,19 +468,16 @@ def test_update_fcm_provider(self, m): "credentials": {}, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.messaging.update_fcm_provider( + response = await self.messaging.update_fcm_provider( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_fcm_provider(self, m): + @respx.mock + async def test_update_fcm_provider(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -551,19 +489,16 @@ def test_update_fcm_provider(self, m): "credentials": {}, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.messaging.update_fcm_provider( + response = await self.messaging.update_fcm_provider( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_mailgun_provider(self, m): + @respx.mock + async def test_create_mailgun_provider(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -575,20 +510,17 @@ def test_create_mailgun_provider(self, m): "credentials": {}, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.messaging.create_mailgun_provider( + response = await self.messaging.create_mailgun_provider( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_mailgun_provider(self, m): + @respx.mock + async def test_update_mailgun_provider(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -600,19 +532,16 @@ def test_update_mailgun_provider(self, m): "credentials": {}, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.messaging.update_mailgun_provider( + response = await self.messaging.update_mailgun_provider( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_msg91_provider(self, m): + @respx.mock + async def test_create_msg91_provider(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -624,20 +553,17 @@ def test_create_msg91_provider(self, m): "credentials": {}, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.messaging.create_msg91_provider( + response = await self.messaging.create_msg91_provider( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_msg91_provider(self, m): + @respx.mock + async def test_update_msg91_provider(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -649,19 +575,16 @@ def test_update_msg91_provider(self, m): "credentials": {}, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.messaging.update_msg91_provider( + response = await self.messaging.update_msg91_provider( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_resend_provider(self, m): + @respx.mock + async def test_create_resend_provider(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -673,20 +596,17 @@ def test_create_resend_provider(self, m): "credentials": {}, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.messaging.create_resend_provider( + response = await self.messaging.create_resend_provider( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_resend_provider(self, m): + @respx.mock + async def test_update_resend_provider(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -698,19 +618,16 @@ def test_update_resend_provider(self, m): "credentials": {}, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.messaging.update_resend_provider( + response = await self.messaging.update_resend_provider( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_sendgrid_provider(self, m): + @respx.mock + async def test_create_sendgrid_provider(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -722,20 +639,17 @@ def test_create_sendgrid_provider(self, m): "credentials": {}, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.messaging.create_sendgrid_provider( + response = await self.messaging.create_sendgrid_provider( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_sendgrid_provider(self, m): + @respx.mock + async def test_update_sendgrid_provider(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -747,19 +661,16 @@ def test_update_sendgrid_provider(self, m): "credentials": {}, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.messaging.update_sendgrid_provider( + response = await self.messaging.update_sendgrid_provider( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_ses_provider(self, m): + @respx.mock + async def test_create_ses_provider(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -771,20 +682,17 @@ def test_create_ses_provider(self, m): "credentials": {}, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.messaging.create_ses_provider( + response = await self.messaging.create_ses_provider( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_ses_provider(self, m): + @respx.mock + async def test_update_ses_provider(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -796,19 +704,16 @@ def test_update_ses_provider(self, m): "credentials": {}, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.messaging.update_ses_provider( + response = await self.messaging.update_ses_provider( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_smtp_provider(self, m): + @respx.mock + async def test_create_smtp_provider(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -820,21 +725,18 @@ def test_create_smtp_provider(self, m): "credentials": {}, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.messaging.create_smtp_provider( + response = await self.messaging.create_smtp_provider( '', '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_smtp_provider(self, m): + @respx.mock + async def test_create_smtp_provider(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -846,21 +748,18 @@ def test_create_smtp_provider(self, m): "credentials": {}, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.messaging.create_smtp_provider( + response = await self.messaging.create_smtp_provider( '', '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_smtp_provider(self, m): + @respx.mock + async def test_update_smtp_provider(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -872,19 +771,16 @@ def test_update_smtp_provider(self, m): "credentials": {}, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.messaging.update_smtp_provider( + response = await self.messaging.update_smtp_provider( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_smtp_provider(self, m): + @respx.mock + async def test_update_smtp_provider(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -896,19 +792,16 @@ def test_update_smtp_provider(self, m): "credentials": {}, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.messaging.update_smtp_provider( + response = await self.messaging.update_smtp_provider( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_telesign_provider(self, m): + @respx.mock + async def test_create_telesign_provider(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -920,20 +813,17 @@ def test_create_telesign_provider(self, m): "credentials": {}, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.messaging.create_telesign_provider( + response = await self.messaging.create_telesign_provider( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_telesign_provider(self, m): + @respx.mock + async def test_update_telesign_provider(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -945,19 +835,16 @@ def test_update_telesign_provider(self, m): "credentials": {}, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.messaging.update_telesign_provider( + response = await self.messaging.update_telesign_provider( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_textmagic_provider(self, m): + @respx.mock + async def test_create_textmagic_provider(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -969,20 +856,17 @@ def test_create_textmagic_provider(self, m): "credentials": {}, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.messaging.create_textmagic_provider( + response = await self.messaging.create_textmagic_provider( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_textmagic_provider(self, m): + @respx.mock + async def test_update_textmagic_provider(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -994,19 +878,16 @@ def test_update_textmagic_provider(self, m): "credentials": {}, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.messaging.update_textmagic_provider( + response = await self.messaging.update_textmagic_provider( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_twilio_provider(self, m): + @respx.mock + async def test_create_twilio_provider(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -1018,20 +899,17 @@ def test_create_twilio_provider(self, m): "credentials": {}, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.messaging.create_twilio_provider( + response = await self.messaging.create_twilio_provider( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_twilio_provider(self, m): + @respx.mock + async def test_update_twilio_provider(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -1043,19 +921,16 @@ def test_update_twilio_provider(self, m): "credentials": {}, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.messaging.update_twilio_provider( + response = await self.messaging.update_twilio_provider( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_vonage_provider(self, m): + @respx.mock + async def test_create_vonage_provider(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -1067,20 +942,17 @@ def test_create_vonage_provider(self, m): "credentials": {}, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.messaging.create_vonage_provider( + response = await self.messaging.create_vonage_provider( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_vonage_provider(self, m): + @respx.mock + async def test_update_vonage_provider(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -1092,19 +964,16 @@ def test_update_vonage_provider(self, m): "credentials": {}, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.messaging.update_vonage_provider( + response = await self.messaging.update_vonage_provider( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_provider(self, m): + @respx.mock + async def test_get_provider(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -1116,50 +985,41 @@ def test_get_provider(self, m): "credentials": {}, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.messaging.get_provider( + response = await self.messaging.get_provider( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete_provider(self, m): + @respx.mock + async def test_delete_provider(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.messaging.delete_provider( + response = await self.messaging.delete_provider( '', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_list_topics(self, m): + @respx.mock + async def test_list_topics(self): data = { "total": 5.0, "topics": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.messaging.list_topics() + response = await self.messaging.list_topics() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_topic(self, m): + @respx.mock + async def test_create_topic(self): data = { "$id": "259125845563242502", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -1172,20 +1032,17 @@ def test_create_topic(self, m): "subscribe": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.messaging.create_topic( + response = await self.messaging.create_topic( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_topic(self, m): + @respx.mock + async def test_get_topic(self): data = { "$id": "259125845563242502", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -1198,19 +1055,16 @@ def test_get_topic(self, m): "subscribe": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.messaging.get_topic( + response = await self.messaging.get_topic( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_topic(self, m): + @respx.mock + async def test_update_topic(self): data = { "$id": "259125845563242502", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -1223,52 +1077,43 @@ def test_update_topic(self, m): "subscribe": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.messaging.update_topic( + response = await self.messaging.update_topic( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete_topic(self, m): + @respx.mock + async def test_delete_topic(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.messaging.delete_topic( + response = await self.messaging.delete_topic( '', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_list_subscribers(self, m): + @respx.mock + async def test_list_subscribers(self): data = { "total": 5.0, "subscribers": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.messaging.list_subscribers( + response = await self.messaging.list_subscribers( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_subscriber(self, m): + @respx.mock + async def test_create_subscriber(self): data = { "$id": "259125845563242502", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -1290,21 +1135,18 @@ def test_create_subscriber(self, m): "providerType": "email", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.messaging.create_subscriber( + response = await self.messaging.create_subscriber( '', '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_subscriber(self, m): + @respx.mock + async def test_get_subscriber(self): data = { "$id": "259125845563242502", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -1326,29 +1168,23 @@ def test_get_subscriber(self, m): "providerType": "email", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.messaging.get_subscriber( + response = await self.messaging.get_subscriber( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete_subscriber(self, m): + @respx.mock + async def test_delete_subscriber(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.messaging.delete_subscriber( + response = await self.messaging.delete_subscriber( '', '', ) diff --git a/test/services/test_mongo.py b/test/services/test_mongo.py index 75b37bfa..6602ce9f 100644 --- a/test/services/test_mongo.py +++ b/test/services/test_mongo.py @@ -1,5 +1,6 @@ import json -import requests_mock +import httpx2 +import respx import unittest from appwrite.client import Client @@ -8,30 +9,30 @@ from appwrite.services.mongo import Mongo -class MongoServiceTest(unittest.TestCase): +class MongoServiceTest(unittest.IsolatedAsyncioTestCase): - def setUp(self): + async def asyncSetUp(self): self.client = Client() self.mongo = Mongo(self.client) - @requests_mock.Mocker() - def test_list(self, m): + async def asyncTearDown(self): + await self.client.aclose() + + @respx.mock + async def test_list(self): data = { "total": 5.0, "databases": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.mongo.list() + response = await self.mongo.list() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create(self, m): + @respx.mock + async def test_create(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -80,36 +81,30 @@ def test_create(self, m): "error": "", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.mongo.create( + response = await self.mongo.create( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_list_specifications(self, m): + @respx.mock + async def test_list_specifications(self): data = { "specifications": [], "total": 9.0, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.mongo.list_specifications() + response = await self.mongo.list_specifications() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get(self, m): + @respx.mock + async def test_get(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -158,19 +153,16 @@ def test_get(self, m): "error": "", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.mongo.get( + response = await self.mongo.get( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update(self, m): + @respx.mock + async def test_update(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -219,52 +211,43 @@ def test_update(self, m): "error": "", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.mongo.update( + response = await self.mongo.update( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete(self, m): + @respx.mock + async def test_delete(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.mongo.delete( + response = await self.mongo.delete( '', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_list_backups(self, m): + @respx.mock + async def test_list_backups(self): data = { "total": 5.0, "backups": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.mongo.list_backups( + response = await self.mongo.list_backups( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_backup(self, m): + @respx.mock + async def test_create_backup(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -280,37 +263,31 @@ def test_create_backup(self, m): "error": "", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.mongo.create_backup( + response = await self.mongo.create_backup( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_list_backup_policies(self, m): + @respx.mock + async def test_list_backup_policies(self): data = { "total": 5.0, "policies": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.mongo.list_backup_policies( + response = await self.mongo.list_backup_policies( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_backup_policy(self, m): + @respx.mock + async def test_create_backup_policy(self): data = { "$id": "5e5ea5c16897e", "name": "Hourly backups", @@ -324,13 +301,10 @@ def test_create_backup_policy(self, m): "enabled": True, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.mongo.create_backup_policy( + response = await self.mongo.create_backup_policy( '', '', '', @@ -339,8 +313,8 @@ def test_create_backup_policy(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_backup_policy(self, m): + @respx.mock + async def test_get_backup_policy(self): data = { "$id": "5e5ea5c16897e", "name": "Hourly backups", @@ -354,20 +328,17 @@ def test_get_backup_policy(self, m): "enabled": True, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.mongo.get_backup_policy( + response = await self.mongo.get_backup_policy( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_backup_policy(self, m): + @respx.mock + async def test_update_backup_policy(self): data = { "$id": "5e5ea5c16897e", "name": "Hourly backups", @@ -381,36 +352,30 @@ def test_update_backup_policy(self, m): "enabled": True, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.mongo.update_backup_policy( + response = await self.mongo.update_backup_policy( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete_backup_policy(self, m): + @respx.mock + async def test_delete_backup_policy(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.mongo.delete_backup_policy( + response = await self.mongo.delete_backup_policy( '', '', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_update_backup_storage(self, m): + @respx.mock + async def test_update_backup_storage(self): data = { "provider": "s3", "bucket": "my-backup-bucket", @@ -419,13 +384,10 @@ def test_update_backup_storage(self, m): "endpoint": "https:\/\/minio.example.com", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.mongo.update_backup_storage( + response = await self.mongo.update_backup_storage( '', 's3', '', @@ -434,8 +396,8 @@ def test_update_backup_storage(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_backup(self, m): + @respx.mock + async def test_get_backup(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -451,54 +413,45 @@ def test_get_backup(self, m): "error": "", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.mongo.get_backup( + response = await self.mongo.get_backup( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete_backup(self, m): + @respx.mock + async def test_delete_backup(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.mongo.delete_backup( + response = await self.mongo.delete_backup( '', '', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_list_branches(self, m): + @respx.mock + async def test_list_branches(self): data = { "total": 2.0, "branches": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.mongo.list_branches( + response = await self.mongo.list_branches( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_branch(self, m): + @respx.mock + async def test_create_branch(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -547,19 +500,16 @@ def test_create_branch(self, m): "error": "", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.mongo.create_branch( + response = await self.mongo.create_branch( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete_branch(self, m): + @respx.mock + async def test_delete_branch(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -608,20 +558,17 @@ def test_delete_branch(self, m): "error": "", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.mongo.delete_branch( + response = await self.mongo.delete_branch( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_credentials(self, m): + @respx.mock + async def test_update_credentials(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -633,19 +580,16 @@ def test_update_credentials(self, m): "errorMessage": "", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.mongo.update_credentials( + response = await self.mongo.update_credentials( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_failover(self, m): + @respx.mock + async def test_create_failover(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -694,19 +638,16 @@ def test_create_failover(self, m): "error": "", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.mongo.create_failover( + response = await self.mongo.create_failover( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_maintenance(self, m): + @respx.mock + async def test_update_maintenance(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -755,21 +696,18 @@ def test_update_maintenance(self, m): "error": "", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.mongo.update_maintenance( + response = await self.mongo.update_maintenance( '', 'sun', 1, ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_migration(self, m): + @respx.mock + async def test_create_migration(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -818,56 +756,47 @@ def test_create_migration(self, m): "error": "", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.mongo.create_migration( + response = await self.mongo.create_migration( '', 'shared', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_list_operations(self, m): + @respx.mock + async def test_list_operations(self): data = { "total": 5.0, "operations": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.mongo.list_operations( + response = await self.mongo.list_operations( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_pitr(self, m): + @respx.mock + async def test_get_pitr(self): data = { "earliest": "2020-10-15T06:38:00.000+00:00", "latest": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.mongo.get_pitr( + response = await self.mongo.get_pitr( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_replicas(self, m): + @respx.mock + async def test_get_replicas(self): data = { "replicas": 2.0, "syncMode": "async", @@ -877,37 +806,31 @@ def test_get_replicas(self, m): "members": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.mongo.get_replicas( + response = await self.mongo.get_replicas( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_list_restorations(self, m): + @respx.mock + async def test_list_restorations(self): data = { "total": 5.0, "restorations": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.mongo.list_restorations( + response = await self.mongo.list_restorations( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_restoration(self, m): + @respx.mock + async def test_create_restoration(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -919,19 +842,16 @@ def test_create_restoration(self, m): "error": "", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.mongo.create_restoration( + response = await self.mongo.create_restoration( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_restoration(self, m): + @respx.mock + async def test_get_restoration(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -943,20 +863,17 @@ def test_get_restoration(self, m): "error": "", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.mongo.get_restoration( + response = await self.mongo.get_restoration( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_promote_restoration(self, m): + @respx.mock + async def test_promote_restoration(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -968,20 +885,17 @@ def test_promote_restoration(self, m): "error": "", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.mongo.promote_restoration( + response = await self.mongo.promote_restoration( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_status(self, m): + @respx.mock + async def test_get_status(self): data = { "health": "healthy", "ready": True, @@ -996,19 +910,16 @@ def test_get_status(self, m): "volumes": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.mongo.get_status( + response = await self.mongo.get_status( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_upgrade(self, m): + @respx.mock + async def test_create_upgrade(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -1057,13 +968,10 @@ def test_create_upgrade(self, m): "error": "", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.mongo.create_upgrade( + response = await self.mongo.create_upgrade( '', '', ) diff --git a/test/services/test_mysql.py b/test/services/test_mysql.py index 3ea4f7d3..ef36d811 100644 --- a/test/services/test_mysql.py +++ b/test/services/test_mysql.py @@ -1,5 +1,6 @@ import json -import requests_mock +import httpx2 +import respx import unittest from appwrite.client import Client @@ -8,30 +9,30 @@ from appwrite.services.mysql import Mysql -class MysqlServiceTest(unittest.TestCase): +class MysqlServiceTest(unittest.IsolatedAsyncioTestCase): - def setUp(self): + async def asyncSetUp(self): self.client = Client() self.mysql = Mysql(self.client) - @requests_mock.Mocker() - def test_list(self, m): + async def asyncTearDown(self): + await self.client.aclose() + + @respx.mock + async def test_list(self): data = { "total": 5.0, "databases": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.mysql.list() + response = await self.mysql.list() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create(self, m): + @respx.mock + async def test_create(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -80,36 +81,30 @@ def test_create(self, m): "error": "", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.mysql.create( + response = await self.mysql.create( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_list_specifications(self, m): + @respx.mock + async def test_list_specifications(self): data = { "specifications": [], "total": 9.0, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.mysql.list_specifications() + response = await self.mysql.list_specifications() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get(self, m): + @respx.mock + async def test_get(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -158,19 +153,16 @@ def test_get(self, m): "error": "", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.mysql.get( + response = await self.mysql.get( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update(self, m): + @respx.mock + async def test_update(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -219,52 +211,43 @@ def test_update(self, m): "error": "", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.mysql.update( + response = await self.mysql.update( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete(self, m): + @respx.mock + async def test_delete(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.mysql.delete( + response = await self.mysql.delete( '', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_list_backups(self, m): + @respx.mock + async def test_list_backups(self): data = { "total": 5.0, "backups": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.mysql.list_backups( + response = await self.mysql.list_backups( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_backup(self, m): + @respx.mock + async def test_create_backup(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -280,37 +263,31 @@ def test_create_backup(self, m): "error": "", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.mysql.create_backup( + response = await self.mysql.create_backup( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_list_backup_policies(self, m): + @respx.mock + async def test_list_backup_policies(self): data = { "total": 5.0, "policies": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.mysql.list_backup_policies( + response = await self.mysql.list_backup_policies( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_backup_policy(self, m): + @respx.mock + async def test_create_backup_policy(self): data = { "$id": "5e5ea5c16897e", "name": "Hourly backups", @@ -324,13 +301,10 @@ def test_create_backup_policy(self, m): "enabled": True, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.mysql.create_backup_policy( + response = await self.mysql.create_backup_policy( '', '', '', @@ -339,8 +313,8 @@ def test_create_backup_policy(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_backup_policy(self, m): + @respx.mock + async def test_get_backup_policy(self): data = { "$id": "5e5ea5c16897e", "name": "Hourly backups", @@ -354,20 +328,17 @@ def test_get_backup_policy(self, m): "enabled": True, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.mysql.get_backup_policy( + response = await self.mysql.get_backup_policy( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_backup_policy(self, m): + @respx.mock + async def test_update_backup_policy(self): data = { "$id": "5e5ea5c16897e", "name": "Hourly backups", @@ -381,36 +352,30 @@ def test_update_backup_policy(self, m): "enabled": True, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.mysql.update_backup_policy( + response = await self.mysql.update_backup_policy( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete_backup_policy(self, m): + @respx.mock + async def test_delete_backup_policy(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.mysql.delete_backup_policy( + response = await self.mysql.delete_backup_policy( '', '', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_update_backup_storage(self, m): + @respx.mock + async def test_update_backup_storage(self): data = { "provider": "s3", "bucket": "my-backup-bucket", @@ -419,13 +384,10 @@ def test_update_backup_storage(self, m): "endpoint": "https:\/\/minio.example.com", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.mysql.update_backup_storage( + response = await self.mysql.update_backup_storage( '', 's3', '', @@ -434,8 +396,8 @@ def test_update_backup_storage(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_backup(self, m): + @respx.mock + async def test_get_backup(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -451,54 +413,45 @@ def test_get_backup(self, m): "error": "", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.mysql.get_backup( + response = await self.mysql.get_backup( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete_backup(self, m): + @respx.mock + async def test_delete_backup(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.mysql.delete_backup( + response = await self.mysql.delete_backup( '', '', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_list_branches(self, m): + @respx.mock + async def test_list_branches(self): data = { "total": 2.0, "branches": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.mysql.list_branches( + response = await self.mysql.list_branches( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_branch(self, m): + @respx.mock + async def test_create_branch(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -547,19 +500,16 @@ def test_create_branch(self, m): "error": "", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.mysql.create_branch( + response = await self.mysql.create_branch( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete_branch(self, m): + @respx.mock + async def test_delete_branch(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -608,20 +558,17 @@ def test_delete_branch(self, m): "error": "", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.mysql.delete_branch( + response = await self.mysql.delete_branch( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_credentials(self, m): + @respx.mock + async def test_update_credentials(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -633,19 +580,16 @@ def test_update_credentials(self, m): "errorMessage": "", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.mysql.update_credentials( + response = await self.mysql.update_credentials( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_execution(self, m): + @respx.mock + async def test_create_execution(self): data = { "rows": [], "rowCount": 1.0, @@ -655,20 +599,17 @@ def test_create_execution(self, m): "bytes": 1024.0, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.mysql.create_execution( + response = await self.mysql.create_execution( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_failover(self, m): + @respx.mock + async def test_create_failover(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -717,19 +658,16 @@ def test_create_failover(self, m): "error": "", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.mysql.create_failover( + response = await self.mysql.create_failover( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_maintenance(self, m): + @respx.mock + async def test_update_maintenance(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -778,21 +716,18 @@ def test_update_maintenance(self, m): "error": "", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.mysql.update_maintenance( + response = await self.mysql.update_maintenance( '', 'sun', 1, ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_migration(self, m): + @respx.mock + async def test_create_migration(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -841,56 +776,47 @@ def test_create_migration(self, m): "error": "", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.mysql.create_migration( + response = await self.mysql.create_migration( '', 'shared', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_list_operations(self, m): + @respx.mock + async def test_list_operations(self): data = { "total": 5.0, "operations": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.mysql.list_operations( + response = await self.mysql.list_operations( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_pitr(self, m): + @respx.mock + async def test_get_pitr(self): data = { "earliest": "2020-10-15T06:38:00.000+00:00", "latest": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.mysql.get_pitr( + response = await self.mysql.get_pitr( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_pooler(self, m): + @respx.mock + async def test_get_pooler(self): data = { "enabled": True, "mode": "transaction", @@ -904,19 +830,16 @@ def test_get_pooler(self, m): "poolerMemoryLimit": "128Mi", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.mysql.get_pooler( + response = await self.mysql.get_pooler( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_pooler(self, m): + @respx.mock + async def test_update_pooler(self): data = { "enabled": True, "mode": "transaction", @@ -930,19 +853,16 @@ def test_update_pooler(self, m): "poolerMemoryLimit": "128Mi", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.mysql.update_pooler( + response = await self.mysql.update_pooler( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_replicas(self, m): + @respx.mock + async def test_get_replicas(self): data = { "replicas": 2.0, "syncMode": "async", @@ -952,37 +872,31 @@ def test_get_replicas(self, m): "members": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.mysql.get_replicas( + response = await self.mysql.get_replicas( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_list_restorations(self, m): + @respx.mock + async def test_list_restorations(self): data = { "total": 5.0, "restorations": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.mysql.list_restorations( + response = await self.mysql.list_restorations( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_restoration(self, m): + @respx.mock + async def test_create_restoration(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -994,19 +908,16 @@ def test_create_restoration(self, m): "error": "", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.mysql.create_restoration( + response = await self.mysql.create_restoration( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_restoration(self, m): + @respx.mock + async def test_get_restoration(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -1018,20 +929,17 @@ def test_get_restoration(self, m): "error": "", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.mysql.get_restoration( + response = await self.mysql.get_restoration( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_promote_restoration(self, m): + @respx.mock + async def test_promote_restoration(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -1043,20 +951,17 @@ def test_promote_restoration(self, m): "error": "", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.mysql.promote_restoration( + response = await self.mysql.promote_restoration( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_status(self, m): + @respx.mock + async def test_get_status(self): data = { "health": "healthy", "ready": True, @@ -1071,19 +976,16 @@ def test_get_status(self, m): "volumes": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.mysql.get_status( + response = await self.mysql.get_status( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_upgrade(self, m): + @respx.mock + async def test_create_upgrade(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -1132,13 +1034,10 @@ def test_create_upgrade(self, m): "error": "", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.mysql.create_upgrade( + response = await self.mysql.create_upgrade( '', '', ) diff --git a/test/services/test_oauth2.py b/test/services/test_oauth2.py index da2520ee..3fba18e6 100644 --- a/test/services/test_oauth2.py +++ b/test/services/test_oauth2.py @@ -1,5 +1,6 @@ import json -import requests_mock +import httpx2 +import respx import unittest from appwrite.client import Client @@ -8,63 +9,57 @@ from appwrite.services.oauth2 import Oauth2 -class Oauth2ServiceTest(unittest.TestCase): +class Oauth2ServiceTest(unittest.IsolatedAsyncioTestCase): - def setUp(self): + async def asyncSetUp(self): self.client = Client() self.oauth2 = Oauth2(self.client) - @requests_mock.Mocker() - def test_approve(self, m): + async def asyncTearDown(self): + await self.client.aclose() + + @respx.mock + async def test_approve(self): data = { "redirectUrl": "https:\/\/example.com\/callback?code=abcde&state=fghij", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.oauth2.approve( + response = await self.oauth2.approve( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_authorize(self, m): + @respx.mock + async def test_authorize(self): data = { "grantId": "5e5ea5c16897e", "redirectUrl": "https:\/\/example.com\/callback?code=abcde&state=fghij", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.oauth2.authorize() + response = await self.oauth2.authorize() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_authorize_post(self, m): + @respx.mock + async def test_authorize_post(self): data = { "grantId": "5e5ea5c16897e", "redirectUrl": "https:\/\/example.com\/callback?code=abcde&state=fghij", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.oauth2.authorize_post() + response = await self.oauth2.authorize_post() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_device_authorization(self, m): + @respx.mock + async def test_create_device_authorization(self): data = { "device_code": "5f3c8d2a1b9e4f7a6c8b2d1e9f4a7b3c5d8e1f2a9b4c7d6e3f5a8b1c4d7e2f9a", "user_code": "ABCD-EFGH", @@ -74,17 +69,14 @@ def test_create_device_authorization(self, m): "interval": 5.0, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.oauth2.create_device_authorization() + response = await self.oauth2.create_device_authorization() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_grant(self, m): + @respx.mock + async def test_create_grant(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -100,19 +92,16 @@ def test_create_grant(self, m): "expire": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.oauth2.create_grant( + response = await self.oauth2.create_grant( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_grant(self, m): + @respx.mock + async def test_get_grant(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -128,120 +117,99 @@ def test_get_grant(self, m): "expire": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.oauth2.get_grant( + response = await self.oauth2.get_grant( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_introspect(self, m): + @respx.mock + async def test_introspect(self): data = { "active": True, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.oauth2.introspect( + response = await self.oauth2.introspect( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_list_organizations(self, m): + @respx.mock + async def test_list_organizations(self): data = { "total": 5.0, "organizations": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.oauth2.list_organizations() + response = await self.oauth2.list_organizations() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_par(self, m): + @respx.mock + async def test_create_par(self): data = { "request_uri": "urn:appwrite:oauth2:request:5e5ea5c16897e", "expires_in": 600.0, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.oauth2.create_par( + response = await self.oauth2.create_par( '', 'https://example.com', 'code', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_list_projects(self, m): + @respx.mock + async def test_list_projects(self): data = { "total": 5.0, "projects": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.oauth2.list_projects() + response = await self.oauth2.list_projects() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_reject(self, m): + @respx.mock + async def test_reject(self): data = { "redirectUrl": "https:\/\/example.com\/callback?error=access_denied&state=fghij", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.oauth2.reject( + response = await self.oauth2.reject( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_revoke(self, m): + @respx.mock + async def test_revoke(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.oauth2.revoke( + response = await self.oauth2.revoke( '', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_create_token(self, m): + @respx.mock + async def test_create_token(self): data = { "access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9...", "token_type": "Bearer", @@ -250,13 +218,10 @@ def test_create_token(self, m): "scope": "openid email profile", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.oauth2.create_token( + response = await self.oauth2.create_token( '', ) self.assertEqual(response.to_dict(), data) diff --git a/test/services/test_organization.py b/test/services/test_organization.py index 41206a71..8f9b930f 100644 --- a/test/services/test_organization.py +++ b/test/services/test_organization.py @@ -1,5 +1,6 @@ import json -import requests_mock +import httpx2 +import respx import unittest from appwrite.client import Client @@ -8,14 +9,17 @@ from appwrite.services.organization import Organization -class OrganizationServiceTest(unittest.TestCase): +class OrganizationServiceTest(unittest.IsolatedAsyncioTestCase): - def setUp(self): + async def asyncSetUp(self): self.client = Client() self.organization = Organization(self.client) - @requests_mock.Mocker() - def test_get(self, m): + async def asyncTearDown(self): + await self.client.aclose() + + @respx.mock + async def test_get(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -104,17 +108,14 @@ def test_get(self, m): "projects": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.organization.get() + response = await self.organization.get() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update(self, m): + @respx.mock + async def test_update(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -203,48 +204,39 @@ def test_update(self, m): "projects": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.organization.update( + response = await self.organization.update( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete(self, m): + @respx.mock + async def test_delete(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.organization.delete() + response = await self.organization.delete() self.assertEqual(response, data) - @requests_mock.Mocker() - def test_list_installations(self, m): + @respx.mock + async def test_list_installations(self): data = { "total": 5.0, "installations": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.organization.list_installations() + response = await self.organization.list_installations() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_installation(self, m): + @respx.mock + async def test_create_installation(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -257,19 +249,16 @@ def test_create_installation(self, m): "createdByName": "Walter White", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.organization.create_installation( + response = await self.organization.create_installation( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_installation(self, m): + @respx.mock + async def test_get_installation(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -282,19 +271,16 @@ def test_get_installation(self, m): "createdByName": "Walter White", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.organization.get_installation( + response = await self.organization.get_installation( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_installation(self, m): + @respx.mock + async def test_update_installation(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -307,50 +293,41 @@ def test_update_installation(self, m): "createdByName": "Walter White", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.organization.update_installation( + response = await self.organization.update_installation( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete_installation(self, m): + @respx.mock + async def test_delete_installation(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.organization.delete_installation( + response = await self.organization.delete_installation( '', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_list_memberships(self, m): + @respx.mock + async def test_list_memberships(self): data = { "total": 5.0, "memberships": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.organization.list_memberships() + response = await self.organization.list_memberships() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_membership(self, m): + @respx.mock + async def test_create_membership(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -369,19 +346,16 @@ def test_create_membership(self, m): "roles": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.organization.create_membership( + response = await self.organization.create_membership( [], ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_membership(self, m): + @respx.mock + async def test_get_membership(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -400,19 +374,16 @@ def test_get_membership(self, m): "roles": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.organization.get_membership( + response = await self.organization.get_membership( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_membership(self, m): + @respx.mock + async def test_update_membership(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -431,51 +402,42 @@ def test_update_membership(self, m): "roles": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.organization.update_membership( + response = await self.organization.update_membership( '', [], ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete_membership(self, m): + @respx.mock + async def test_delete_membership(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.organization.delete_membership( + response = await self.organization.delete_membership( '', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_list_projects(self, m): + @respx.mock + async def test_list_projects(self): data = { "total": 5.0, "projects": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.organization.list_projects() + response = await self.organization.list_projects() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_project(self, m): + @respx.mock + async def test_create_project(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -505,20 +467,17 @@ def test_create_project(self, m): "consoleAccessedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.organization.create_project( + response = await self.organization.create_project( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_project(self, m): + @respx.mock + async def test_get_project(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -548,19 +507,16 @@ def test_get_project(self, m): "consoleAccessedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.organization.get_project( + response = await self.organization.get_project( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_project(self, m): + @respx.mock + async def test_update_project(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -590,53 +546,44 @@ def test_update_project(self, m): "consoleAccessedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.organization.update_project( + response = await self.organization.update_project( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete_project(self, m): + @respx.mock + async def test_delete_project(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.organization.delete_project( + response = await self.organization.delete_project( '', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_list_project_keys(self, m): + @respx.mock + async def test_list_project_keys(self): data = { "total": 5.0, "keys": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.organization.list_project_keys( + response = await self.organization.list_project_keys( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_ephemeral_project_key(self, m): + @respx.mock + async def test_create_ephemeral_project_key(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -650,21 +597,18 @@ def test_create_ephemeral_project_key(self, m): "sdks": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.organization.create_ephemeral_project_key( + response = await self.organization.create_ephemeral_project_key( '', [], 1, ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_project_key(self, m): + @respx.mock + async def test_get_project_key(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -678,20 +622,17 @@ def test_get_project_key(self, m): "sdks": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.organization.get_project_key( + response = await self.organization.get_project_key( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_project_key(self, m): + @respx.mock + async def test_update_project_key(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -705,13 +646,10 @@ def test_update_project_key(self, m): "sdks": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.organization.update_project_key( + response = await self.organization.update_project_key( '', '', '', @@ -719,17 +657,14 @@ def test_update_project_key(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete_project_key(self, m): + @respx.mock + async def test_delete_project_key(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.organization.delete_project_key( + response = await self.organization.delete_project_key( '', '', ) diff --git a/test/services/test_postgresql.py b/test/services/test_postgresql.py index 756a1305..cc8cf4a2 100644 --- a/test/services/test_postgresql.py +++ b/test/services/test_postgresql.py @@ -1,5 +1,6 @@ import json -import requests_mock +import httpx2 +import respx import unittest from appwrite.client import Client @@ -8,30 +9,30 @@ from appwrite.services.postgresql import Postgresql -class PostgresqlServiceTest(unittest.TestCase): +class PostgresqlServiceTest(unittest.IsolatedAsyncioTestCase): - def setUp(self): + async def asyncSetUp(self): self.client = Client() self.postgresql = Postgresql(self.client) - @requests_mock.Mocker() - def test_list(self, m): + async def asyncTearDown(self): + await self.client.aclose() + + @respx.mock + async def test_list(self): data = { "total": 5.0, "databases": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.postgresql.list() + response = await self.postgresql.list() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create(self, m): + @respx.mock + async def test_create(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -80,36 +81,30 @@ def test_create(self, m): "error": "", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.postgresql.create( + response = await self.postgresql.create( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_list_specifications(self, m): + @respx.mock + async def test_list_specifications(self): data = { "specifications": [], "total": 9.0, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.postgresql.list_specifications() + response = await self.postgresql.list_specifications() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get(self, m): + @respx.mock + async def test_get(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -158,19 +153,16 @@ def test_get(self, m): "error": "", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.postgresql.get( + response = await self.postgresql.get( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update(self, m): + @respx.mock + async def test_update(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -219,52 +211,43 @@ def test_update(self, m): "error": "", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.postgresql.update( + response = await self.postgresql.update( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete(self, m): + @respx.mock + async def test_delete(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.postgresql.delete( + response = await self.postgresql.delete( '', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_list_backups(self, m): + @respx.mock + async def test_list_backups(self): data = { "total": 5.0, "backups": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.postgresql.list_backups( + response = await self.postgresql.list_backups( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_backup(self, m): + @respx.mock + async def test_create_backup(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -280,37 +263,31 @@ def test_create_backup(self, m): "error": "", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.postgresql.create_backup( + response = await self.postgresql.create_backup( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_list_backup_policies(self, m): + @respx.mock + async def test_list_backup_policies(self): data = { "total": 5.0, "policies": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.postgresql.list_backup_policies( + response = await self.postgresql.list_backup_policies( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_backup_policy(self, m): + @respx.mock + async def test_create_backup_policy(self): data = { "$id": "5e5ea5c16897e", "name": "Hourly backups", @@ -324,13 +301,10 @@ def test_create_backup_policy(self, m): "enabled": True, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.postgresql.create_backup_policy( + response = await self.postgresql.create_backup_policy( '', '', '', @@ -339,8 +313,8 @@ def test_create_backup_policy(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_backup_policy(self, m): + @respx.mock + async def test_get_backup_policy(self): data = { "$id": "5e5ea5c16897e", "name": "Hourly backups", @@ -354,20 +328,17 @@ def test_get_backup_policy(self, m): "enabled": True, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.postgresql.get_backup_policy( + response = await self.postgresql.get_backup_policy( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_backup_policy(self, m): + @respx.mock + async def test_update_backup_policy(self): data = { "$id": "5e5ea5c16897e", "name": "Hourly backups", @@ -381,36 +352,30 @@ def test_update_backup_policy(self, m): "enabled": True, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.postgresql.update_backup_policy( + response = await self.postgresql.update_backup_policy( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete_backup_policy(self, m): + @respx.mock + async def test_delete_backup_policy(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.postgresql.delete_backup_policy( + response = await self.postgresql.delete_backup_policy( '', '', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_update_backup_storage(self, m): + @respx.mock + async def test_update_backup_storage(self): data = { "provider": "s3", "bucket": "my-backup-bucket", @@ -419,13 +384,10 @@ def test_update_backup_storage(self, m): "endpoint": "https:\/\/minio.example.com", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.postgresql.update_backup_storage( + response = await self.postgresql.update_backup_storage( '', 's3', '', @@ -434,8 +396,8 @@ def test_update_backup_storage(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_backup(self, m): + @respx.mock + async def test_get_backup(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -451,54 +413,45 @@ def test_get_backup(self, m): "error": "", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.postgresql.get_backup( + response = await self.postgresql.get_backup( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete_backup(self, m): + @respx.mock + async def test_delete_backup(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.postgresql.delete_backup( + response = await self.postgresql.delete_backup( '', '', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_list_branches(self, m): + @respx.mock + async def test_list_branches(self): data = { "total": 2.0, "branches": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.postgresql.list_branches( + response = await self.postgresql.list_branches( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_branch(self, m): + @respx.mock + async def test_create_branch(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -547,19 +500,16 @@ def test_create_branch(self, m): "error": "", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.postgresql.create_branch( + response = await self.postgresql.create_branch( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete_branch(self, m): + @respx.mock + async def test_delete_branch(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -608,20 +558,17 @@ def test_delete_branch(self, m): "error": "", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.postgresql.delete_branch( + response = await self.postgresql.delete_branch( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_credentials(self, m): + @respx.mock + async def test_update_credentials(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -633,19 +580,16 @@ def test_update_credentials(self, m): "errorMessage": "", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.postgresql.update_credentials( + response = await self.postgresql.update_credentials( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_execution(self, m): + @respx.mock + async def test_create_execution(self): data = { "rows": [], "rowCount": 1.0, @@ -655,39 +599,33 @@ def test_create_execution(self, m): "bytes": 1024.0, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.postgresql.create_execution( + response = await self.postgresql.create_execution( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_list_extensions(self, m): + @respx.mock + async def test_list_extensions(self): data = { "installed": [], "available": [], "metadata": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.postgresql.list_extensions( + response = await self.postgresql.list_extensions( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_extension(self, m): + @respx.mock + async def test_create_extension(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -736,20 +674,17 @@ def test_create_extension(self, m): "error": "", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.postgresql.create_extension( + response = await self.postgresql.create_extension( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete_extension(self, m): + @respx.mock + async def test_delete_extension(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -798,20 +733,17 @@ def test_delete_extension(self, m): "error": "", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.postgresql.delete_extension( + response = await self.postgresql.delete_extension( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_failover(self, m): + @respx.mock + async def test_create_failover(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -860,19 +792,16 @@ def test_create_failover(self, m): "error": "", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.postgresql.create_failover( + response = await self.postgresql.create_failover( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_maintenance(self, m): + @respx.mock + async def test_update_maintenance(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -921,21 +850,18 @@ def test_update_maintenance(self, m): "error": "", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.postgresql.update_maintenance( + response = await self.postgresql.update_maintenance( '', 'sun', 1, ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_migration(self, m): + @respx.mock + async def test_create_migration(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -984,56 +910,47 @@ def test_create_migration(self, m): "error": "", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.postgresql.create_migration( + response = await self.postgresql.create_migration( '', 'shared', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_list_operations(self, m): + @respx.mock + async def test_list_operations(self): data = { "total": 5.0, "operations": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.postgresql.list_operations( + response = await self.postgresql.list_operations( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_pitr(self, m): + @respx.mock + async def test_get_pitr(self): data = { "earliest": "2020-10-15T06:38:00.000+00:00", "latest": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.postgresql.get_pitr( + response = await self.postgresql.get_pitr( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_pooler(self, m): + @respx.mock + async def test_get_pooler(self): data = { "enabled": True, "mode": "transaction", @@ -1047,19 +964,16 @@ def test_get_pooler(self, m): "poolerMemoryLimit": "128Mi", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.postgresql.get_pooler( + response = await self.postgresql.get_pooler( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_pooler(self, m): + @respx.mock + async def test_update_pooler(self): data = { "enabled": True, "mode": "transaction", @@ -1073,19 +987,16 @@ def test_update_pooler(self, m): "poolerMemoryLimit": "128Mi", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.postgresql.update_pooler( + response = await self.postgresql.update_pooler( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_replicas(self, m): + @respx.mock + async def test_get_replicas(self): data = { "replicas": 2.0, "syncMode": "async", @@ -1095,37 +1006,31 @@ def test_get_replicas(self, m): "members": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.postgresql.get_replicas( + response = await self.postgresql.get_replicas( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_list_restorations(self, m): + @respx.mock + async def test_list_restorations(self): data = { "total": 5.0, "restorations": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.postgresql.list_restorations( + response = await self.postgresql.list_restorations( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_restoration(self, m): + @respx.mock + async def test_create_restoration(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -1137,19 +1042,16 @@ def test_create_restoration(self, m): "error": "", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.postgresql.create_restoration( + response = await self.postgresql.create_restoration( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_restoration(self, m): + @respx.mock + async def test_get_restoration(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -1161,20 +1063,17 @@ def test_get_restoration(self, m): "error": "", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.postgresql.get_restoration( + response = await self.postgresql.get_restoration( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_promote_restoration(self, m): + @respx.mock + async def test_promote_restoration(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -1186,20 +1085,17 @@ def test_promote_restoration(self, m): "error": "", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.postgresql.promote_restoration( + response = await self.postgresql.promote_restoration( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_status(self, m): + @respx.mock + async def test_get_status(self): data = { "health": "healthy", "ready": True, @@ -1214,19 +1110,16 @@ def test_get_status(self, m): "volumes": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.postgresql.get_status( + response = await self.postgresql.get_status( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_upgrade(self, m): + @respx.mock + async def test_create_upgrade(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -1275,13 +1168,10 @@ def test_create_upgrade(self, m): "error": "", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.postgresql.create_upgrade( + response = await self.postgresql.create_upgrade( '', '', ) diff --git a/test/services/test_presences.py b/test/services/test_presences.py index 709ebb15..6978a262 100644 --- a/test/services/test_presences.py +++ b/test/services/test_presences.py @@ -1,5 +1,6 @@ import json -import requests_mock +import httpx2 +import respx import unittest from appwrite.client import Client @@ -8,30 +9,30 @@ from appwrite.services.presences import Presences -class PresencesServiceTest(unittest.TestCase): +class PresencesServiceTest(unittest.IsolatedAsyncioTestCase): - def setUp(self): + async def asyncSetUp(self): self.client = Client() self.presences = Presences(self.client) - @requests_mock.Mocker() - def test_list(self, m): + async def asyncTearDown(self): + await self.client.aclose() + + @respx.mock + async def test_list(self): data = { "total": 5.0, "presences": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.presences.list() + response = await self.presences.list() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get(self, m): + @respx.mock + async def test_get(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -41,19 +42,16 @@ def test_get(self, m): "source": "HTTP", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.presences.get( + response = await self.presences.get( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_upsert(self, m): + @respx.mock + async def test_upsert(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -63,21 +61,18 @@ def test_upsert(self, m): "source": "HTTP", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.presences.upsert( + response = await self.presences.upsert( '', '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update(self, m): + @respx.mock + async def test_update(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -87,29 +82,23 @@ def test_update(self, m): "source": "HTTP", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.presences.update( + response = await self.presences.update( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete(self, m): + @respx.mock + async def test_delete(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.presences.delete( + response = await self.presences.delete( '', ) self.assertEqual(response, data) diff --git a/test/services/test_project.py b/test/services/test_project.py index d0c94701..788e015d 100644 --- a/test/services/test_project.py +++ b/test/services/test_project.py @@ -1,5 +1,6 @@ import json -import requests_mock +import httpx2 +import respx import unittest from appwrite.client import Client @@ -8,14 +9,17 @@ from appwrite.services.project import Project -class ProjectServiceTest(unittest.TestCase): +class ProjectServiceTest(unittest.IsolatedAsyncioTestCase): - def setUp(self): + async def asyncSetUp(self): self.client = Client() self.project = Project(self.client) - @requests_mock.Mocker() - def test_get(self, m): + async def asyncTearDown(self): + await self.client.aclose() + + @respx.mock + async def test_get(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -45,30 +49,24 @@ def test_get(self, m): "consoleAccessedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.get() + response = await self.project.get() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete(self, m): + @respx.mock + async def test_delete(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.delete() + response = await self.project.delete() self.assertEqual(response, data) - @requests_mock.Mocker() - def test_update_auth_method(self, m): + @respx.mock + async def test_update_auth_method(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -98,36 +96,30 @@ def test_update_auth_method(self, m): "consoleAccessedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.update_auth_method( + response = await self.project.update_auth_method( 'email-password', True, ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_list_environments(self, m): + @respx.mock + async def test_list_environments(self): data = { "total": 5.0, "projects": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.list_environments() + response = await self.project.list_environments() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_environment(self, m): + @respx.mock + async def test_create_environment(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -157,20 +149,17 @@ def test_create_environment(self, m): "consoleAccessedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.create_environment( + response = await self.project.create_environment( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_environment(self, m): + @respx.mock + async def test_get_environment(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -200,19 +189,16 @@ def test_get_environment(self, m): "consoleAccessedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.get_environment( + response = await self.project.get_environment( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_environment(self, m): + @respx.mock + async def test_update_environment(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -242,51 +228,42 @@ def test_update_environment(self, m): "consoleAccessedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.update_environment( + response = await self.project.update_environment( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete_environment(self, m): + @respx.mock + async def test_delete_environment(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.delete_environment( + response = await self.project.delete_environment( '', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_list_keys(self, m): + @respx.mock + async def test_list_keys(self): data = { "total": 5.0, "keys": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.list_keys() + response = await self.project.list_keys() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_ephemeral_key(self, m): + @respx.mock + async def test_create_ephemeral_key(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -300,20 +277,17 @@ def test_create_ephemeral_key(self, m): "sdks": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.create_ephemeral_key( + response = await self.project.create_ephemeral_key( [], 1, ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_key(self, m): + @respx.mock + async def test_get_key(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -327,19 +301,16 @@ def test_get_key(self, m): "sdks": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.get_key( + response = await self.project.get_key( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_key(self, m): + @respx.mock + async def test_update_key(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -353,36 +324,30 @@ def test_update_key(self, m): "sdks": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.update_key( + response = await self.project.update_key( '', '', [], ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete_key(self, m): + @respx.mock + async def test_delete_key(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.delete_key( + response = await self.project.delete_key( '', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_update_labels(self, m): + @respx.mock + async def test_update_labels(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -412,35 +377,29 @@ def test_update_labels(self, m): "consoleAccessedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.update_labels( + response = await self.project.update_labels( [], ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_list_mock_phones(self, m): + @respx.mock + async def test_list_mock_phones(self): data = { "total": 5.0, "mockNumbers": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.list_mock_phones() + response = await self.project.list_mock_phones() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_mock_phone(self, m): + @respx.mock + async def test_create_mock_phone(self): data = { "number": "+1612842323", "otp": "123456", @@ -448,20 +407,17 @@ def test_create_mock_phone(self, m): "$updatedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.create_mock_phone( + response = await self.project.create_mock_phone( '+12065550100', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_mock_phone(self, m): + @respx.mock + async def test_get_mock_phone(self): data = { "number": "+1612842323", "otp": "123456", @@ -469,19 +425,16 @@ def test_get_mock_phone(self, m): "$updatedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.get_mock_phone( + response = await self.project.get_mock_phone( '+12065550100', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_mock_phone(self, m): + @respx.mock + async def test_update_mock_phone(self): data = { "number": "+1612842323", "otp": "123456", @@ -489,51 +442,42 @@ def test_update_mock_phone(self, m): "$updatedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.update_mock_phone( + response = await self.project.update_mock_phone( '+12065550100', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete_mock_phone(self, m): + @respx.mock + async def test_delete_mock_phone(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.delete_mock_phone( + response = await self.project.delete_mock_phone( '+12065550100', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_list_o_auth2_providers(self, m): + @respx.mock + async def test_list_o_auth2_providers(self): data = { "total": 5.0, "providers": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.list_o_auth2_providers() + response = await self.project.list_o_auth2_providers() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_o_auth2_server(self, m): + @respx.mock + async def test_update_o_auth2_server(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -563,20 +507,17 @@ def test_update_o_auth2_server(self, m): "consoleAccessedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.update_o_auth2_server( + response = await self.project.update_o_auth2_server( True, 'https://example.com', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_o_auth2_amazon(self, m): + @respx.mock + async def test_update_o_auth2_amazon(self): data = { "$id": "github", "enabled": True, @@ -584,17 +525,14 @@ def test_update_o_auth2_amazon(self, m): "clientSecret": "79ffe4000000000000000000000000000000000000000000000000000002de55", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.update_o_auth2_amazon() + response = await self.project.update_o_auth2_amazon() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_o_auth2_apple(self, m): + @respx.mock + async def test_update_o_auth2_apple(self): data = { "$id": "apple", "enabled": True, @@ -606,17 +544,14 @@ def test_update_o_auth2_apple(self, m): "nativeClientIds": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.update_o_auth2_apple() + response = await self.project.update_o_auth2_apple() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_o_auth2_appwrite(self, m): + @respx.mock + async def test_update_o_auth2_appwrite(self): data = { "$id": "github", "enabled": True, @@ -624,17 +559,14 @@ def test_update_o_auth2_appwrite(self, m): "clientSecret": "b86afd000000000000000000000000000000000000000000000000000ced5f93", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.update_o_auth2_appwrite() + response = await self.project.update_o_auth2_appwrite() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_o_auth2_auth0(self, m): + @respx.mock + async def test_update_o_auth2_auth0(self): data = { "$id": "github", "enabled": True, @@ -644,17 +576,14 @@ def test_update_o_auth2_auth0(self, m): "endpoint": "example.us.auth0.com", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.update_o_auth2_auth0() + response = await self.project.update_o_auth2_auth0() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_o_auth2_authentik(self, m): + @respx.mock + async def test_update_o_auth2_authentik(self): data = { "$id": "github", "enabled": True, @@ -663,17 +592,14 @@ def test_update_o_auth2_authentik(self, m): "endpoint": "example.authentik.com", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.update_o_auth2_authentik() + response = await self.project.update_o_auth2_authentik() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_o_auth2_autodesk(self, m): + @respx.mock + async def test_update_o_auth2_autodesk(self): data = { "$id": "github", "enabled": True, @@ -681,17 +607,14 @@ def test_update_o_auth2_autodesk(self, m): "clientSecret": "7I000000000000MW", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.update_o_auth2_autodesk() + response = await self.project.update_o_auth2_autodesk() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_o_auth2_bitbucket(self, m): + @respx.mock + async def test_update_o_auth2_bitbucket(self): data = { "$id": "github", "enabled": True, @@ -699,17 +622,14 @@ def test_update_o_auth2_bitbucket(self, m): "secret": "NMfLZJ00000000000000000000TLQdDx", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.update_o_auth2_bitbucket() + response = await self.project.update_o_auth2_bitbucket() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_o_auth2_bitly(self, m): + @respx.mock + async def test_update_o_auth2_bitly(self): data = { "$id": "github", "enabled": True, @@ -717,17 +637,14 @@ def test_update_o_auth2_bitly(self, m): "clientSecret": "a13e250000000000000000000000000000d73095", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.update_o_auth2_bitly() + response = await self.project.update_o_auth2_bitly() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_o_auth2_box(self, m): + @respx.mock + async def test_update_o_auth2_box(self): data = { "$id": "github", "enabled": True, @@ -735,17 +652,14 @@ def test_update_o_auth2_box(self, m): "clientSecret": "OKM1f100000000000000000000eshEif", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.update_o_auth2_box() + response = await self.project.update_o_auth2_box() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_o_auth2_cloudflare(self, m): + @respx.mock + async def test_update_o_auth2_cloudflare(self): data = { "$id": "github", "enabled": True, @@ -753,17 +667,14 @@ def test_update_o_auth2_cloudflare(self, m): "clientSecret": "cfoc_5Q6YRl0000000000000000000000000000000000003d214f", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.update_o_auth2_cloudflare() + response = await self.project.update_o_auth2_cloudflare() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_o_auth2_dailymotion(self, m): + @respx.mock + async def test_update_o_auth2_dailymotion(self): data = { "$id": "github", "enabled": True, @@ -771,17 +682,14 @@ def test_update_o_auth2_dailymotion(self, m): "apiSecret": "a399a90000000000000000000000000000d90639", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.update_o_auth2_dailymotion() + response = await self.project.update_o_auth2_dailymotion() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_o_auth2_discord(self, m): + @respx.mock + async def test_update_o_auth2_discord(self): data = { "$id": "github", "enabled": True, @@ -790,17 +698,14 @@ def test_update_o_auth2_discord(self, m): "prompt": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.update_o_auth2_discord() + response = await self.project.update_o_auth2_discord() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_o_auth2_disqus(self, m): + @respx.mock + async def test_update_o_auth2_disqus(self): data = { "$id": "github", "enabled": True, @@ -808,17 +713,14 @@ def test_update_o_auth2_disqus(self, m): "secretKey": "W7Bykj00000000000000000000000000000000000000000000000000003o43w9", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.update_o_auth2_disqus() + response = await self.project.update_o_auth2_disqus() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_o_auth2_dropbox(self, m): + @respx.mock + async def test_update_o_auth2_dropbox(self): data = { "$id": "github", "enabled": True, @@ -826,17 +728,14 @@ def test_update_o_auth2_dropbox(self, m): "appSecret": "g200000000000vw", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.update_o_auth2_dropbox() + response = await self.project.update_o_auth2_dropbox() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_o_auth2_etsy(self, m): + @respx.mock + async def test_update_o_auth2_etsy(self): data = { "$id": "github", "enabled": True, @@ -844,17 +743,14 @@ def test_update_o_auth2_etsy(self, m): "sharedSecret": "tp000000ru", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.update_o_auth2_etsy() + response = await self.project.update_o_auth2_etsy() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_o_auth2_facebook(self, m): + @respx.mock + async def test_update_o_auth2_facebook(self): data = { "$id": "github", "enabled": True, @@ -862,17 +758,14 @@ def test_update_o_auth2_facebook(self, m): "appSecret": "2d0b2800000000000000000000d38af4", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.update_o_auth2_facebook() + response = await self.project.update_o_auth2_facebook() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_o_auth2_figma(self, m): + @respx.mock + async def test_update_o_auth2_figma(self): data = { "$id": "github", "enabled": True, @@ -880,17 +773,14 @@ def test_update_o_auth2_figma(self, m): "clientSecret": "yEpOYn0000000000000000004iIsU5", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.update_o_auth2_figma() + response = await self.project.update_o_auth2_figma() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_o_auth2_fusion_auth(self, m): + @respx.mock + async def test_update_o_auth2_fusion_auth(self): data = { "$id": "github", "enabled": True, @@ -899,17 +789,14 @@ def test_update_o_auth2_fusion_auth(self, m): "endpoint": "example.fusionauth.io", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.update_o_auth2_fusion_auth() + response = await self.project.update_o_auth2_fusion_auth() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_o_auth2_git_hub(self, m): + @respx.mock + async def test_update_o_auth2_git_hub(self): data = { "$id": "github", "enabled": True, @@ -918,17 +805,14 @@ def test_update_o_auth2_git_hub(self, m): "prompt": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.update_o_auth2_git_hub() + response = await self.project.update_o_auth2_git_hub() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_o_auth2_gitlab(self, m): + @respx.mock + async def test_update_o_auth2_gitlab(self): data = { "$id": "github", "enabled": True, @@ -937,17 +821,14 @@ def test_update_o_auth2_gitlab(self, m): "endpoint": "https:\/\/gitlab.com", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.update_o_auth2_gitlab() + response = await self.project.update_o_auth2_gitlab() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_o_auth2_google(self, m): + @respx.mock + async def test_update_o_auth2_google(self): data = { "$id": "github", "enabled": True, @@ -958,17 +839,14 @@ def test_update_o_auth2_google(self, m): "nativeClientIds": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.update_o_auth2_google() + response = await self.project.update_o_auth2_google() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_o_auth2_hugging_face(self, m): + @respx.mock + async def test_update_o_auth2_hugging_face(self): data = { "$id": "github", "enabled": True, @@ -976,17 +854,14 @@ def test_update_o_auth2_hugging_face(self, m): "clientSecret": "oauth_app_secret_wcLhRtl000000000000000000000xbNdLt", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.update_o_auth2_hugging_face() + response = await self.project.update_o_auth2_hugging_face() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_o_auth2_kakao(self, m): + @respx.mock + async def test_update_o_auth2_kakao(self): data = { "$id": "github", "enabled": True, @@ -995,17 +870,14 @@ def test_update_o_auth2_kakao(self, m): "prompt": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.update_o_auth2_kakao() + response = await self.project.update_o_auth2_kakao() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_o_auth2_keycloak(self, m): + @respx.mock + async def test_update_o_auth2_keycloak(self): data = { "$id": "github", "enabled": True, @@ -1015,17 +887,14 @@ def test_update_o_auth2_keycloak(self, m): "realmName": "appwrite-realm", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.update_o_auth2_keycloak() + response = await self.project.update_o_auth2_keycloak() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_o_auth2_kick(self, m): + @respx.mock + async def test_update_o_auth2_kick(self): data = { "$id": "github", "enabled": True, @@ -1033,17 +902,14 @@ def test_update_o_auth2_kick(self, m): "clientSecret": "34ac5600000000000000000000000000000000000000000000000000e830c8b", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.update_o_auth2_kick() + response = await self.project.update_o_auth2_kick() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_o_auth2_linkedin(self, m): + @respx.mock + async def test_update_o_auth2_linkedin(self): data = { "$id": "github", "enabled": True, @@ -1051,17 +917,14 @@ def test_update_o_auth2_linkedin(self, m): "primaryClientSecret": "WPL_AP1.2Bf0000000000000.\/HtlYw==", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.update_o_auth2_linkedin() + response = await self.project.update_o_auth2_linkedin() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_o_auth2_microsoft(self, m): + @respx.mock + async def test_update_o_auth2_microsoft(self): data = { "$id": "github", "enabled": True, @@ -1071,17 +934,14 @@ def test_update_o_auth2_microsoft(self, m): "tenant": "common", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.update_o_auth2_microsoft() + response = await self.project.update_o_auth2_microsoft() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_o_auth2_notion(self, m): + @respx.mock + async def test_update_o_auth2_notion(self): data = { "$id": "github", "enabled": True, @@ -1089,17 +949,14 @@ def test_update_o_auth2_notion(self, m): "oauthClientSecret": "secret_dLUr4b000000000000000000000000000000lFHAa9", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.update_o_auth2_notion() + response = await self.project.update_o_auth2_notion() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_o_auth2_oidc(self, m): + @respx.mock + async def test_update_o_auth2_oidc(self): data = { "$id": "github", "enabled": True, @@ -1112,17 +969,14 @@ def test_update_o_auth2_oidc(self, m): "userInfoURL": "https:\/\/myoauth.com\/oauth2\/userinfo", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.update_o_auth2_oidc() + response = await self.project.update_o_auth2_oidc() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_o_auth2_okta(self, m): + @respx.mock + async def test_update_o_auth2_okta(self): data = { "$id": "github", "enabled": True, @@ -1133,17 +987,14 @@ def test_update_o_auth2_okta(self, m): "authorizationServerId": "aus000000000000000h7z", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.update_o_auth2_okta() + response = await self.project.update_o_auth2_okta() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_o_auth2_paypal(self, m): + @respx.mock + async def test_update_o_auth2_paypal(self): data = { "$id": "github", "enabled": True, @@ -1151,17 +1002,14 @@ def test_update_o_auth2_paypal(self, m): "secretKey": "EH8KCXtew--000000000000000000000000000000000000000_C-1_5UP_000000000000000CB7KDp", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.update_o_auth2_paypal() + response = await self.project.update_o_auth2_paypal() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_o_auth2_paypal_sandbox(self, m): + @respx.mock + async def test_update_o_auth2_paypal_sandbox(self): data = { "$id": "github", "enabled": True, @@ -1169,17 +1017,14 @@ def test_update_o_auth2_paypal_sandbox(self, m): "secretKey": "EH8KCXtew--000000000000000000000000000000000000000_C-1_5UP_000000000000000CB7KDp", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.update_o_auth2_paypal_sandbox() + response = await self.project.update_o_auth2_paypal_sandbox() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_o_auth2_podio(self, m): + @respx.mock + async def test_update_o_auth2_podio(self): data = { "$id": "github", "enabled": True, @@ -1187,17 +1032,14 @@ def test_update_o_auth2_podio(self, m): "clientSecret": "Rn247T0000000000000000000000000000000000000000000000000000W2zWTN", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.update_o_auth2_podio() + response = await self.project.update_o_auth2_podio() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_o_auth2_resend(self, m): + @respx.mock + async def test_update_o_auth2_resend(self): data = { "$id": "github", "enabled": True, @@ -1205,17 +1047,14 @@ def test_update_o_auth2_resend(self, m): "clientSecret": "9c1e4b00000000000000000000000000000000000000000000000000a72d5f4", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.update_o_auth2_resend() + response = await self.project.update_o_auth2_resend() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_o_auth2_salesforce(self, m): + @respx.mock + async def test_update_o_auth2_salesforce(self): data = { "$id": "github", "enabled": True, @@ -1224,17 +1063,14 @@ def test_update_o_auth2_salesforce(self, m): "prompt": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.update_o_auth2_salesforce() + response = await self.project.update_o_auth2_salesforce() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_o_auth2_slack(self, m): + @respx.mock + async def test_update_o_auth2_slack(self): data = { "$id": "github", "enabled": True, @@ -1242,17 +1078,14 @@ def test_update_o_auth2_slack(self, m): "clientSecret": "81656000000000000000000000f3d2fd", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.update_o_auth2_slack() + response = await self.project.update_o_auth2_slack() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_o_auth2_spotify(self, m): + @respx.mock + async def test_update_o_auth2_spotify(self): data = { "$id": "github", "enabled": True, @@ -1260,17 +1093,14 @@ def test_update_o_auth2_spotify(self, m): "clientSecret": "db068a000000000000000000008b5b9f", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.update_o_auth2_spotify() + response = await self.project.update_o_auth2_spotify() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_o_auth2_stripe(self, m): + @respx.mock + async def test_update_o_auth2_stripe(self): data = { "$id": "github", "enabled": True, @@ -1278,17 +1108,14 @@ def test_update_o_auth2_stripe(self, m): "apiSecretKey": "sk_51SfOd000000000000000000000000000000000000000000000000000000000000000000000000000000000000000QGWYfp", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.update_o_auth2_stripe() + response = await self.project.update_o_auth2_stripe() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_o_auth2_tik_tok(self, m): + @respx.mock + async def test_update_o_auth2_tik_tok(self): data = { "$id": "github", "enabled": True, @@ -1296,17 +1123,14 @@ def test_update_o_auth2_tik_tok(self, m): "clientSecret": "6wXewM00000000000000000000yXnite", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.update_o_auth2_tik_tok() + response = await self.project.update_o_auth2_tik_tok() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_o_auth2_tradeshift(self, m): + @respx.mock + async def test_update_o_auth2_tradeshift(self): data = { "$id": "github", "enabled": True, @@ -1314,17 +1138,14 @@ def test_update_o_auth2_tradeshift(self, m): "oauth2ClientSecret": "7cb52700-0000-0000-0000-000000ca5b83", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.update_o_auth2_tradeshift() + response = await self.project.update_o_auth2_tradeshift() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_o_auth2_tradeshift_sandbox(self, m): + @respx.mock + async def test_update_o_auth2_tradeshift_sandbox(self): data = { "$id": "github", "enabled": True, @@ -1332,17 +1153,14 @@ def test_update_o_auth2_tradeshift_sandbox(self, m): "oauth2ClientSecret": "7cb52700-0000-0000-0000-000000ca5b83", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.update_o_auth2_tradeshift_sandbox() + response = await self.project.update_o_auth2_tradeshift_sandbox() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_o_auth2_twitch(self, m): + @respx.mock + async def test_update_o_auth2_twitch(self): data = { "$id": "github", "enabled": True, @@ -1350,17 +1168,14 @@ def test_update_o_auth2_twitch(self, m): "clientSecret": "pmapue000000000000000000zylw3v", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.update_o_auth2_twitch() + response = await self.project.update_o_auth2_twitch() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_o_auth2_webflow(self, m): + @respx.mock + async def test_update_o_auth2_webflow(self): data = { "$id": "github", "enabled": True, @@ -1368,17 +1183,14 @@ def test_update_o_auth2_webflow(self, m): "clientSecret": "59bf00000000000000000000000000000000000000000000000000000000fe59", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.update_o_auth2_webflow() + response = await self.project.update_o_auth2_webflow() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_o_auth2_word_press(self, m): + @respx.mock + async def test_update_o_auth2_word_press(self): data = { "$id": "github", "enabled": True, @@ -1386,17 +1198,14 @@ def test_update_o_auth2_word_press(self, m): "clientSecret": "PlBfJS0000000000000000000000000000000000000000000000000000EdUZJk", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.update_o_auth2_word_press() + response = await self.project.update_o_auth2_word_press() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_o_auth2_x(self, m): + @respx.mock + async def test_update_o_auth2_x(self): data = { "$id": "github", "enabled": True, @@ -1404,17 +1213,14 @@ def test_update_o_auth2_x(self, m): "secretKey": "tkEPkp00000000000000000000000000000000000000FTxbI9", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.update_o_auth2_x() + response = await self.project.update_o_auth2_x() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_o_auth2_yahoo(self, m): + @respx.mock + async def test_update_o_auth2_yahoo(self): data = { "$id": "github", "enabled": True, @@ -1422,17 +1228,14 @@ def test_update_o_auth2_yahoo(self, m): "clientSecret": "cf978f0000000000000000000000000000c5e2e9", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.update_o_auth2_yahoo() + response = await self.project.update_o_auth2_yahoo() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_o_auth2_yandex(self, m): + @respx.mock + async def test_update_o_auth2_yandex(self): data = { "$id": "github", "enabled": True, @@ -1440,17 +1243,14 @@ def test_update_o_auth2_yandex(self, m): "clientSecret": "bbf98500000000000000000000c75a63", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.update_o_auth2_yandex() + response = await self.project.update_o_auth2_yandex() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_o_auth2_zoho(self, m): + @respx.mock + async def test_update_o_auth2_zoho(self): data = { "$id": "github", "enabled": True, @@ -1459,17 +1259,14 @@ def test_update_o_auth2_zoho(self, m): "prompt": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.update_o_auth2_zoho() + response = await self.project.update_o_auth2_zoho() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_o_auth2_zoom(self, m): + @respx.mock + async def test_update_o_auth2_zoom(self): data = { "$id": "github", "enabled": True, @@ -1477,17 +1274,14 @@ def test_update_o_auth2_zoom(self, m): "clientSecret": "GAWsG4000000000000000000007U01ON", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.update_o_auth2_zoom() + response = await self.project.update_o_auth2_zoom() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_o_auth2_provider(self, m): + @respx.mock + async def test_get_o_auth2_provider(self): data = { "$id": "github", "enabled": True, @@ -1496,35 +1290,29 @@ def test_get_o_auth2_provider(self, m): "prompt": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.get_o_auth2_provider( + response = await self.project.get_o_auth2_provider( 'amazon', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_list_platforms(self, m): + @respx.mock + async def test_list_platforms(self): data = { "total": 5.0, "platforms": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.list_platforms() + response = await self.project.list_platforms() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_android_platform(self, m): + @respx.mock + async def test_create_android_platform(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -1535,21 +1323,18 @@ def test_create_android_platform(self, m): "fingerprints": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.create_android_platform( + response = await self.project.create_android_platform( '', '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_android_platform(self, m): + @respx.mock + async def test_update_android_platform(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -1560,21 +1345,18 @@ def test_update_android_platform(self, m): "fingerprints": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.update_android_platform( + response = await self.project.update_android_platform( '', '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_apple_platform(self, m): + @respx.mock + async def test_create_apple_platform(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -1584,21 +1366,18 @@ def test_create_apple_platform(self, m): "bundleIdentifier": "com.company.appname", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.create_apple_platform( + response = await self.project.create_apple_platform( '', '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_apple_platform(self, m): + @respx.mock + async def test_update_apple_platform(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -1608,21 +1387,18 @@ def test_update_apple_platform(self, m): "bundleIdentifier": "com.company.appname", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.update_apple_platform( + response = await self.project.update_apple_platform( '', '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_linux_platform(self, m): + @respx.mock + async def test_create_linux_platform(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -1632,21 +1408,18 @@ def test_create_linux_platform(self, m): "packageName": "com.company.appname", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.create_linux_platform( + response = await self.project.create_linux_platform( '', '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_linux_platform(self, m): + @respx.mock + async def test_update_linux_platform(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -1656,21 +1429,18 @@ def test_update_linux_platform(self, m): "packageName": "com.company.appname", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.update_linux_platform( + response = await self.project.update_linux_platform( '', '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_web_platform(self, m): + @respx.mock + async def test_create_web_platform(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -1680,21 +1450,18 @@ def test_create_web_platform(self, m): "hostname": "app.example.com", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.create_web_platform( + response = await self.project.create_web_platform( '', '', 'app.example.com', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_web_platform(self, m): + @respx.mock + async def test_update_web_platform(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -1704,21 +1471,18 @@ def test_update_web_platform(self, m): "hostname": "app.example.com", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.update_web_platform( + response = await self.project.update_web_platform( '', '', 'app.example.com', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_windows_platform(self, m): + @respx.mock + async def test_create_windows_platform(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -1728,21 +1492,18 @@ def test_create_windows_platform(self, m): "packageIdentifierName": "com.company.appname", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.create_windows_platform( + response = await self.project.create_windows_platform( '', '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_windows_platform(self, m): + @respx.mock + async def test_update_windows_platform(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -1752,21 +1513,18 @@ def test_update_windows_platform(self, m): "packageIdentifierName": "com.company.appname", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.update_windows_platform( + response = await self.project.update_windows_platform( '', '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_platform(self, m): + @respx.mock + async def test_get_platform(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -1776,50 +1534,41 @@ def test_get_platform(self, m): "hostname": "app.example.com", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.get_platform( + response = await self.project.get_platform( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete_platform(self, m): + @respx.mock + async def test_delete_platform(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.delete_platform( + response = await self.project.delete_platform( '', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_list_policies(self, m): + @respx.mock + async def test_list_policies(self): data = { "total": 10.0, "policies": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.list_policies() + response = await self.project.list_policies() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_deny_aliased_email_policy(self, m): + @respx.mock + async def test_update_deny_aliased_email_policy(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -1849,19 +1598,16 @@ def test_update_deny_aliased_email_policy(self, m): "consoleAccessedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.update_deny_aliased_email_policy( + response = await self.project.update_deny_aliased_email_policy( True, ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_deny_corporate_email_policy(self, m): + @respx.mock + async def test_update_deny_corporate_email_policy(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -1891,19 +1637,16 @@ def test_update_deny_corporate_email_policy(self, m): "consoleAccessedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.update_deny_corporate_email_policy( + response = await self.project.update_deny_corporate_email_policy( True, ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_deny_disposable_email_policy(self, m): + @respx.mock + async def test_update_deny_disposable_email_policy(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -1933,19 +1676,16 @@ def test_update_deny_disposable_email_policy(self, m): "consoleAccessedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.update_deny_disposable_email_policy( + response = await self.project.update_deny_disposable_email_policy( True, ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_deny_free_email_policy(self, m): + @respx.mock + async def test_update_deny_free_email_policy(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -1975,19 +1715,16 @@ def test_update_deny_free_email_policy(self, m): "consoleAccessedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.update_deny_free_email_policy( + response = await self.project.update_deny_free_email_policy( True, ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_membership_privacy_policy(self, m): + @respx.mock + async def test_update_membership_privacy_policy(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -2017,17 +1754,14 @@ def test_update_membership_privacy_policy(self, m): "consoleAccessedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.update_membership_privacy_policy() + response = await self.project.update_membership_privacy_policy() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_mfa_factors_policy(self, m): + @respx.mock + async def test_update_mfa_factors_policy(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -2057,17 +1791,14 @@ def test_update_mfa_factors_policy(self, m): "consoleAccessedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.update_mfa_factors_policy() + response = await self.project.update_mfa_factors_policy() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_passkey_policy(self, m): + @respx.mock + async def test_update_passkey_policy(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -2097,19 +1828,16 @@ def test_update_passkey_policy(self, m): "consoleAccessedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.update_passkey_policy( + response = await self.project.update_passkey_policy( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_password_dictionary_policy(self, m): + @respx.mock + async def test_update_password_dictionary_policy(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -2139,19 +1867,16 @@ def test_update_password_dictionary_policy(self, m): "consoleAccessedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.update_password_dictionary_policy( + response = await self.project.update_password_dictionary_policy( True, ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_password_history_policy(self, m): + @respx.mock + async def test_update_password_history_policy(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -2181,19 +1906,16 @@ def test_update_password_history_policy(self, m): "consoleAccessedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.update_password_history_policy( + response = await self.project.update_password_history_policy( 1, ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_password_personal_data_policy(self, m): + @respx.mock + async def test_update_password_personal_data_policy(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -2223,19 +1945,16 @@ def test_update_password_personal_data_policy(self, m): "consoleAccessedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.update_password_personal_data_policy( + response = await self.project.update_password_personal_data_policy( True, ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_password_pwned_policy(self, m): + @respx.mock + async def test_update_password_pwned_policy(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -2265,17 +1984,14 @@ def test_update_password_pwned_policy(self, m): "consoleAccessedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.update_password_pwned_policy() + response = await self.project.update_password_pwned_policy() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_password_rotation_policy(self, m): + @respx.mock + async def test_update_password_rotation_policy(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -2305,17 +2021,14 @@ def test_update_password_rotation_policy(self, m): "consoleAccessedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.update_password_rotation_policy() + response = await self.project.update_password_rotation_policy() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_password_strength_policy(self, m): + @respx.mock + async def test_update_password_strength_policy(self): data = { "$id": "password-dictionary", "min": 12.0, @@ -2325,17 +2038,14 @@ def test_update_password_strength_policy(self, m): "symbols": True, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.update_password_strength_policy() + response = await self.project.update_password_strength_policy() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_session_alert_policy(self, m): + @respx.mock + async def test_update_session_alert_policy(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -2365,19 +2075,16 @@ def test_update_session_alert_policy(self, m): "consoleAccessedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.update_session_alert_policy( + response = await self.project.update_session_alert_policy( True, ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_session_duration_policy(self, m): + @respx.mock + async def test_update_session_duration_policy(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -2407,19 +2114,16 @@ def test_update_session_duration_policy(self, m): "consoleAccessedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.update_session_duration_policy( + response = await self.project.update_session_duration_policy( 1, ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_session_invalidation_policy(self, m): + @respx.mock + async def test_update_session_invalidation_policy(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -2449,19 +2153,16 @@ def test_update_session_invalidation_policy(self, m): "consoleAccessedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.update_session_invalidation_policy( + response = await self.project.update_session_invalidation_policy( True, ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_session_limit_policy(self, m): + @respx.mock + async def test_update_session_limit_policy(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -2491,19 +2192,16 @@ def test_update_session_limit_policy(self, m): "consoleAccessedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.update_session_limit_policy( + response = await self.project.update_session_limit_policy( 1, ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_user_limit_policy(self, m): + @respx.mock + async def test_update_user_limit_policy(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -2533,38 +2231,32 @@ def test_update_user_limit_policy(self, m): "consoleAccessedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.update_user_limit_policy( + response = await self.project.update_user_limit_policy( 1, ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_policy(self, m): + @respx.mock + async def test_get_policy(self): data = { "$id": "password-dictionary", "enabled": True, "denyList": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.get_policy( + response = await self.project.get_policy( 'password-dictionary', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_protocol(self, m): + @respx.mock + async def test_update_protocol(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -2594,20 +2286,17 @@ def test_update_protocol(self, m): "consoleAccessedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.update_protocol( + response = await self.project.update_protocol( 'rest', True, ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_service(self, m): + @respx.mock + async def test_update_service(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -2637,20 +2326,17 @@ def test_update_service(self, m): "consoleAccessedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.update_service( + response = await self.project.update_service( 'account', True, ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_smtp(self, m): + @respx.mock + async def test_update_smtp(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -2680,48 +2366,39 @@ def test_update_smtp(self, m): "consoleAccessedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.update_smtp() + response = await self.project.update_smtp() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_smtp_test(self, m): + @respx.mock + async def test_create_smtp_test(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.create_smtp_test( + response = await self.project.create_smtp_test( [], ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_list_email_templates(self, m): + @respx.mock + async def test_list_email_templates(self): data = { "total": 5.0, "templates": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.list_email_templates() + response = await self.project.list_email_templates() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_email_template(self, m): + @respx.mock + async def test_update_email_template(self): data = { "templateId": "verification", "locale": "en_us", @@ -2733,19 +2410,16 @@ def test_update_email_template(self, m): "subject": "Please verify your email address", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.update_email_template( + response = await self.project.update_email_template( 'verification', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_email_template(self, m): + @respx.mock + async def test_get_email_template(self): data = { "templateId": "verification", "locale": "en_us", @@ -2757,35 +2431,29 @@ def test_get_email_template(self, m): "subject": "Please verify your email address", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.get_email_template( + response = await self.project.get_email_template( 'verification', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_list_variables(self, m): + @respx.mock + async def test_list_variables(self): data = { "total": 5.0, "variables": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.list_variables() + response = await self.project.list_variables() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_variable(self, m): + @respx.mock + async def test_create_variable(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -2798,21 +2466,18 @@ def test_create_variable(self, m): "resourceId": "myAwesomeFunction", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.create_variable( + response = await self.project.create_variable( '', '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_variable(self, m): + @respx.mock + async def test_get_variable(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -2825,19 +2490,16 @@ def test_get_variable(self, m): "resourceId": "myAwesomeFunction", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.get_variable( + response = await self.project.get_variable( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_variable(self, m): + @respx.mock + async def test_update_variable(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -2850,28 +2512,22 @@ def test_update_variable(self, m): "resourceId": "myAwesomeFunction", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.update_variable( + response = await self.project.update_variable( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete_variable(self, m): + @respx.mock + async def test_delete_variable(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.project.delete_variable( + response = await self.project.delete_variable( '', ) self.assertEqual(response, data) diff --git a/test/services/test_proxy.py b/test/services/test_proxy.py index c12c5271..fa67e4d5 100644 --- a/test/services/test_proxy.py +++ b/test/services/test_proxy.py @@ -1,5 +1,6 @@ import json -import requests_mock +import httpx2 +import respx import unittest from appwrite.client import Client @@ -8,14 +9,17 @@ from appwrite.services.proxy import Proxy -class ProxyServiceTest(unittest.TestCase): +class ProxyServiceTest(unittest.IsolatedAsyncioTestCase): - def setUp(self): + async def asyncSetUp(self): self.client = Client() self.proxy = Proxy(self.client) - @requests_mock.Mocker() - def test_create_invalidation(self, m): + async def asyncTearDown(self): + await self.client.aclose() + + @respx.mock + async def test_create_invalidation(self): data = { "domain": "appwrite.company.com", "type": "tag", @@ -23,36 +27,30 @@ def test_create_invalidation(self, m): "status": "success", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.proxy.create_invalidation( + response = await self.proxy.create_invalidation( 'example.com', 'tag', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_list_rules(self, m): + @respx.mock + async def test_list_rules(self): data = { "total": 5.0, "rules": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.proxy.list_rules() + response = await self.proxy.list_rules() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_api_rule(self, m): + @respx.mock + async def test_create_api_rule(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -71,19 +69,16 @@ def test_create_api_rule(self, m): "protocol": "http", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.proxy.create_api_rule( + response = await self.proxy.create_api_rule( 'example.com', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_function_rule(self, m): + @respx.mock + async def test_create_function_rule(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -102,20 +97,17 @@ def test_create_function_rule(self, m): "protocol": "http", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.proxy.create_function_rule( + response = await self.proxy.create_function_rule( 'example.com', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_redirect_rule(self, m): + @respx.mock + async def test_create_redirect_rule(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -134,13 +126,10 @@ def test_create_redirect_rule(self, m): "protocol": "http", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.proxy.create_redirect_rule( + response = await self.proxy.create_redirect_rule( 'example.com', 'https://example.com', '301', @@ -149,8 +138,8 @@ def test_create_redirect_rule(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_site_rule(self, m): + @respx.mock + async def test_create_site_rule(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -169,20 +158,17 @@ def test_create_site_rule(self, m): "protocol": "http", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.proxy.create_site_rule( + response = await self.proxy.create_site_rule( 'example.com', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_smtp_rule(self, m): + @respx.mock + async def test_create_smtp_rule(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -201,20 +187,17 @@ def test_create_smtp_rule(self, m): "protocol": "http", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.proxy.create_smtp_rule( + response = await self.proxy.create_smtp_rule( 'example.com', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_rule(self, m): + @respx.mock + async def test_get_rule(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -233,34 +216,28 @@ def test_get_rule(self, m): "protocol": "http", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.proxy.get_rule( + response = await self.proxy.get_rule( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete_rule(self, m): + @respx.mock + async def test_delete_rule(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.proxy.delete_rule( + response = await self.proxy.delete_rule( '', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_update_rule_status(self, m): + @respx.mock + async def test_update_rule_status(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -279,13 +256,10 @@ def test_update_rule_status(self, m): "protocol": "http", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.proxy.update_rule_status( + response = await self.proxy.update_rule_status( '', ) self.assertEqual(response.to_dict(), data) diff --git a/test/services/test_sites.py b/test/services/test_sites.py index a1e4354e..4823b1c0 100644 --- a/test/services/test_sites.py +++ b/test/services/test_sites.py @@ -1,5 +1,6 @@ import json -import requests_mock +import httpx2 +import respx import unittest from appwrite.client import Client @@ -8,30 +9,30 @@ from appwrite.services.sites import Sites -class SitesServiceTest(unittest.TestCase): +class SitesServiceTest(unittest.IsolatedAsyncioTestCase): - def setUp(self): + async def asyncSetUp(self): self.client = Client() self.sites = Sites(self.client) - @requests_mock.Mocker() - def test_list(self, m): + async def asyncTearDown(self): + await self.client.aclose() + + @respx.mock + async def test_list(self): data = { "total": 5.0, "sites": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.sites.list() + response = await self.sites.list() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create(self, m): + @respx.mock + async def test_create(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -71,13 +72,10 @@ def test_create(self, m): "fallbackFile": "index.html", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.sites.create( + response = await self.sites.create( '', '', 'analog', @@ -85,40 +83,34 @@ def test_create(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_list_frameworks(self, m): + @respx.mock + async def test_list_frameworks(self): data = { "total": 5.0, "frameworks": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.sites.list_frameworks() + response = await self.sites.list_frameworks() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_list_specifications(self, m): + @respx.mock + async def test_list_specifications(self): data = { "total": 5.0, "specifications": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.sites.list_specifications() + response = await self.sites.list_specifications() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get(self, m): + @respx.mock + async def test_get(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -158,19 +150,16 @@ def test_get(self, m): "fallbackFile": "index.html", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.sites.get( + response = await self.sites.get( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update(self, m): + @respx.mock + async def test_update(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -210,36 +199,30 @@ def test_update(self, m): "fallbackFile": "index.html", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.sites.update( + response = await self.sites.update( '', '', 'analog', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete(self, m): + @respx.mock + async def test_delete(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.sites.delete( + response = await self.sites.delete( '', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_update_site_deployment(self, m): + @respx.mock + async def test_update_site_deployment(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -279,38 +262,32 @@ def test_update_site_deployment(self, m): "fallbackFile": "index.html", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.sites.update_site_deployment( + response = await self.sites.update_site_deployment( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_list_deployments(self, m): + @respx.mock + async def test_list_deployments(self): data = { "total": 5.0, "deployments": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.sites.list_deployments( + response = await self.sites.list_deployments( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_deployment(self, m): + @respx.mock + async def test_create_deployment(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -341,20 +318,17 @@ def test_create_deployment(self, m): "providerBranchUrl": "https:\/\/github.com\/vermakhushboo\/appwrite\/tree\/0.7.x", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.sites.create_deployment( + response = await self.sites.create_deployment( '', InputFile.from_bytes(bytearray(), "example.file"), ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_duplicate_deployment(self, m): + @respx.mock + async def test_create_duplicate_deployment(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -385,20 +359,17 @@ def test_create_duplicate_deployment(self, m): "providerBranchUrl": "https:\/\/github.com\/vermakhushboo\/appwrite\/tree\/0.7.x", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.sites.create_duplicate_deployment( + response = await self.sites.create_duplicate_deployment( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_template_deployment(self, m): + @respx.mock + async def test_create_template_deployment(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -429,13 +400,10 @@ def test_create_template_deployment(self, m): "providerBranchUrl": "https:\/\/github.com\/vermakhushboo\/appwrite\/tree\/0.7.x", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.sites.create_template_deployment( + response = await self.sites.create_template_deployment( '', '', '', @@ -445,8 +413,8 @@ def test_create_template_deployment(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_vcs_deployment(self, m): + @respx.mock + async def test_create_vcs_deployment(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -477,21 +445,18 @@ def test_create_vcs_deployment(self, m): "providerBranchUrl": "https:\/\/github.com\/vermakhushboo\/appwrite\/tree\/0.7.x", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.sites.create_vcs_deployment( + response = await self.sites.create_vcs_deployment( '', 'branch', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_deployment(self, m): + @respx.mock + async def test_get_deployment(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -522,52 +487,43 @@ def test_get_deployment(self, m): "providerBranchUrl": "https:\/\/github.com\/vermakhushboo\/appwrite\/tree\/0.7.x", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.sites.get_deployment( + response = await self.sites.get_deployment( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete_deployment(self, m): + @respx.mock + async def test_delete_deployment(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.sites.delete_deployment( + response = await self.sites.delete_deployment( '', '', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_get_deployment_download(self, m): + @respx.mock + async def test_get_deployment_download(self): data = bytearray() headers = {'Content-Type': 'application/octet-stream'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - body=data, - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, content=bytes(data), headers=headers), ) - response = self.sites.get_deployment_download( + response = await self.sites.get_deployment_download( '', '', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_update_deployment_status(self, m): + @respx.mock + async def test_update_deployment_status(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -598,38 +554,32 @@ def test_update_deployment_status(self, m): "providerBranchUrl": "https:\/\/github.com\/vermakhushboo\/appwrite\/tree\/0.7.x", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.sites.update_deployment_status( + response = await self.sites.update_deployment_status( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_list_logs(self, m): + @respx.mock + async def test_list_logs(self): data = { "total": 5.0, "executions": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.sites.list_logs( + response = await self.sites.list_logs( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_log(self, m): + @respx.mock + async def test_get_log(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -651,54 +601,45 @@ def test_get_log(self, m): "duration": 1.23, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.sites.get_log( + response = await self.sites.get_log( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete_log(self, m): + @respx.mock + async def test_delete_log(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.sites.delete_log( + response = await self.sites.delete_log( '', '', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_list_variables(self, m): + @respx.mock + async def test_list_variables(self): data = { "total": 5.0, "variables": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.sites.list_variables( + response = await self.sites.list_variables( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_variable(self, m): + @respx.mock + async def test_create_variable(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -711,13 +652,10 @@ def test_create_variable(self, m): "resourceId": "myAwesomeFunction", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.sites.create_variable( + response = await self.sites.create_variable( '', '', '', @@ -725,8 +663,8 @@ def test_create_variable(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_variable(self, m): + @respx.mock + async def test_get_variable(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -739,20 +677,17 @@ def test_get_variable(self, m): "resourceId": "myAwesomeFunction", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.sites.get_variable( + response = await self.sites.get_variable( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_variable(self, m): + @respx.mock + async def test_update_variable(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -765,29 +700,23 @@ def test_update_variable(self, m): "resourceId": "myAwesomeFunction", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.sites.update_variable( + response = await self.sites.update_variable( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete_variable(self, m): + @respx.mock + async def test_delete_variable(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.sites.delete_variable( + response = await self.sites.delete_variable( '', '', ) diff --git a/test/services/test_storage.py b/test/services/test_storage.py index 15c0da0a..be64fe73 100644 --- a/test/services/test_storage.py +++ b/test/services/test_storage.py @@ -1,5 +1,6 @@ import json -import requests_mock +import httpx2 +import respx import unittest from appwrite.client import Client @@ -8,30 +9,30 @@ from appwrite.services.storage import Storage -class StorageServiceTest(unittest.TestCase): +class StorageServiceTest(unittest.IsolatedAsyncioTestCase): - def setUp(self): + async def asyncSetUp(self): self.client = Client() self.storage = Storage(self.client) - @requests_mock.Mocker() - def test_list_buckets(self, m): + async def asyncTearDown(self): + await self.client.aclose() + + @respx.mock + async def test_list_buckets(self): data = { "total": 5.0, "buckets": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.storage.list_buckets() + response = await self.storage.list_buckets() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_bucket(self, m): + @respx.mock + async def test_create_bucket(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -51,20 +52,17 @@ def test_create_bucket(self, m): "totalSize": 128.0, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.storage.create_bucket( + response = await self.storage.create_bucket( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_bucket(self, m): + @respx.mock + async def test_get_bucket(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -84,19 +82,16 @@ def test_get_bucket(self, m): "totalSize": 128.0, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.storage.get_bucket( + response = await self.storage.get_bucket( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_bucket(self, m): + @respx.mock + async def test_update_bucket(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -116,53 +111,44 @@ def test_update_bucket(self, m): "totalSize": 128.0, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.storage.update_bucket( + response = await self.storage.update_bucket( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete_bucket(self, m): + @respx.mock + async def test_delete_bucket(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.storage.delete_bucket( + response = await self.storage.delete_bucket( '', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_list_files(self, m): + @respx.mock + async def test_list_files(self): data = { "total": 5.0, "files": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.storage.list_files( + response = await self.storage.list_files( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_file(self, m): + @respx.mock + async def test_create_file(self): data = { "$id": "5e5ea5c16897e", "bucketId": "5e5ea5c16897e", @@ -182,21 +168,18 @@ def test_create_file(self, m): "compression": "gzip", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.storage.create_file( + response = await self.storage.create_file( '', '', InputFile.from_bytes(bytearray(), "example.file"), ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_file(self, m): + @respx.mock + async def test_get_file(self): data = { "$id": "5e5ea5c16897e", "bucketId": "5e5ea5c16897e", @@ -216,20 +199,17 @@ def test_get_file(self, m): "compression": "gzip", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.storage.get_file( + response = await self.storage.get_file( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_file(self, m): + @respx.mock + async def test_update_file(self): data = { "$id": "5e5ea5c16897e", "bucketId": "5e5ea5c16897e", @@ -249,77 +229,62 @@ def test_update_file(self, m): "compression": "gzip", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.storage.update_file( + response = await self.storage.update_file( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete_file(self, m): + @respx.mock + async def test_delete_file(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.storage.delete_file( + response = await self.storage.delete_file( '', '', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_get_file_download(self, m): + @respx.mock + async def test_get_file_download(self): data = bytearray() headers = {'Content-Type': 'application/octet-stream'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - body=data, - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, content=bytes(data), headers=headers), ) - response = self.storage.get_file_download( + response = await self.storage.get_file_download( '', '', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_get_file_preview(self, m): + @respx.mock + async def test_get_file_preview(self): data = bytearray() headers = {'Content-Type': 'application/octet-stream'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - body=data, - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, content=bytes(data), headers=headers), ) - response = self.storage.get_file_preview( + response = await self.storage.get_file_preview( '', '', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_get_file_view(self, m): + @respx.mock + async def test_get_file_view(self): data = bytearray() headers = {'Content-Type': 'application/octet-stream'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - body=data, - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, content=bytes(data), headers=headers), ) - response = self.storage.get_file_view( + response = await self.storage.get_file_view( '', '', ) diff --git a/test/services/test_tables_db.py b/test/services/test_tables_db.py index 31151822..a15d96be 100644 --- a/test/services/test_tables_db.py +++ b/test/services/test_tables_db.py @@ -1,5 +1,6 @@ import json -import requests_mock +import httpx2 +import respx import unittest from appwrite.client import Client @@ -8,30 +9,30 @@ from appwrite.services.tables_db import TablesDB -class TablesDBServiceTest(unittest.TestCase): +class TablesDBServiceTest(unittest.IsolatedAsyncioTestCase): - def setUp(self): + async def asyncSetUp(self): self.client = Client() self.tables_db = TablesDB(self.client) - @requests_mock.Mocker() - def test_list(self, m): + async def asyncTearDown(self): + await self.client.aclose() + + @respx.mock + async def test_list(self): data = { "total": 5.0, "databases": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.tables_db.list() + response = await self.tables_db.list() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create(self, m): + @respx.mock + async def test_create(self): data = { "$id": "5e5ea5c16897e", "name": "My Database", @@ -42,52 +43,43 @@ def test_create(self, m): "type": "legacy", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.tables_db.create( + response = await self.tables_db.create( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_list_specifications(self, m): + @respx.mock + async def test_list_specifications(self): data = { "specifications": [], "total": 9.0, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.tables_db.list_specifications() + response = await self.tables_db.list_specifications() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_list_transactions(self, m): + @respx.mock + async def test_list_transactions(self): data = { "total": 5.0, "transactions": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.tables_db.list_transactions() + response = await self.tables_db.list_transactions() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_transaction(self, m): + @respx.mock + async def test_create_transaction(self): data = { "$id": "259125845563242502", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -97,17 +89,14 @@ def test_create_transaction(self, m): "expiresAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.tables_db.create_transaction() + response = await self.tables_db.create_transaction() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_transaction(self, m): + @respx.mock + async def test_get_transaction(self): data = { "$id": "259125845563242502", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -117,19 +106,16 @@ def test_get_transaction(self, m): "expiresAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.tables_db.get_transaction( + response = await self.tables_db.get_transaction( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_transaction(self, m): + @respx.mock + async def test_update_transaction(self): data = { "$id": "259125845563242502", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -139,34 +125,28 @@ def test_update_transaction(self, m): "expiresAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.tables_db.update_transaction( + response = await self.tables_db.update_transaction( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete_transaction(self, m): + @respx.mock + async def test_delete_transaction(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.tables_db.delete_transaction( + response = await self.tables_db.delete_transaction( '', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_create_operations(self, m): + @respx.mock + async def test_create_operations(self): data = { "$id": "259125845563242502", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -176,19 +156,16 @@ def test_create_operations(self, m): "expiresAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.tables_db.create_operations( + response = await self.tables_db.create_operations( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get(self, m): + @respx.mock + async def test_get(self): data = { "$id": "5e5ea5c16897e", "name": "My Database", @@ -199,19 +176,16 @@ def test_get(self, m): "type": "legacy", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.tables_db.get( + response = await self.tables_db.get( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update(self, m): + @respx.mock + async def test_update(self): data = { "$id": "5e5ea5c16897e", "name": "My Database", @@ -222,34 +196,28 @@ def test_update(self, m): "type": "legacy", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.tables_db.update( + response = await self.tables_db.update( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete(self, m): + @respx.mock + async def test_delete(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.tables_db.delete( + response = await self.tables_db.delete( '', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_create_failover(self, m): + @respx.mock + async def test_create_failover(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -298,37 +266,31 @@ def test_create_failover(self, m): "error": "", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.tables_db.create_failover( + response = await self.tables_db.create_failover( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_list_migrations(self, m): + @respx.mock + async def test_list_migrations(self): data = { "total": 5.0, "migrations": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.tables_db.list_migrations( + response = await self.tables_db.list_migrations( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_migration(self, m): + @respx.mock + async def test_create_migration(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -349,20 +311,17 @@ def test_create_migration(self, m): "paused": True, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.tables_db.create_migration( + response = await self.tables_db.create_migration( '', 's-1vcpu-1gb', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_migration(self, m): + @respx.mock + async def test_get_migration(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -383,36 +342,30 @@ def test_get_migration(self, m): "paused": True, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.tables_db.get_migration( + response = await self.tables_db.get_migration( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete_migration(self, m): + @respx.mock + async def test_delete_migration(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.tables_db.delete_migration( + response = await self.tables_db.delete_migration( '', '', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_create_cutover(self, m): + @respx.mock + async def test_create_cutover(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -433,38 +386,32 @@ def test_create_cutover(self, m): "paused": True, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.tables_db.create_cutover( + response = await self.tables_db.create_cutover( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_list_operations(self, m): + @respx.mock + async def test_list_operations(self): data = { "total": 5.0, "operations": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.tables_db.list_operations( + response = await self.tables_db.list_operations( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_replicas(self, m): + @respx.mock + async def test_get_replicas(self): data = { "replicas": 2.0, "syncMode": "async", @@ -474,19 +421,16 @@ def test_get_replicas(self, m): "members": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.tables_db.get_replicas( + response = await self.tables_db.get_replicas( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_status(self, m): + @respx.mock + async def test_get_status(self): data = { "health": "healthy", "ready": True, @@ -501,37 +445,31 @@ def test_get_status(self, m): "volumes": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.tables_db.get_status( + response = await self.tables_db.get_status( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_list_tables(self, m): + @respx.mock + async def test_list_tables(self): data = { "total": 5.0, "tables": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.tables_db.list_tables( + response = await self.tables_db.list_tables( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_table(self, m): + @respx.mock + async def test_create_table(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -548,21 +486,18 @@ def test_create_table(self, m): "bytesUsed": 1500.0, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.tables_db.create_table( + response = await self.tables_db.create_table( '', '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_table(self, m): + @respx.mock + async def test_get_table(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -579,20 +514,17 @@ def test_get_table(self, m): "bytesUsed": 1500.0, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.tables_db.get_table( + response = await self.tables_db.get_table( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_table(self, m): + @respx.mock + async def test_update_table(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -609,55 +541,46 @@ def test_update_table(self, m): "bytesUsed": 1500.0, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.tables_db.update_table( + response = await self.tables_db.update_table( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete_table(self, m): + @respx.mock + async def test_delete_table(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.tables_db.delete_table( + response = await self.tables_db.delete_table( '', '', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_list_columns(self, m): + @respx.mock + async def test_list_columns(self): data = { "total": 5.0, "columns": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.tables_db.list_columns( + response = await self.tables_db.list_columns( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_big_int_column(self, m): + @respx.mock + async def test_create_big_int_column(self): data = { "key": "count", "description": "Name shown on the public profile.", @@ -669,13 +592,10 @@ def test_create_big_int_column(self, m): "$updatedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.tables_db.create_big_int_column( + response = await self.tables_db.create_big_int_column( '', '', '', @@ -683,8 +603,8 @@ def test_create_big_int_column(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_big_int_column(self, m): + @respx.mock + async def test_update_big_int_column(self): data = { "key": "count", "description": "Name shown on the public profile.", @@ -696,13 +616,10 @@ def test_update_big_int_column(self, m): "$updatedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.tables_db.update_big_int_column( + response = await self.tables_db.update_big_int_column( '', '', '', @@ -711,8 +628,8 @@ def test_update_big_int_column(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_boolean_column(self, m): + @respx.mock + async def test_create_boolean_column(self): data = { "key": "isEnabled", "description": "Name shown on the public profile.", @@ -724,13 +641,10 @@ def test_create_boolean_column(self, m): "$updatedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.tables_db.create_boolean_column( + response = await self.tables_db.create_boolean_column( '', '', '', @@ -738,8 +652,8 @@ def test_create_boolean_column(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_boolean_column(self, m): + @respx.mock + async def test_update_boolean_column(self): data = { "key": "isEnabled", "description": "Name shown on the public profile.", @@ -751,13 +665,10 @@ def test_update_boolean_column(self, m): "$updatedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.tables_db.update_boolean_column( + response = await self.tables_db.update_boolean_column( '', '', '', @@ -766,8 +677,8 @@ def test_update_boolean_column(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_datetime_column(self, m): + @respx.mock + async def test_create_datetime_column(self): data = { "key": "birthDay", "description": "Name shown on the public profile.", @@ -780,13 +691,10 @@ def test_create_datetime_column(self, m): "format": "datetime", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.tables_db.create_datetime_column( + response = await self.tables_db.create_datetime_column( '', '', '', @@ -794,8 +702,8 @@ def test_create_datetime_column(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_datetime_column(self, m): + @respx.mock + async def test_update_datetime_column(self): data = { "key": "birthDay", "description": "Name shown on the public profile.", @@ -808,13 +716,10 @@ def test_update_datetime_column(self, m): "format": "datetime", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.tables_db.update_datetime_column( + response = await self.tables_db.update_datetime_column( '', '', '', @@ -823,8 +728,8 @@ def test_update_datetime_column(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_email_column(self, m): + @respx.mock + async def test_create_email_column(self): data = { "key": "userEmail", "description": "Name shown on the public profile.", @@ -837,13 +742,10 @@ def test_create_email_column(self, m): "format": "email", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.tables_db.create_email_column( + response = await self.tables_db.create_email_column( '', '', '', @@ -851,8 +753,8 @@ def test_create_email_column(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_email_column(self, m): + @respx.mock + async def test_update_email_column(self): data = { "key": "userEmail", "description": "Name shown on the public profile.", @@ -865,13 +767,10 @@ def test_update_email_column(self, m): "format": "email", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.tables_db.update_email_column( + response = await self.tables_db.update_email_column( '', '', '', @@ -880,8 +779,8 @@ def test_update_email_column(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_enum_column(self, m): + @respx.mock + async def test_create_enum_column(self): data = { "key": "status", "description": "Name shown on the public profile.", @@ -895,13 +794,10 @@ def test_create_enum_column(self, m): "format": "enum", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.tables_db.create_enum_column( + response = await self.tables_db.create_enum_column( '', '', '', @@ -910,8 +806,8 @@ def test_create_enum_column(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_enum_column(self, m): + @respx.mock + async def test_update_enum_column(self): data = { "key": "status", "description": "Name shown on the public profile.", @@ -925,13 +821,10 @@ def test_update_enum_column(self, m): "format": "enum", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.tables_db.update_enum_column( + response = await self.tables_db.update_enum_column( '', '', '', @@ -941,8 +834,8 @@ def test_update_enum_column(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_float_column(self, m): + @respx.mock + async def test_create_float_column(self): data = { "key": "percentageCompleted", "description": "Name shown on the public profile.", @@ -954,13 +847,10 @@ def test_create_float_column(self, m): "$updatedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.tables_db.create_float_column( + response = await self.tables_db.create_float_column( '', '', '', @@ -968,8 +858,8 @@ def test_create_float_column(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_float_column(self, m): + @respx.mock + async def test_update_float_column(self): data = { "key": "percentageCompleted", "description": "Name shown on the public profile.", @@ -981,13 +871,10 @@ def test_update_float_column(self, m): "$updatedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.tables_db.update_float_column( + response = await self.tables_db.update_float_column( '', '', '', @@ -996,8 +883,8 @@ def test_update_float_column(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_integer_column(self, m): + @respx.mock + async def test_create_integer_column(self): data = { "key": "count", "description": "Name shown on the public profile.", @@ -1009,13 +896,10 @@ def test_create_integer_column(self, m): "$updatedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.tables_db.create_integer_column( + response = await self.tables_db.create_integer_column( '', '', '', @@ -1023,8 +907,8 @@ def test_create_integer_column(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_integer_column(self, m): + @respx.mock + async def test_update_integer_column(self): data = { "key": "count", "description": "Name shown on the public profile.", @@ -1036,13 +920,10 @@ def test_update_integer_column(self, m): "$updatedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.tables_db.update_integer_column( + response = await self.tables_db.update_integer_column( '', '', '', @@ -1051,8 +932,8 @@ def test_update_integer_column(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_ip_column(self, m): + @respx.mock + async def test_create_ip_column(self): data = { "key": "ipAddress", "description": "Name shown on the public profile.", @@ -1065,13 +946,10 @@ def test_create_ip_column(self, m): "format": "ip", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.tables_db.create_ip_column( + response = await self.tables_db.create_ip_column( '', '', '', @@ -1079,8 +957,8 @@ def test_create_ip_column(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_ip_column(self, m): + @respx.mock + async def test_update_ip_column(self): data = { "key": "ipAddress", "description": "Name shown on the public profile.", @@ -1093,13 +971,10 @@ def test_update_ip_column(self, m): "format": "ip", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.tables_db.update_ip_column( + response = await self.tables_db.update_ip_column( '', '', '', @@ -1108,8 +983,8 @@ def test_update_ip_column(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_line_column(self, m): + @respx.mock + async def test_create_line_column(self): data = { "key": "fullName", "description": "Name shown on the public profile.", @@ -1121,13 +996,10 @@ def test_create_line_column(self, m): "$updatedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.tables_db.create_line_column( + response = await self.tables_db.create_line_column( '', '', '', @@ -1135,8 +1007,8 @@ def test_create_line_column(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_line_column(self, m): + @respx.mock + async def test_update_line_column(self): data = { "key": "fullName", "description": "Name shown on the public profile.", @@ -1148,13 +1020,10 @@ def test_update_line_column(self, m): "$updatedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.tables_db.update_line_column( + response = await self.tables_db.update_line_column( '', '', '', @@ -1162,8 +1031,8 @@ def test_update_line_column(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_longtext_column(self, m): + @respx.mock + async def test_create_longtext_column(self): data = { "key": "fullName", "description": "Name shown on the public profile.", @@ -1175,13 +1044,10 @@ def test_create_longtext_column(self, m): "$updatedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.tables_db.create_longtext_column( + response = await self.tables_db.create_longtext_column( '', '', '', @@ -1189,8 +1055,8 @@ def test_create_longtext_column(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_longtext_column(self, m): + @respx.mock + async def test_update_longtext_column(self): data = { "key": "fullName", "description": "Name shown on the public profile.", @@ -1202,13 +1068,10 @@ def test_update_longtext_column(self, m): "$updatedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.tables_db.update_longtext_column( + response = await self.tables_db.update_longtext_column( '', '', '', @@ -1217,8 +1080,8 @@ def test_update_longtext_column(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_mediumtext_column(self, m): + @respx.mock + async def test_create_mediumtext_column(self): data = { "key": "fullName", "description": "Name shown on the public profile.", @@ -1230,13 +1093,10 @@ def test_create_mediumtext_column(self, m): "$updatedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.tables_db.create_mediumtext_column( + response = await self.tables_db.create_mediumtext_column( '', '', '', @@ -1244,8 +1104,8 @@ def test_create_mediumtext_column(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_mediumtext_column(self, m): + @respx.mock + async def test_update_mediumtext_column(self): data = { "key": "fullName", "description": "Name shown on the public profile.", @@ -1257,13 +1117,10 @@ def test_update_mediumtext_column(self, m): "$updatedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.tables_db.update_mediumtext_column( + response = await self.tables_db.update_mediumtext_column( '', '', '', @@ -1272,8 +1129,8 @@ def test_update_mediumtext_column(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_point_column(self, m): + @respx.mock + async def test_create_point_column(self): data = { "key": "fullName", "description": "Name shown on the public profile.", @@ -1285,13 +1142,10 @@ def test_create_point_column(self, m): "$updatedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.tables_db.create_point_column( + response = await self.tables_db.create_point_column( '', '', '', @@ -1299,8 +1153,8 @@ def test_create_point_column(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_point_column(self, m): + @respx.mock + async def test_update_point_column(self): data = { "key": "fullName", "description": "Name shown on the public profile.", @@ -1312,13 +1166,10 @@ def test_update_point_column(self, m): "$updatedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.tables_db.update_point_column( + response = await self.tables_db.update_point_column( '', '', '', @@ -1326,8 +1177,8 @@ def test_update_point_column(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_polygon_column(self, m): + @respx.mock + async def test_create_polygon_column(self): data = { "key": "fullName", "description": "Name shown on the public profile.", @@ -1339,13 +1190,10 @@ def test_create_polygon_column(self, m): "$updatedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.tables_db.create_polygon_column( + response = await self.tables_db.create_polygon_column( '', '', '', @@ -1353,8 +1201,8 @@ def test_create_polygon_column(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_polygon_column(self, m): + @respx.mock + async def test_update_polygon_column(self): data = { "key": "fullName", "description": "Name shown on the public profile.", @@ -1366,13 +1214,10 @@ def test_update_polygon_column(self, m): "$updatedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.tables_db.update_polygon_column( + response = await self.tables_db.update_polygon_column( '', '', '', @@ -1380,8 +1225,8 @@ def test_update_polygon_column(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_relationship_column(self, m): + @respx.mock + async def test_create_relationship_column(self): data = { "key": "fullName", "description": "Name shown on the public profile.", @@ -1399,13 +1244,10 @@ def test_create_relationship_column(self, m): "side": "parent|child", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.tables_db.create_relationship_column( + response = await self.tables_db.create_relationship_column( '', '', '', @@ -1413,8 +1255,8 @@ def test_create_relationship_column(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_relationship_column(self, m): + @respx.mock + async def test_update_relationship_column(self): data = { "key": "fullName", "description": "Name shown on the public profile.", @@ -1432,21 +1274,18 @@ def test_update_relationship_column(self, m): "side": "parent|child", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.tables_db.update_relationship_column( + response = await self.tables_db.update_relationship_column( '', '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_string_column(self, m): + @respx.mock + async def test_create_string_column(self): data = { "key": "fullName", "description": "Name shown on the public profile.", @@ -1459,13 +1298,10 @@ def test_create_string_column(self, m): "size": 128.0, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.tables_db.create_string_column( + response = await self.tables_db.create_string_column( '', '', '', @@ -1474,8 +1310,8 @@ def test_create_string_column(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_string_column(self, m): + @respx.mock + async def test_update_string_column(self): data = { "key": "fullName", "description": "Name shown on the public profile.", @@ -1488,13 +1324,10 @@ def test_update_string_column(self, m): "size": 128.0, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.tables_db.update_string_column( + response = await self.tables_db.update_string_column( '', '', '', @@ -1503,8 +1336,8 @@ def test_update_string_column(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_text_column(self, m): + @respx.mock + async def test_create_text_column(self): data = { "key": "fullName", "description": "Name shown on the public profile.", @@ -1516,13 +1349,10 @@ def test_create_text_column(self, m): "$updatedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.tables_db.create_text_column( + response = await self.tables_db.create_text_column( '', '', '', @@ -1530,8 +1360,8 @@ def test_create_text_column(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_text_column(self, m): + @respx.mock + async def test_update_text_column(self): data = { "key": "fullName", "description": "Name shown on the public profile.", @@ -1543,13 +1373,10 @@ def test_update_text_column(self, m): "$updatedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.tables_db.update_text_column( + response = await self.tables_db.update_text_column( '', '', '', @@ -1558,8 +1385,8 @@ def test_update_text_column(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_url_column(self, m): + @respx.mock + async def test_create_url_column(self): data = { "key": "githubUrl", "description": "Name shown on the public profile.", @@ -1572,13 +1399,10 @@ def test_create_url_column(self, m): "format": "url", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.tables_db.create_url_column( + response = await self.tables_db.create_url_column( '', '', '', @@ -1586,8 +1410,8 @@ def test_create_url_column(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_url_column(self, m): + @respx.mock + async def test_update_url_column(self): data = { "key": "githubUrl", "description": "Name shown on the public profile.", @@ -1600,13 +1424,10 @@ def test_update_url_column(self, m): "format": "url", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.tables_db.update_url_column( + response = await self.tables_db.update_url_column( '', '', '', @@ -1615,8 +1436,8 @@ def test_update_url_column(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_varchar_column(self, m): + @respx.mock + async def test_create_varchar_column(self): data = { "key": "fullName", "description": "Name shown on the public profile.", @@ -1629,13 +1450,10 @@ def test_create_varchar_column(self, m): "size": 128.0, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.tables_db.create_varchar_column( + response = await self.tables_db.create_varchar_column( '', '', '', @@ -1644,8 +1462,8 @@ def test_create_varchar_column(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_varchar_column(self, m): + @respx.mock + async def test_update_varchar_column(self): data = { "key": "fullName", "description": "Name shown on the public profile.", @@ -1658,13 +1476,10 @@ def test_update_varchar_column(self, m): "size": 128.0, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.tables_db.update_varchar_column( + response = await self.tables_db.update_varchar_column( '', '', '', @@ -1673,8 +1488,8 @@ def test_update_varchar_column(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_column(self, m): + @respx.mock + async def test_get_column(self): data = { "key": "isEnabled", "description": "Name shown on the public profile.", @@ -1686,57 +1501,48 @@ def test_get_column(self, m): "$updatedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.tables_db.get_column( + response = await self.tables_db.get_column( '', '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete_column(self, m): + @respx.mock + async def test_delete_column(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.tables_db.delete_column( + response = await self.tables_db.delete_column( '', '', '', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_list_indexes(self, m): + @respx.mock + async def test_list_indexes(self): data = { "total": 5.0, "indexes": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.tables_db.list_indexes( + response = await self.tables_db.list_indexes( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_index(self, m): + @respx.mock + async def test_create_index(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -1750,13 +1556,10 @@ def test_create_index(self, m): "lengths": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.tables_db.create_index( + response = await self.tables_db.create_index( '', '', '', @@ -1765,8 +1568,8 @@ def test_create_index(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_index(self, m): + @respx.mock + async def test_get_index(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -1780,57 +1583,48 @@ def test_get_index(self, m): "lengths": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.tables_db.get_index( + response = await self.tables_db.get_index( '', '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete_index(self, m): + @respx.mock + async def test_delete_index(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.tables_db.delete_index( + response = await self.tables_db.delete_index( '', '', '', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_list_rows(self, m): + @respx.mock + async def test_list_rows(self): data = { "total": 5.0, "rows": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.tables_db.list_rows( + response = await self.tables_db.list_rows( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_row(self, m): + @respx.mock + async def test_create_row(self): data = { "$id": "5e5ea5c16897e", "$sequence": "1", @@ -1841,13 +1635,10 @@ def test_create_row(self, m): "$permissions": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.tables_db.create_row( + response = await self.tables_db.create_row( '', '', '', @@ -1856,105 +1647,90 @@ def test_create_row(self, m): data['data'] = {} self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_rows(self, m): + @respx.mock + async def test_create_rows(self): data = { "total": 5.0, "rows": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.tables_db.create_rows( + response = await self.tables_db.create_rows( '', '', [], ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_upsert_rows(self, m): + @respx.mock + async def test_upsert_rows(self): data = { "total": 5.0, "rows": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.tables_db.upsert_rows( + response = await self.tables_db.upsert_rows( '', '', [], ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_rows(self, m): + @respx.mock + async def test_update_rows(self): data = { "total": 5.0, "rows": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.tables_db.update_rows( + response = await self.tables_db.update_rows( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete_rows(self, m): + @respx.mock + async def test_delete_rows(self): data = { "total": 5.0, "rows": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.tables_db.delete_rows( + response = await self.tables_db.delete_rows( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_query(self, m): + @respx.mock + async def test_create_query(self): data = { "total": 5.0, "rows": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.tables_db.create_query( + response = await self.tables_db.create_query( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_row(self, m): + @respx.mock + async def test_get_row(self): data = { "$id": "5e5ea5c16897e", "$sequence": "1", @@ -1965,13 +1741,10 @@ def test_get_row(self, m): "$permissions": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.tables_db.get_row( + response = await self.tables_db.get_row( '', '', '', @@ -1979,8 +1752,8 @@ def test_get_row(self, m): data['data'] = {} self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_upsert_row(self, m): + @respx.mock + async def test_upsert_row(self): data = { "$id": "5e5ea5c16897e", "$sequence": "1", @@ -1991,13 +1764,10 @@ def test_upsert_row(self, m): "$permissions": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.tables_db.upsert_row( + response = await self.tables_db.upsert_row( '', '', '', @@ -2005,8 +1775,8 @@ def test_upsert_row(self, m): data['data'] = {} self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_row(self, m): + @respx.mock + async def test_update_row(self): data = { "$id": "5e5ea5c16897e", "$sequence": "1", @@ -2017,13 +1787,10 @@ def test_update_row(self, m): "$permissions": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.tables_db.update_row( + response = await self.tables_db.update_row( '', '', '', @@ -2031,25 +1798,22 @@ def test_update_row(self, m): data['data'] = {} self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete_row(self, m): + @respx.mock + async def test_delete_row(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.tables_db.delete_row( + response = await self.tables_db.delete_row( '', '', '', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_decrement_row_column(self, m): + @respx.mock + async def test_decrement_row_column(self): data = { "$id": "5e5ea5c16897e", "$sequence": "1", @@ -2060,13 +1824,10 @@ def test_decrement_row_column(self, m): "$permissions": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.tables_db.decrement_row_column( + response = await self.tables_db.decrement_row_column( '', '', '', @@ -2075,8 +1836,8 @@ def test_decrement_row_column(self, m): data['data'] = {} self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_increment_row_column(self, m): + @respx.mock + async def test_increment_row_column(self): data = { "$id": "5e5ea5c16897e", "$sequence": "1", @@ -2087,13 +1848,10 @@ def test_increment_row_column(self, m): "$permissions": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.tables_db.increment_row_column( + response = await self.tables_db.increment_row_column( '', '', '', diff --git a/test/services/test_teams.py b/test/services/test_teams.py index 24f7dbb5..660ee81e 100644 --- a/test/services/test_teams.py +++ b/test/services/test_teams.py @@ -1,5 +1,6 @@ import json -import requests_mock +import httpx2 +import respx import unittest from appwrite.client import Client @@ -8,30 +9,30 @@ from appwrite.services.teams import Teams -class TeamsServiceTest(unittest.TestCase): +class TeamsServiceTest(unittest.IsolatedAsyncioTestCase): - def setUp(self): + async def asyncSetUp(self): self.client = Client() self.teams = Teams(self.client) - @requests_mock.Mocker() - def test_list(self, m): + async def asyncTearDown(self): + await self.client.aclose() + + @respx.mock + async def test_list(self): data = { "total": 5.0, "teams": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.teams.list() + response = await self.teams.list() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create(self, m): + @respx.mock + async def test_create(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -41,20 +42,17 @@ def test_create(self, m): "prefs": {}, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.teams.create( + response = await self.teams.create( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get(self, m): + @respx.mock + async def test_get(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -64,19 +62,16 @@ def test_get(self, m): "prefs": {}, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.teams.get( + response = await self.teams.get( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_name(self, m): + @respx.mock + async def test_update_name(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -86,53 +81,44 @@ def test_update_name(self, m): "prefs": {}, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.teams.update_name( + response = await self.teams.update_name( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete(self, m): + @respx.mock + async def test_delete(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.teams.delete( + response = await self.teams.delete( '', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_list_installations(self, m): + @respx.mock + async def test_list_installations(self): data = { "total": 5.0, "installations": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.teams.list_installations( + response = await self.teams.list_installations( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_installation(self, m): + @respx.mock + async def test_create_installation(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -145,20 +131,17 @@ def test_create_installation(self, m): "createdByName": "Walter White", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.teams.create_installation( + response = await self.teams.create_installation( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_installation(self, m): + @respx.mock + async def test_get_installation(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -171,20 +154,17 @@ def test_get_installation(self, m): "createdByName": "Walter White", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.teams.get_installation( + response = await self.teams.get_installation( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_installation(self, m): + @respx.mock + async def test_update_installation(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -197,54 +177,45 @@ def test_update_installation(self, m): "createdByName": "Walter White", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.teams.update_installation( + response = await self.teams.update_installation( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete_installation(self, m): + @respx.mock + async def test_delete_installation(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.teams.delete_installation( + response = await self.teams.delete_installation( '', '', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_list_memberships(self, m): + @respx.mock + async def test_list_memberships(self): data = { "total": 5.0, "memberships": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.teams.list_memberships( + response = await self.teams.list_memberships( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_membership(self, m): + @respx.mock + async def test_create_membership(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -263,20 +234,17 @@ def test_create_membership(self, m): "roles": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.teams.create_membership( + response = await self.teams.create_membership( '', [], ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_membership(self, m): + @respx.mock + async def test_get_membership(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -295,20 +263,17 @@ def test_get_membership(self, m): "roles": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.teams.get_membership( + response = await self.teams.get_membership( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_membership(self, m): + @respx.mock + async def test_update_membership(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -327,37 +292,31 @@ def test_update_membership(self, m): "roles": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.teams.update_membership( + response = await self.teams.update_membership( '', '', [], ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete_membership(self, m): + @respx.mock + async def test_delete_membership(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.teams.delete_membership( + response = await self.teams.delete_membership( '', '', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_update_membership_status(self, m): + @respx.mock + async def test_update_membership_status(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -376,13 +335,10 @@ def test_update_membership_status(self, m): "roles": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.teams.update_membership_status( + response = await self.teams.update_membership_status( '', '', '', @@ -390,32 +346,26 @@ def test_update_membership_status(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_prefs(self, m): + @respx.mock + async def test_get_prefs(self): data = {} headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.teams.get_prefs( + response = await self.teams.get_prefs( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_prefs(self, m): + @respx.mock + async def test_update_prefs(self): data = {} headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.teams.update_prefs( + response = await self.teams.update_prefs( '', {}, ) diff --git a/test/services/test_tokens.py b/test/services/test_tokens.py index de5f3f87..786b2e2c 100644 --- a/test/services/test_tokens.py +++ b/test/services/test_tokens.py @@ -1,5 +1,6 @@ import json -import requests_mock +import httpx2 +import respx import unittest from appwrite.client import Client @@ -8,33 +9,33 @@ from appwrite.services.tokens import Tokens -class TokensServiceTest(unittest.TestCase): +class TokensServiceTest(unittest.IsolatedAsyncioTestCase): - def setUp(self): + async def asyncSetUp(self): self.client = Client() self.tokens = Tokens(self.client) - @requests_mock.Mocker() - def test_list(self, m): + async def asyncTearDown(self): + await self.client.aclose() + + @respx.mock + async def test_list(self): data = { "total": 5.0, "tokens": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.tokens.list( + response = await self.tokens.list( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_file_token(self, m): + @respx.mock + async def test_create_file_token(self): data = { "$id": "bb8ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -45,20 +46,17 @@ def test_create_file_token(self, m): "accessedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.tokens.create_file_token( + response = await self.tokens.create_file_token( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get(self, m): + @respx.mock + async def test_get(self): data = { "$id": "bb8ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -69,19 +67,16 @@ def test_get(self, m): "accessedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.tokens.get( + response = await self.tokens.get( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update(self, m): + @respx.mock + async def test_update(self): data = { "$id": "bb8ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -92,28 +87,22 @@ def test_update(self, m): "accessedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.tokens.update( + response = await self.tokens.update( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete(self, m): + @respx.mock + async def test_delete(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.tokens.delete( + response = await self.tokens.delete( '', ) self.assertEqual(response, data) diff --git a/test/services/test_users.py b/test/services/test_users.py index 4dad6e4c..1a8f108c 100644 --- a/test/services/test_users.py +++ b/test/services/test_users.py @@ -1,5 +1,6 @@ import json -import requests_mock +import httpx2 +import respx import unittest from appwrite.client import Client @@ -8,30 +9,30 @@ from appwrite.services.users import Users -class UsersServiceTest(unittest.TestCase): +class UsersServiceTest(unittest.IsolatedAsyncioTestCase): - def setUp(self): + async def asyncSetUp(self): self.client = Client() self.users = Users(self.client) - @requests_mock.Mocker() - def test_list(self, m): + async def asyncTearDown(self): + await self.client.aclose() + + @respx.mock + async def test_list(self): data = { "total": 5.0, "users": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.users.list() + response = await self.users.list() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create(self, m): + @respx.mock + async def test_create(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -51,19 +52,16 @@ def test_create(self, m): "accessedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.users.create( + response = await self.users.create( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_argon2_user(self, m): + @respx.mock + async def test_create_argon2_user(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -83,21 +81,18 @@ def test_create_argon2_user(self, m): "accessedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.users.create_argon2_user( + response = await self.users.create_argon2_user( '', 'email@example.com', 'password', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_bcrypt_user(self, m): + @respx.mock + async def test_create_bcrypt_user(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -117,52 +112,43 @@ def test_create_bcrypt_user(self, m): "accessedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.users.create_bcrypt_user( + response = await self.users.create_bcrypt_user( '', 'email@example.com', 'password', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_list_identities(self, m): + @respx.mock + async def test_list_identities(self): data = { "total": 5.0, "identities": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.users.list_identities() + response = await self.users.list_identities() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete_identity(self, m): + @respx.mock + async def test_delete_identity(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.users.delete_identity( + response = await self.users.delete_identity( '', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_create_md5_user(self, m): + @respx.mock + async def test_create_md5_user(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -182,21 +168,18 @@ def test_create_md5_user(self, m): "accessedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.users.create_md5_user( + response = await self.users.create_md5_user( '', 'email@example.com', 'password', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_ph_pass_user(self, m): + @respx.mock + async def test_create_ph_pass_user(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -216,21 +199,18 @@ def test_create_ph_pass_user(self, m): "accessedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.users.create_ph_pass_user( + response = await self.users.create_ph_pass_user( '', 'email@example.com', 'password', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_scrypt_user(self, m): + @respx.mock + async def test_create_scrypt_user(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -250,13 +230,10 @@ def test_create_scrypt_user(self, m): "accessedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.users.create_scrypt_user( + response = await self.users.create_scrypt_user( '', 'email@example.com', 'password', @@ -268,8 +245,8 @@ def test_create_scrypt_user(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_scrypt_modified_user(self, m): + @respx.mock + async def test_create_scrypt_modified_user(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -289,13 +266,10 @@ def test_create_scrypt_modified_user(self, m): "accessedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.users.create_scrypt_modified_user( + response = await self.users.create_scrypt_modified_user( '', 'email@example.com', 'password', @@ -305,8 +279,8 @@ def test_create_scrypt_modified_user(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_sha_user(self, m): + @respx.mock + async def test_create_sha_user(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -326,21 +300,18 @@ def test_create_sha_user(self, m): "accessedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.users.create_sha_user( + response = await self.users.create_sha_user( '', 'email@example.com', 'password', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get(self, m): + @respx.mock + async def test_get(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -360,34 +331,28 @@ def test_get(self, m): "accessedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.users.get( + response = await self.users.get( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete(self, m): + @respx.mock + async def test_delete(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.users.delete( + response = await self.users.delete( '', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_update_email(self, m): + @respx.mock + async def test_update_email(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -407,20 +372,17 @@ def test_update_email(self, m): "accessedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.users.update_email( + response = await self.users.update_email( '', 'email@example.com', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_impersonator(self, m): + @respx.mock + async def test_update_impersonator(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -440,37 +402,31 @@ def test_update_impersonator(self, m): "accessedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.users.update_impersonator( + response = await self.users.update_impersonator( '', True, ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_jwt(self, m): + @respx.mock + async def test_create_jwt(self): data = { "jwt": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.users.create_jwt( + response = await self.users.create_jwt( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_labels(self, m): + @respx.mock + async def test_update_labels(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -490,38 +446,32 @@ def test_update_labels(self, m): "accessedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.users.update_labels( + response = await self.users.update_labels( '', [], ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_list_memberships(self, m): + @respx.mock + async def test_list_memberships(self): data = { "total": 5.0, "memberships": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.users.list_memberships( + response = await self.users.list_memberships( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_mfa(self, m): + @respx.mock + async def test_update_mfa(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -541,20 +491,17 @@ def test_update_mfa(self, m): "accessedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.users.update_mfa( + response = await self.users.update_mfa( '', True, ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_mfa(self, m): + @respx.mock + async def test_update_mfa(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -574,52 +521,43 @@ def test_update_mfa(self, m): "accessedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.users.update_mfa( + response = await self.users.update_mfa( '', True, ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete_mfa_authenticator(self, m): + @respx.mock + async def test_delete_mfa_authenticator(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.users.delete_mfa_authenticator( + response = await self.users.delete_mfa_authenticator( '', 'totp', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_delete_mfa_authenticator(self, m): + @respx.mock + async def test_delete_mfa_authenticator(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.users.delete_mfa_authenticator( + response = await self.users.delete_mfa_authenticator( '', 'totp', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_get_mfa_challenge(self, m): + @respx.mock + async def test_get_mfa_challenge(self): data = { "$id": "bb8ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -628,20 +566,17 @@ def test_get_mfa_challenge(self, m): "code": "446372", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.users.get_mfa_challenge( + response = await self.users.get_mfa_challenge( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_list_mfa_factors(self, m): + @respx.mock + async def test_list_mfa_factors(self): data = { "totp": True, "phone": True, @@ -650,19 +585,16 @@ def test_list_mfa_factors(self, m): "custom": True, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.users.list_mfa_factors( + response = await self.users.list_mfa_factors( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_list_mfa_factors(self, m): + @respx.mock + async def test_list_mfa_factors(self): data = { "totp": True, "phone": True, @@ -671,121 +603,100 @@ def test_list_mfa_factors(self, m): "custom": True, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.users.list_mfa_factors( + response = await self.users.list_mfa_factors( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_mfa_recovery_codes(self, m): + @respx.mock + async def test_get_mfa_recovery_codes(self): data = { "recoveryCodes": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.users.get_mfa_recovery_codes( + response = await self.users.get_mfa_recovery_codes( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_mfa_recovery_codes(self, m): + @respx.mock + async def test_get_mfa_recovery_codes(self): data = { "recoveryCodes": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.users.get_mfa_recovery_codes( + response = await self.users.get_mfa_recovery_codes( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_mfa_recovery_codes(self, m): + @respx.mock + async def test_update_mfa_recovery_codes(self): data = { "recoveryCodes": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.users.update_mfa_recovery_codes( + response = await self.users.update_mfa_recovery_codes( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_mfa_recovery_codes(self, m): + @respx.mock + async def test_update_mfa_recovery_codes(self): data = { "recoveryCodes": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.users.update_mfa_recovery_codes( + response = await self.users.update_mfa_recovery_codes( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_mfa_recovery_codes(self, m): + @respx.mock + async def test_create_mfa_recovery_codes(self): data = { "recoveryCodes": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.users.create_mfa_recovery_codes( + response = await self.users.create_mfa_recovery_codes( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_mfa_recovery_codes(self, m): + @respx.mock + async def test_create_mfa_recovery_codes(self): data = { "recoveryCodes": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.users.create_mfa_recovery_codes( + response = await self.users.create_mfa_recovery_codes( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_name(self, m): + @respx.mock + async def test_update_name(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -805,38 +716,32 @@ def test_update_name(self, m): "accessedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.users.update_name( + response = await self.users.update_name( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_list_passkeys(self, m): + @respx.mock + async def test_list_passkeys(self): data = { "total": 5.0, "passkeys": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.users.list_passkeys( + response = await self.users.list_passkeys( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_passkey(self, m): + @respx.mock + async def test_get_passkey(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -845,20 +750,17 @@ def test_get_passkey(self, m): "accessedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.users.get_passkey( + response = await self.users.get_passkey( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_passkey(self, m): + @respx.mock + async def test_update_passkey(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -867,37 +769,31 @@ def test_update_passkey(self, m): "accessedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.users.update_passkey( + response = await self.users.update_passkey( '', '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete_passkey(self, m): + @respx.mock + async def test_delete_passkey(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.users.delete_passkey( + response = await self.users.delete_passkey( '', '', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_update_password(self, m): + @respx.mock + async def test_update_password(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -917,20 +813,17 @@ def test_update_password(self, m): "accessedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.users.update_password( + response = await self.users.update_password( '', 'password', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_phone(self, m): + @respx.mock + async def test_update_phone(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -950,69 +843,57 @@ def test_update_phone(self, m): "accessedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.users.update_phone( + response = await self.users.update_phone( '', '+12065550100', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_prefs(self, m): + @respx.mock + async def test_get_prefs(self): data = {} headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.users.get_prefs( + response = await self.users.get_prefs( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_prefs(self, m): + @respx.mock + async def test_update_prefs(self): data = {} headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.users.update_prefs( + response = await self.users.update_prefs( '', {}, ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_list_sessions(self, m): + @respx.mock + async def test_list_sessions(self): data = { "total": 5.0, "sessions": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.users.list_sessions( + response = await self.users.list_sessions( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_session(self, m): + @respx.mock + async def test_create_session(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -1045,50 +926,41 @@ def test_create_session(self, m): "mfaUpdatedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.users.create_session( + response = await self.users.create_session( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete_sessions(self, m): + @respx.mock + async def test_delete_sessions(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.users.delete_sessions( + response = await self.users.delete_sessions( '', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_delete_session(self, m): + @respx.mock + async def test_delete_session(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.users.delete_session( + response = await self.users.delete_session( '', '', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_update_status(self, m): + @respx.mock + async def test_update_status(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -1108,38 +980,32 @@ def test_update_status(self, m): "accessedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.users.update_status( + response = await self.users.update_status( '', True, ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_list_targets(self, m): + @respx.mock + async def test_list_targets(self): data = { "total": 5.0, "targets": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.users.list_targets( + response = await self.users.list_targets( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_target(self, m): + @respx.mock + async def test_create_target(self): data = { "$id": "259125845563242502", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -1151,13 +1017,10 @@ def test_create_target(self, m): "expired": True, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.users.create_target( + response = await self.users.create_target( '', '', 'email', @@ -1165,8 +1028,8 @@ def test_create_target(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_target(self, m): + @respx.mock + async def test_get_target(self): data = { "$id": "259125845563242502", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -1178,20 +1041,17 @@ def test_get_target(self, m): "expired": True, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.users.get_target( + response = await self.users.get_target( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_target(self, m): + @respx.mock + async def test_update_target(self): data = { "$id": "259125845563242502", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -1203,36 +1063,30 @@ def test_update_target(self, m): "expired": True, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.users.update_target( + response = await self.users.update_target( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete_target(self, m): + @respx.mock + async def test_delete_target(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.users.delete_target( + response = await self.users.delete_target( '', '', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_create_token(self, m): + @respx.mock + async def test_create_token(self): data = { "$id": "bb8ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -1242,19 +1096,16 @@ def test_create_token(self, m): "phrase": "Golden Fox", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.users.create_token( + response = await self.users.create_token( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_email_verification(self, m): + @respx.mock + async def test_update_email_verification(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -1274,20 +1125,17 @@ def test_update_email_verification(self, m): "accessedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.users.update_email_verification( + response = await self.users.update_email_verification( '', True, ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_phone_verification(self, m): + @respx.mock + async def test_update_phone_verification(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -1307,13 +1155,10 @@ def test_update_phone_verification(self, m): "accessedAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.users.update_phone_verification( + response = await self.users.update_phone_verification( '', True, ) diff --git a/test/services/test_vectors_db.py b/test/services/test_vectors_db.py index 2c6f2240..a927ccc1 100644 --- a/test/services/test_vectors_db.py +++ b/test/services/test_vectors_db.py @@ -1,5 +1,6 @@ import json -import requests_mock +import httpx2 +import respx import unittest from appwrite.client import Client @@ -8,30 +9,30 @@ from appwrite.services.vectors_db import VectorsDB -class VectorsDBServiceTest(unittest.TestCase): +class VectorsDBServiceTest(unittest.IsolatedAsyncioTestCase): - def setUp(self): + async def asyncSetUp(self): self.client = Client() self.vectors_db = VectorsDB(self.client) - @requests_mock.Mocker() - def test_list(self, m): + async def asyncTearDown(self): + await self.client.aclose() + + @respx.mock + async def test_list(self): data = { "total": 5.0, "databases": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.vectors_db.list() + response = await self.vectors_db.list() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create(self, m): + @respx.mock + async def test_create(self): data = { "$id": "5e5ea5c16897e", "name": "My Database", @@ -42,52 +43,43 @@ def test_create(self, m): "type": "legacy", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.vectors_db.create( + response = await self.vectors_db.create( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_list_specifications(self, m): + @respx.mock + async def test_list_specifications(self): data = { "specifications": [], "total": 9.0, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.vectors_db.list_specifications() + response = await self.vectors_db.list_specifications() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_list_transactions(self, m): + @respx.mock + async def test_list_transactions(self): data = { "total": 5.0, "transactions": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.vectors_db.list_transactions() + response = await self.vectors_db.list_transactions() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_transaction(self, m): + @respx.mock + async def test_create_transaction(self): data = { "$id": "259125845563242502", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -97,17 +89,14 @@ def test_create_transaction(self, m): "expiresAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.vectors_db.create_transaction() + response = await self.vectors_db.create_transaction() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_transaction(self, m): + @respx.mock + async def test_get_transaction(self): data = { "$id": "259125845563242502", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -117,19 +106,16 @@ def test_get_transaction(self, m): "expiresAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.vectors_db.get_transaction( + response = await self.vectors_db.get_transaction( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_transaction(self, m): + @respx.mock + async def test_update_transaction(self): data = { "$id": "259125845563242502", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -139,34 +125,28 @@ def test_update_transaction(self, m): "expiresAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.vectors_db.update_transaction( + response = await self.vectors_db.update_transaction( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete_transaction(self, m): + @respx.mock + async def test_delete_transaction(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.vectors_db.delete_transaction( + response = await self.vectors_db.delete_transaction( '', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_create_operations(self, m): + @respx.mock + async def test_create_operations(self): data = { "$id": "259125845563242502", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -176,19 +156,16 @@ def test_create_operations(self, m): "expiresAt": "2020-10-15T06:38:00.000+00:00", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.vectors_db.create_operations( + response = await self.vectors_db.create_operations( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get(self, m): + @respx.mock + async def test_get(self): data = { "$id": "5e5ea5c16897e", "name": "My Database", @@ -199,19 +176,16 @@ def test_get(self, m): "type": "legacy", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.vectors_db.get( + response = await self.vectors_db.get( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update(self, m): + @respx.mock + async def test_update(self): data = { "$id": "5e5ea5c16897e", "name": "My Database", @@ -222,53 +196,44 @@ def test_update(self, m): "type": "legacy", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.vectors_db.update( + response = await self.vectors_db.update( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete(self, m): + @respx.mock + async def test_delete(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.vectors_db.delete( + response = await self.vectors_db.delete( '', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_list_collections(self, m): + @respx.mock + async def test_list_collections(self): data = { "total": 5.0, "collections": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.vectors_db.list_collections( + response = await self.vectors_db.list_collections( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_collection(self, m): + @respx.mock + async def test_create_collection(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -286,13 +251,10 @@ def test_create_collection(self, m): "dimension": 1536.0, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.vectors_db.create_collection( + response = await self.vectors_db.create_collection( '', '', '', @@ -300,8 +262,8 @@ def test_create_collection(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_collection(self, m): + @respx.mock + async def test_get_collection(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -319,20 +281,17 @@ def test_get_collection(self, m): "dimension": 1536.0, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.vectors_db.get_collection( + response = await self.vectors_db.get_collection( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_collection(self, m): + @respx.mock + async def test_update_collection(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -350,56 +309,47 @@ def test_update_collection(self, m): "dimension": 1536.0, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.vectors_db.update_collection( + response = await self.vectors_db.update_collection( '', '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete_collection(self, m): + @respx.mock + async def test_delete_collection(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.vectors_db.delete_collection( + response = await self.vectors_db.delete_collection( '', '', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_list_documents(self, m): + @respx.mock + async def test_list_documents(self): data = { "total": 5.0, "documents": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.vectors_db.list_documents( + response = await self.vectors_db.list_documents( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_document(self, m): + @respx.mock + async def test_create_document(self): data = { "$id": "5e5ea5c16897e", "$sequence": "1", @@ -410,13 +360,10 @@ def test_create_document(self, m): "$permissions": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.vectors_db.create_document( + response = await self.vectors_db.create_document( '', '', '', @@ -425,105 +372,90 @@ def test_create_document(self, m): data['data'] = {} self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_documents(self, m): + @respx.mock + async def test_create_documents(self): data = { "total": 5.0, "documents": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.vectors_db.create_documents( + response = await self.vectors_db.create_documents( '', '', [], ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_upsert_documents(self, m): + @respx.mock + async def test_upsert_documents(self): data = { "total": 5.0, "documents": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.vectors_db.upsert_documents( + response = await self.vectors_db.upsert_documents( '', '', [], ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_documents(self, m): + @respx.mock + async def test_update_documents(self): data = { "total": 5.0, "documents": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.vectors_db.update_documents( + response = await self.vectors_db.update_documents( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete_documents(self, m): + @respx.mock + async def test_delete_documents(self): data = { "total": 5.0, "documents": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.vectors_db.delete_documents( + response = await self.vectors_db.delete_documents( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_query(self, m): + @respx.mock + async def test_create_query(self): data = { "total": 5.0, "documents": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.vectors_db.create_query( + response = await self.vectors_db.create_query( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_document(self, m): + @respx.mock + async def test_get_document(self): data = { "$id": "5e5ea5c16897e", "$sequence": "1", @@ -534,13 +466,10 @@ def test_get_document(self, m): "$permissions": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.vectors_db.get_document( + response = await self.vectors_db.get_document( '', '', '', @@ -548,8 +477,8 @@ def test_get_document(self, m): data['data'] = {} self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_upsert_document(self, m): + @respx.mock + async def test_upsert_document(self): data = { "$id": "5e5ea5c16897e", "$sequence": "1", @@ -560,13 +489,10 @@ def test_upsert_document(self, m): "$permissions": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.vectors_db.upsert_document( + response = await self.vectors_db.upsert_document( '', '', '', @@ -574,8 +500,8 @@ def test_upsert_document(self, m): data['data'] = {} self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_document(self, m): + @respx.mock + async def test_update_document(self): data = { "$id": "5e5ea5c16897e", "$sequence": "1", @@ -586,13 +512,10 @@ def test_update_document(self, m): "$permissions": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.vectors_db.update_document( + response = await self.vectors_db.update_document( '', '', '', @@ -600,44 +523,38 @@ def test_update_document(self, m): data['data'] = {} self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete_document(self, m): + @respx.mock + async def test_delete_document(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.vectors_db.delete_document( + response = await self.vectors_db.delete_document( '', '', '', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_list_indexes(self, m): + @respx.mock + async def test_list_indexes(self): data = { "total": 5.0, "indexes": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.vectors_db.list_indexes( + response = await self.vectors_db.list_indexes( '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_index(self, m): + @respx.mock + async def test_create_index(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -651,13 +568,10 @@ def test_create_index(self, m): "lengths": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.vectors_db.create_index( + response = await self.vectors_db.create_index( '', '', '', @@ -666,8 +580,8 @@ def test_create_index(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_index(self, m): + @respx.mock + async def test_get_index(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -681,38 +595,32 @@ def test_get_index(self, m): "lengths": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.vectors_db.get_index( + response = await self.vectors_db.get_index( '', '', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete_index(self, m): + @respx.mock + async def test_delete_index(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.vectors_db.delete_index( + response = await self.vectors_db.delete_index( '', '', '', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_create_failover(self, m): + @respx.mock + async def test_create_failover(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -761,37 +669,31 @@ def test_create_failover(self, m): "error": "", } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.vectors_db.create_failover( + response = await self.vectors_db.create_failover( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_list_operations(self, m): + @respx.mock + async def test_list_operations(self): data = { "total": 5.0, "operations": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.vectors_db.list_operations( + response = await self.vectors_db.list_operations( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_replicas(self, m): + @respx.mock + async def test_get_replicas(self): data = { "replicas": 2.0, "syncMode": "async", @@ -801,19 +703,16 @@ def test_get_replicas(self, m): "members": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.vectors_db.get_replicas( + response = await self.vectors_db.get_replicas( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_status(self, m): + @respx.mock + async def test_get_status(self): data = { "health": "healthy", "ready": True, @@ -828,13 +727,10 @@ def test_get_status(self, m): "volumes": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.vectors_db.get_status( + response = await self.vectors_db.get_status( '', ) self.assertEqual(response.to_dict(), data) diff --git a/test/services/test_waf.py b/test/services/test_waf.py index 8c9e8bec..f827aa68 100644 --- a/test/services/test_waf.py +++ b/test/services/test_waf.py @@ -1,5 +1,6 @@ import json -import requests_mock +import httpx2 +import respx import unittest from appwrite.client import Client @@ -8,30 +9,30 @@ from appwrite.services.waf import Waf -class WafServiceTest(unittest.TestCase): +class WafServiceTest(unittest.IsolatedAsyncioTestCase): - def setUp(self): + async def asyncSetUp(self): self.client = Client() self.waf = Waf(self.client) - @requests_mock.Mocker() - def test_list_rules(self, m): + async def asyncTearDown(self): + await self.client.aclose() + + @respx.mock + async def test_list_rules(self): data = { "total": 5.0, "rules": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.waf.list_rules() + response = await self.waf.list_rules() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_bypass_rule(self, m): + @respx.mock + async def test_create_bypass_rule(self): data = { "$id": "wafRule1", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -49,21 +50,18 @@ def test_create_bypass_rule(self, m): "config": {}, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.waf.create_bypass_rule( + response = await self.waf.create_bypass_rule( '', 'api', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_bypass_rule(self, m): + @respx.mock + async def test_update_bypass_rule(self): data = { "$id": "wafRule1", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -81,19 +79,16 @@ def test_update_bypass_rule(self, m): "config": {}, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.waf.update_bypass_rule( + response = await self.waf.update_bypass_rule( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_challenge_rule(self, m): + @respx.mock + async def test_create_challenge_rule(self): data = { "$id": "wafRule1", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -114,21 +109,18 @@ def test_create_challenge_rule(self, m): "ttl": 1800.0, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.waf.create_challenge_rule( + response = await self.waf.create_challenge_rule( '', 'api', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_challenge_rule(self, m): + @respx.mock + async def test_update_challenge_rule(self): data = { "$id": "wafRule1", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -149,19 +141,16 @@ def test_update_challenge_rule(self, m): "ttl": 1800.0, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.waf.update_challenge_rule( + response = await self.waf.update_challenge_rule( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_deny_rule(self, m): + @respx.mock + async def test_create_deny_rule(self): data = { "$id": "wafRule1", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -179,21 +168,18 @@ def test_create_deny_rule(self, m): "config": {}, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.waf.create_deny_rule( + response = await self.waf.create_deny_rule( '', 'api', '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_deny_rule(self, m): + @respx.mock + async def test_update_deny_rule(self): data = { "$id": "wafRule1", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -211,19 +197,16 @@ def test_update_deny_rule(self, m): "config": {}, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.waf.update_deny_rule( + response = await self.waf.update_deny_rule( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_rate_limit_rule(self, m): + @respx.mock + async def test_create_rate_limit_rule(self): data = { "$id": "wafRule1", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -246,13 +229,10 @@ def test_create_rate_limit_rule(self, m): "maxBucketSize": 200.0, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.waf.create_rate_limit_rule( + response = await self.waf.create_rate_limit_rule( '', 'api', '', @@ -261,8 +241,8 @@ def test_create_rate_limit_rule(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_rate_limit_rule(self, m): + @respx.mock + async def test_update_rate_limit_rule(self): data = { "$id": "wafRule1", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -285,19 +265,16 @@ def test_update_rate_limit_rule(self, m): "maxBucketSize": 200.0, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.waf.update_rate_limit_rule( + response = await self.waf.update_rate_limit_rule( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create_redirect_rule(self, m): + @respx.mock + async def test_create_redirect_rule(self): data = { "$id": "wafRule1", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -317,13 +294,10 @@ def test_create_redirect_rule(self, m): "statusCode": 301.0, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.waf.create_redirect_rule( + response = await self.waf.create_redirect_rule( '', 'api', '', @@ -332,8 +306,8 @@ def test_create_redirect_rule(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update_redirect_rule(self, m): + @respx.mock + async def test_update_redirect_rule(self): data = { "$id": "wafRule1", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -353,19 +327,16 @@ def test_update_redirect_rule(self, m): "statusCode": 301.0, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.waf.update_redirect_rule( + response = await self.waf.update_redirect_rule( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get_rule(self, m): + @respx.mock + async def test_get_rule(self): data = { "$id": "wafRule1", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -383,28 +354,22 @@ def test_get_rule(self, m): "config": {}, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.waf.get_rule( + response = await self.waf.get_rule( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete_rule(self, m): + @respx.mock + async def test_delete_rule(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.waf.delete_rule( + response = await self.waf.delete_rule( '', ) self.assertEqual(response, data) diff --git a/test/services/test_webhooks.py b/test/services/test_webhooks.py index 0f65c6b2..d1f059bf 100644 --- a/test/services/test_webhooks.py +++ b/test/services/test_webhooks.py @@ -1,5 +1,6 @@ import json -import requests_mock +import httpx2 +import respx import unittest from appwrite.client import Client @@ -8,30 +9,30 @@ from appwrite.services.webhooks import Webhooks -class WebhooksServiceTest(unittest.TestCase): +class WebhooksServiceTest(unittest.IsolatedAsyncioTestCase): - def setUp(self): + async def asyncSetUp(self): self.client = Client() self.webhooks = Webhooks(self.client) - @requests_mock.Mocker() - def test_list(self, m): + async def asyncTearDown(self): + await self.client.aclose() + + @respx.mock + async def test_list(self): data = { "total": 5.0, "webhooks": [], } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.webhooks.list() + response = await self.webhooks.list() self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_create(self, m): + @respx.mock + async def test_create(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -49,13 +50,10 @@ def test_create(self, m): "attempts": 10.0, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.webhooks.create( + response = await self.webhooks.create( '', 'https://example.com/webhook', '', @@ -63,8 +61,8 @@ def test_create(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_get(self, m): + @respx.mock + async def test_get(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -82,19 +80,16 @@ def test_get(self, m): "attempts": 10.0, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.webhooks.get( + response = await self.webhooks.get( '', ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_update(self, m): + @respx.mock + async def test_update(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -112,13 +107,10 @@ def test_update(self, m): "attempts": 10.0, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.webhooks.update( + response = await self.webhooks.update( '', '', 'https://example.com/webhook', @@ -126,23 +118,20 @@ def test_update(self, m): ) self.assertEqual(response.to_dict(), data) - @requests_mock.Mocker() - def test_delete(self, m): + @respx.mock + async def test_delete(self): data = '' headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.webhooks.delete( + response = await self.webhooks.delete( '', ) self.assertEqual(response, data) - @requests_mock.Mocker() - def test_update_secret(self, m): + @respx.mock + async def test_update_secret(self): data = { "$id": "5e5ea5c16897e", "$createdAt": "2020-10-15T06:38:00.000+00:00", @@ -160,13 +149,10 @@ def test_update_secret(self, m): "attempts": 10.0, } headers = {'Content-Type': 'application/json'} - m.request( - requests_mock.ANY, - requests_mock.ANY, - text=json.dumps(data), - headers=headers, + respx.route().mock( + return_value=httpx2.Response(200, text=json.dumps(data), headers=headers), ) - response = self.webhooks.update_secret( + response = await self.webhooks.update_secret( '', ) self.assertEqual(response.to_dict(), data) diff --git a/test/test_async_client.py b/test/test_async_client.py new file mode 100644 index 00000000..d9172d5b --- /dev/null +++ b/test/test_async_client.py @@ -0,0 +1,224 @@ +import asyncio +import unittest + +import httpx2 +import respx + +from appwrite.client import Client +from appwrite.exception import AppwriteException +from appwrite.input_file import InputFile +from appwrite.services.account import Account +from appwrite.services.storage import Storage + + +class AsyncClientTest(unittest.IsolatedAsyncioTestCase): + + @respx.mock + async def test_requests_are_served_concurrently(self): + in_flight = 0 + peak = 0 + + async def handler(request): + nonlocal in_flight, peak + in_flight += 1 + peak = max(peak, in_flight) + await asyncio.sleep(0.05) + in_flight -= 1 + return httpx2.Response(200, json={'$id': 'user-1'}, headers={'Content-Type': 'application/json'}) + + respx.route().mock(side_effect=handler) + + async with Client() as client: + responses = await asyncio.gather( + *[client.call('get', f'/users/{index}', {'accept': 'application/json'}) for index in range(5)] + ) + + self.assertEqual(len(responses), 5) + self.assertEqual(peak, 5) + + @respx.mock + async def test_error_response_raises_appwrite_exception(self): + respx.route().mock( + return_value=httpx2.Response( + 404, + json={'message': 'User not found', 'type': 'user_not_found'}, + headers={'Content-Type': 'application/json'}, + ) + ) + + async with Client() as client: + with self.assertRaises(AppwriteException) as context: + await client.call('get', '/users/missing', {'accept': 'application/json'}) + + self.assertEqual(context.exception.message, 'User not found') + self.assertEqual(context.exception.code, 404) + self.assertEqual(context.exception.type, 'user_not_found') + + @respx.mock + async def test_context_manager_closes_the_connection_pool(self): + async with Client() as client: + http = client._http + self.assertFalse(http.is_closed) + + self.assertTrue(http.is_closed) + + @respx.mock + async def test_chunked_upload_reports_progress(self): + total_chunks = 4 + received = 0 + ranges = [] + upload_ids = [] + + async def handler(request): + nonlocal received + if request.method == 'GET': + # Resume probe: the SDK asks whether an upload is already in progress. + return httpx2.Response( + 200, + json={'$id': 'file-1', 'chunksTotal': total_chunks, 'chunksUploaded': 0}, + headers={'Content-Type': 'application/json'}, + ) + received += 1 + ranges.append(request.headers.get('content-range')) + upload_ids.append(request.headers.get('x-appwrite-id')) + return httpx2.Response( + 200, + json={'$id': 'file-1', 'chunksTotal': total_chunks, 'chunksUploaded': received}, + headers={'Content-Type': 'application/json'}, + ) + + respx.route().mock(side_effect=handler) + + progress = [] + + async def on_progress(payload): + progress.append(payload) + + async with Client() as client: + client._chunk_size = 10 + storage = Storage(client) + await storage.create_file( + bucket_id='bucket-1', + file_id='file-1', + file=InputFile.from_bytes(b'x' * 40, 'test.txt'), + on_progress=on_progress, + ) + + self.assertEqual(received, total_chunks) + self.assertEqual( + sorted(ranges), + ['bytes 0-9/40', 'bytes 10-19/40', 'bytes 20-29/40', 'bytes 30-39/40'], + ) + self.assertEqual(upload_ids, ['file-1'] * total_chunks) + self.assertEqual(sorted(item['chunksUploaded'] for item in progress), [1, 2, 3, 4]) + self.assertEqual(max(item['progress'] for item in progress), 100.0) + self.assertEqual(max(item['sizeUploaded'] for item in progress), 40) + + @respx.mock + async def test_chunked_upload_waits_for_sibling_chunks_after_a_failure(self): + total_chunks = 4 + in_flight = 0 + completed = 0 + + async def handler(request): + nonlocal in_flight, completed + if request.method == 'GET': + # Resume probe: the SDK asks whether an upload is already in progress. + return httpx2.Response( + 200, + json={'$id': 'file-1', 'chunksTotal': total_chunks, 'chunksUploaded': 0}, + headers={'Content-Type': 'application/json'}, + ) + if request.headers.get('content-range', '').startswith('bytes 10-19'): + # Reject one chunk straight away, while its siblings are still uploading. + return httpx2.Response( + 400, + json={'message': 'Chunk rejected', 'type': 'general_bad_request'}, + headers={'Content-Type': 'application/json'}, + ) + in_flight += 1 + await asyncio.sleep(0.2) + in_flight -= 1 + completed += 1 + return httpx2.Response( + 200, + json={'$id': 'file-1', 'chunksTotal': total_chunks, 'chunksUploaded': 1}, + headers={'Content-Type': 'application/json'}, + ) + + respx.route().mock(side_effect=handler) + + async with Client() as client: + client._chunk_size = 10 + storage = Storage(client) + with self.assertRaises(AppwriteException) as context: + await storage.create_file( + bucket_id='bucket-1', + file_id='file-1', + file=InputFile.from_bytes(b'x' * 40, 'test.txt'), + ) + + self.assertEqual(context.exception.message, 'Chunk rejected') + self.assertEqual(in_flight, 0, 'sibling chunk uploads were still running when the error surfaced') + self.assertEqual(completed, 3, 'sibling chunk uploads did not run to completion') + + @respx.mock + async def test_location_response_returns_the_redirect_url(self): + # httpx raises on 3xx, so a redirect is only a success when the client + # treats it as one; OAuth login depends on the Location header. + respx.route().mock( + return_value=httpx2.Response( + 302, + headers={'Location': 'https://appwrite.io/oauth/callback?userId=1&secret=2'}, + ) + ) + + async with Client() as client: + location = await client.call( + 'get', + '/account/tokens/oauth2/github', + {'accept': 'text/html'}, + {}, + response_type='location', + ) + + self.assertEqual(location, 'https://appwrite.io/oauth/callback?userId=1&secret=2') + + @respx.mock + async def test_location_response_still_raises_on_client_errors(self): + respx.route().mock( + return_value=httpx2.Response( + 400, + json={'message': 'Invalid provider', 'type': 'general_bad_request'}, + headers={'Content-Type': 'application/json'}, + ) + ) + + async with Client() as client: + with self.assertRaises(AppwriteException) as context: + await client.call( + 'get', + '/account/tokens/oauth2/github', + {'accept': 'text/html'}, + {}, + response_type='location', + ) + + self.assertEqual(context.exception.message, 'Invalid provider') + self.assertEqual(context.exception.code, 400) + self.assertEqual(context.exception.type, 'general_bad_request') + + @respx.mock + async def test_create_o_auth2_token_returns_the_redirect_url(self): + respx.route().mock( + return_value=httpx2.Response( + 302, + headers={'Location': 'https://appwrite.io/oauth/callback?userId=1&secret=2'}, + ) + ) + + async with Client() as client: + account = Account(client) + response = await account.create_o_auth2_token('github') + + self.assertEqual(response, 'https://appwrite.io/oauth/callback?userId=1&secret=2') diff --git a/test/test_deprecated.py b/test/test_deprecated.py new file mode 100644 index 00000000..f7f56093 --- /dev/null +++ b/test/test_deprecated.py @@ -0,0 +1,125 @@ +import asyncio +import unittest +import warnings + +from appwrite.utils.deprecated import deprecated + + +class TestDeprecatedDecorator(unittest.IsolatedAsyncioTestCase): + + def test_warns_on_every_call(self): + @deprecated("use new_api instead") + def old_api(): + return 'ok' + + with warnings.catch_warnings(record=True) as caught: + warnings.simplefilter('always', DeprecationWarning) + self.assertEqual('ok', old_api()) + self.assertEqual('ok', old_api()) + + self.assertEqual( + [ + "Call to deprecated function 'old_api'. use new_api instead", + "Call to deprecated function 'old_api'. use new_api instead", + ], + [str(warning.message) for warning in caught], + ) + + def test_warning_is_attributed_to_the_caller(self): + @deprecated("use new_api instead") + def old_api(): + return 'ok' + + with warnings.catch_warnings(record=True) as caught: + warnings.simplefilter('always', DeprecationWarning) + old_api() + + self.assertEqual(__file__, caught[0].filename) + + def test_caller_filters_are_restored(self): + @deprecated("use new_api instead") + def old_api(): + return 'ok' + + with warnings.catch_warnings(): + warnings.simplefilter('ignore', DeprecationWarning) + before = warnings.filters[:] + old_api() + after = warnings.filters[:] + + self.assertEqual(before, after) + + def test_caller_filters_still_apply_after_the_call(self): + @deprecated("use new_api instead") + def old_api(): + return 'ok' + + with warnings.catch_warnings(record=True) as caught: + warnings.simplefilter('ignore', DeprecationWarning) + old_api() + warnings.warn('unrelated', DeprecationWarning) + + self.assertEqual( + ["Call to deprecated function 'old_api'. use new_api instead"], + [str(warning.message) for warning in caught], + ) + + async def test_async_warning_is_attributed_to_the_caller(self): + @deprecated("use new_api instead") + async def old_api(): + return 'ok' + + with warnings.catch_warnings(record=True) as caught: + warnings.simplefilter('always', DeprecationWarning) + await old_api() + + self.assertEqual(__file__, caught[0].filename) + + async def test_awaited_call_is_not_affected_by_the_temporary_filter(self): + @deprecated("use new_api instead") + async def old_api(): + warnings.warn('unrelated', DeprecationWarning) + await asyncio.sleep(0) + warnings.warn('unrelated after await', DeprecationWarning) + return 'ok' + + with warnings.catch_warnings(record=True) as caught: + warnings.simplefilter('ignore', DeprecationWarning) + result = await old_api() + + self.assertEqual('ok', result) + self.assertEqual( + ["Call to deprecated function 'old_api'. use new_api instead"], + [str(warning.message) for warning in caught], + ) + + async def test_awaited_call_runs_without_the_always_filter(self): + observed = [] + + @deprecated("use new_api instead") + async def old_api(): + observed.extend( + (action, category) + for action, message, category, module, lineno in warnings.filters + if category is DeprecationWarning + ) + return 'ok' + + with warnings.catch_warnings(): + warnings.simplefilter('ignore', DeprecationWarning) + await old_api() + + self.assertNotIn(('always', DeprecationWarning), observed) + + async def test_async_caller_filters_are_restored(self): + @deprecated("use new_api instead") + async def old_api(): + return 'ok' + + with warnings.catch_warnings(): + warnings.simplefilter('ignore', DeprecationWarning) + before = warnings.filters[:] + await old_api() + after = warnings.filters[:] + + self.assertEqual(before, after) diff --git a/test/test_integration.py b/test/test_integration.py new file mode 100644 index 00000000..5a96ad3a --- /dev/null +++ b/test/test_integration.py @@ -0,0 +1,487 @@ +"""End-to-end checks against a real local server over real sockets. + +The unit suite mocks at the transport layer, so it never exercises TCP, TLS, +keep-alive or real concurrency. These tests drive the SDK against a real +HTTP(S) server bound to 127.0.0.1 and assert on what actually went over the wire. +""" + +import asyncio +import hashlib +import json +import shutil +import ssl +import subprocess +import tempfile +import threading +import time +import unittest +from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer +from urllib.parse import parse_qs, urlparse + +from appwrite.client import Client +from appwrite.exception import AppwriteException +from appwrite.input_file import InputFile +from appwrite.services.storage import Storage + + +class _State: + """Thread-safe counters describing what the server actually observed.""" + + def __init__(self): + self.lock = threading.Lock() + self.reset() + + def reset(self): + self.connections = 0 + self.requests = 0 + self.in_flight = 0 + self.peak_in_flight = 0 + self.chunks = [] + self.chunk_size = 0 + self.expected_total = 0 + self.file_id = 'file-1' + + def enter(self): + with self.lock: + self.in_flight += 1 + self.requests += 1 + self.peak_in_flight = max(self.peak_in_flight, self.in_flight) + + def leave(self): + with self.lock: + self.in_flight -= 1 + + def record_chunk(self, index, payload, content_range, upload_id): + with self.lock: + self.chunks.append( + { + 'index': index, + 'payload': payload, + 'content_range': content_range, + 'upload_id': upload_id, + } + ) + + +def _multipart_parts(body, content_type): + """Split a raw multipart body into (headers, payload) pairs.""" + boundary = None + for piece in content_type.split(';')[1:]: + key, _, value = piece.strip().partition('=') + if key.lower() == 'boundary': + boundary = value.strip('"') + if not boundary: + return [] + + marker = ('--' + boundary).encode() + parts = [] + for raw in body.split(marker)[1:]: + if raw.startswith(b'--'): + break + if raw.startswith(b'\r\n'): + raw = raw[2:] + head, _, payload = raw.partition(b'\r\n\r\n') + if payload.endswith(b'\r\n'): + payload = payload[:-2] + parts.append((head, payload)) + return parts + + +def _build_handler(state): + class Handler(BaseHTTPRequestHandler): + protocol_version = 'HTTP/1.1' + + def setup(self): + super().setup() + with state.lock: + state.connections += 1 + self.connection_id = state.connections + + def log_message(self, *args): + pass + + def _read_body(self): + length = int(self.headers.get('Content-Length') or 0) + return self.rfile.read(length) if length else b'' + + def _send(self, status, body=b'', content_type='application/json', extra=None): + if isinstance(body, str): + body = body.encode('utf-8') + self.send_response(status) + self.send_header('Content-Type', content_type) + self.send_header('Content-Length', str(len(body))) + for key, value in (extra or {}).items(): + self.send_header(key, value) + self.end_headers() + if body: + self.wfile.write(body) + + def _send_json(self, status, payload, extra=None): + self._send(status, json.dumps(payload), 'application/json', extra) + + def _route(self, path, query, body): + if path == '/slow': + time.sleep(float(query.get('delay', ['0.25'])[0])) + self._send_json(200, {'ok': True, 'connection': self.connection_id}) + return + + if path == '/echo': + parts = _multipart_parts(body, self.headers.get('Content-Type', '')) + file_parts = [payload for head, payload in parts if b'filename=' in head] + self._send_json( + 200, + { + 'method': self.command, + 'path': path, + 'query': query, + 'body_len': len(body), + 'body_text': body.decode('utf-8', 'replace'), + 'body_sha256': hashlib.sha256(body).hexdigest(), + 'content_range': self.headers.get('content-range'), + 'x_appwrite_id': self.headers.get('x-appwrite-id'), + 'file_sha256': hashlib.sha256(file_parts[0]).hexdigest() if file_parts else None, + 'file_len': len(file_parts[0]) if file_parts else 0, + }, + ) + return + + if path == '/error': + self._send_json(404, {'message': 'Resource not found', 'type': 'not_found', 'code': 404}) + return + + if path == '/text': + self._send(200, 'plain text body', 'text/plain') + return + + if path == '/binary': + self._send(200, bytes(range(256)), 'application/octet-stream') + return + + if path == '/location': + self._send_json(200, {'ok': True}, {'Location': 'https://example.com/redirected'}) + return + + if path == '/redirect': + self._send(302, b'', 'text/plain', {'Location': '/echo'}) + return + + if self.command == 'GET': + # Resume probe for a chunked upload. + total = (state.expected_total + state.chunk_size - 1) // max(state.chunk_size, 1) + self._send_json(200, {'$id': state.file_id, 'chunksTotal': total, 'chunksUploaded': 0}) + return + + # Chunk upload. + content_range = self.headers.get('content-range') + start = int(content_range.split(' ')[1].split('-')[0]) if content_range else 0 + index = start // state.chunk_size if state.chunk_size else 0 + parts = _multipart_parts(body, self.headers.get('Content-Type', '')) + file_parts = [payload for head, payload in parts if b'filename=' in head] + state.record_chunk( + index, + file_parts[0] if file_parts else b'', + content_range, + self.headers.get('x-appwrite-id'), + ) + + total_chunks = (state.expected_total + state.chunk_size - 1) // max(state.chunk_size, 1) + self._send_json( + 200, + { + '$id': state.file_id, + 'chunksTotal': total_chunks, + 'chunksUploaded': len({chunk['index'] for chunk in state.chunks}), + }, + ) + + def _handle(self): + parsed = urlparse(self.path) + body = self._read_body() + state.enter() + try: + self._route(parsed.path, parse_qs(parsed.query), body) + finally: + state.leave() + + do_GET = _handle + do_POST = _handle + do_PUT = _handle + do_DELETE = _handle + do_PATCH = _handle + + return Handler + + +class _Server: + def __init__(self, tls=False): + self.state = _State() + self.httpd = ThreadingHTTPServer(('127.0.0.1', 0), _build_handler(self.state)) + self.httpd.daemon_threads = True + self.certdir = None + if tls: + self.certdir = tempfile.mkdtemp(prefix='appwrite-tls-') + self._make_cert() + context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER) + context.load_cert_chain(self.certdir + '/cert.pem', self.certdir + '/key.pem') + self.httpd.socket = context.wrap_socket(self.httpd.socket, server_side=True) + self.port = self.httpd.server_address[1] + self.scheme = 'https' if tls else 'http' + self.thread = threading.Thread(target=self.httpd.serve_forever, daemon=True) + self.thread.start() + + def _make_cert(self): + subprocess.run( + [ + 'openssl', + 'req', + '-x509', + '-newkey', + 'rsa:2048', + '-keyout', + self.certdir + '/key.pem', + '-out', + self.certdir + '/cert.pem', + '-days', + '1', + '-nodes', + '-subj', + '/CN=localhost', + ], + check=True, + capture_output=True, + ) + + @property + def endpoint(self): + return f'{self.scheme}://localhost:{self.port}' + + def close(self): + self.httpd.shutdown() + self.httpd.server_close() + if self.certdir: + shutil.rmtree(self.certdir, ignore_errors=True) + + +class _LiveServerTest(unittest.IsolatedAsyncioTestCase): + server = None + + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.server = _Server() + + @classmethod + def tearDownClass(cls): + super().tearDownClass() + cls.server.close() + + async def asyncSetUp(self): + self.client = Client() + self.client.set_endpoint(self.server.endpoint) + self.state = self.server.state + + async def asyncTearDown(self): + await self.client.aclose() + + +class TestRealRequests(_LiveServerTest): + async def test_request_round_trips_over_a_real_socket(self): + response = await self.client.call('get', '/echo', {}, {'probe': 'yes'}) + + self.assertEqual(response['method'], 'GET') + self.assertEqual(response['path'], '/echo') + self.assertEqual(response['query'], {'probe': ['yes']}) + self.assertGreater(self.state.connections, 0) + + async def test_json_body_is_sent_and_parsed(self): + body = {'name': 'Walter', 'active': True} + response = await self.client.call('post', '/echo', {'content-type': 'application/json'}, body) + + self.assertEqual(response['method'], 'POST') + self.assertEqual(response['body_text'], json.dumps(body)) + + async def test_multipart_file_bytes_reach_the_server_intact(self): + payload = b'\x00\x01\x02binary\xff' * 100 + response = await self.client.call( + 'post', + '/echo', + {'content-type': 'multipart/form-data'}, + {'file': InputFile.from_bytes(payload, 'blob.bin'), 'name': 'blob'}, + ) + + self.assertEqual(response['file_len'], len(payload)) + self.assertEqual(response['file_sha256'], hashlib.sha256(payload).hexdigest()) + + async def test_binary_response_is_returned_as_bytes(self): + response = await self.client.call('get', '/binary') + + self.assertIsInstance(response, bytes) + self.assertEqual(response, bytes(range(256))) + + async def test_text_response_is_decoded(self): + response = await self.client.call('get', '/text', response_type='text') + + self.assertEqual(response, 'plain text body') + + async def test_location_response_type_returns_the_header(self): + response = await self.client.call('get', '/location', response_type='location') + + self.assertEqual(response, 'https://example.com/redirected') + + async def test_error_response_raises_appwrite_exception(self): + with self.assertRaises(AppwriteException) as context: + await self.client.call('get', '/error') + + self.assertEqual(context.exception.code, 404) + self.assertEqual(context.exception.message, 'Resource not found') + self.assertEqual(context.exception.type, 'not_found') + + async def test_connection_refused_is_wrapped_in_appwrite_exception(self): + client = Client() + client.set_endpoint('http://127.0.0.1:1/v1') + try: + with self.assertRaises(AppwriteException): + await client.call('get', '/echo') + finally: + await client.aclose() + + +class TestRealConcurrency(_LiveServerTest): + async def test_requests_overlap_on_the_wire(self): + """Sequential calls pay the delay every time; concurrent calls overlap.""" + count = 8 + delay = 0.25 + + self.state.reset() + started = time.perf_counter() + for _ in range(count): + await self.client.call('get', '/slow', {}, {'delay': str(delay)}) + sequential = time.perf_counter() - started + + self.state.reset() + started = time.perf_counter() + await asyncio.gather(*[self.client.call('get', '/slow', {}, {'delay': str(delay)}) for _ in range(count)]) + concurrent = time.perf_counter() - started + + self.assertGreater(sequential, delay * count * 0.9, 'sequential baseline should pay the delay every time') + self.assertLess(concurrent, sequential / 3, 'concurrent calls should overlap instead of queueing') + self.assertGreater(self.state.peak_in_flight, 1, 'the server never handled two requests at once') + + async def test_each_concurrent_request_gets_its_own_connection(self): + count = 6 + self.state.reset() + + await asyncio.gather(*[self.client.call('get', '/slow', {}, {'delay': '0.2'}) for _ in range(count)]) + + self.assertEqual(self.state.requests, count) + self.assertEqual(self.state.connections, count, 'requests were serialised onto a single connection') + + async def test_connection_pool_is_reused_for_sequential_calls(self): + self.state.reset() + + for _ in range(5): + await self.client.call('get', '/echo') + + self.assertEqual(self.state.requests, 5) + self.assertEqual(self.state.connections, 1, 'keep-alive should reuse a single connection') + + +class TestRealChunkedUpload(_LiveServerTest): + async def test_chunks_arrive_intact_over_real_multipart(self): + payload = bytes(range(256)) * 800 # 204800 bytes + chunk_size = 51_200 # exactly 4 chunks + self.state.reset() + self.state.chunk_size = chunk_size + self.state.expected_total = len(payload) + self.state.file_id = 'file-1' + + self.client._chunk_size = chunk_size + progress = [] + + async def on_progress(update): + progress.append(update) + + storage = Storage(self.client) + result = await storage.create_file( + bucket_id='bucket-1', + file_id='file-1', + file=InputFile.from_bytes(payload, 'blob.bin'), + on_progress=on_progress, + ) + + self.assertEqual(result.id, 'file-1') + + chunks = sorted(self.state.chunks, key=lambda chunk: chunk['index']) + self.assertEqual(len(chunks), 4) + self.assertEqual( + hashlib.sha256(b''.join(chunk['payload'] for chunk in chunks)).hexdigest(), + hashlib.sha256(payload).hexdigest(), + 'the bytes that arrived on the wire differ from the bytes we sent', + ) + self.assertEqual( + sorted(chunk['content_range'] for chunk in chunks), + [ + 'bytes 0-51199/204800', + 'bytes 102400-153599/204800', + 'bytes 153600-204799/204800', + 'bytes 51200-102399/204800', + ], + ) + self.assertEqual([chunk['upload_id'] for chunk in chunks], ['file-1'] * 4) + + self.assertEqual(max(item['progress'] for item in progress), 100.0) + self.assertEqual(sorted(item['chunksUploaded'] for item in progress), [1, 2, 3, 4]) + + +class TestRealTls(unittest.IsolatedAsyncioTestCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + if shutil.which('openssl') is None: + raise unittest.SkipTest('openssl is required to generate a self-signed certificate') + cls.server = _Server(tls=True) + + @classmethod + def tearDownClass(cls): + super().tearDownClass() + cls.server.close() + + async def test_self_signed_certificate_is_rejected_by_default(self): + client = Client() + client.set_endpoint(self.server.endpoint) + try: + with self.assertRaises(AppwriteException): + await client.call('get', '/echo') + finally: + await client.aclose() + + async def test_self_signed_certificate_is_accepted_after_opt_in(self): + async with Client() as client: + client.set_endpoint(self.server.endpoint) + client.set_self_signed() + response = await client.call('get', '/echo') + + self.assertEqual(response['method'], 'GET') + + +class TestRealAppwriteCloud(unittest.IsolatedAsyncioTestCase): + """Talks to the real Appwrite Cloud endpoint over real TLS.""" + + async def test_cloud_endpoint_rejects_unauthenticated_call(self): + async with Client() as client: + client.set_endpoint('https://cloud.appwrite.io/v1') + try: + with self.assertRaises(AppwriteException) as context: + await asyncio.wait_for(client.call('get', '/health'), timeout=20) + except TimeoutError: + self.skipTest('Appwrite Cloud did not answer within 20s') + + if context.exception.code is None: + self.skipTest(f'Appwrite Cloud is unreachable from this machine: {context.exception.message}') + + self.assertEqual(context.exception.code, 401) + self.assertIn('missing scopes', context.exception.message) + + +if __name__ == '__main__': + unittest.main() diff --git a/test/test_query.py b/test/test_query.py index ae47a4b1..77896e16 100644 --- a/test/test_query.py +++ b/test/test_query.py @@ -3,7 +3,8 @@ from urllib.parse import parse_qsl from urllib.parse import urlsplit -import requests_mock +import httpx2 +import respx from appwrite.client import Client from appwrite.query import Query @@ -30,7 +31,7 @@ def __init__(self, description: str, value, expected_values): ] -class TestQueryMethods(unittest.TestCase): +class TestQueryMethods(unittest.IsolatedAsyncioTestCase): def test_equal(self): for t in tests: @@ -352,39 +353,40 @@ def test_flatten_splices_builders_beside_nested_string_arrays(self): Query._flatten([builder, ['a', 'b']]), ) - @requests_mock.Mocker() - def test_client_sends_flattened_params(self, m): - m.register_uri( - requests_mock.ANY, - requests_mock.ANY, - json={}, - headers={'Content-Type': 'application/json'}, + @respx.mock + async def test_client_sends_flattened_params(self): + respx.route().mock( + return_value=httpx2.Response(200, json={}, headers={'Content-Type': 'application/json'}), ) - client = Client().set_endpoint('https://example.com/v1') queries = [Query.limit(1), Query.offset(2)] def params(): return {'queries': Query.builder().limit(1).offset(2), 'tags': [['a', 'b']]} - client.call('post', '/items', {'content-type': 'application/json'}, params()) - client.call('get', '/items', {'content-type': 'application/json'}, params()) - client.call('post', '/items', {'content-type': 'multipart/form-data'}, params()) + async with Client().set_endpoint('https://example.com/v1') as client: + await client.call('post', '/items', {'content-type': 'application/json'}, params()) + await client.call('get', '/items', {'content-type': 'application/json'}, params()) + await client.call('post', '/items', {'content-type': 'multipart/form-data'}, params()) - json_request, get_request, multipart_request = m.request_history - self.assertEqual( - {'queries': queries, 'tags': [['a', 'b']]}, - json.loads(json_request.body), - ) - self.assertEqual( - [ - ('queries[0]', queries[0]), - ('queries[1]', queries[1]), - ('tags[0][0]', 'a'), - ('tags[0][1]', 'b'), - ], - parse_qsl(urlsplit(get_request.url).query), - ) - multipart_body = multipart_request.body.decode() - self.assertIn('name="tags[0][0]"\r\n\r\na\r\n', multipart_body) - self.assertIn('name="tags[0][1]"\r\n\r\nb\r\n', multipart_body) - self.assertIn(f'name="queries[1]"\r\n\r\n{queries[1]}\r\n', multipart_body) + json_request, get_request, multipart_request = [call.request for call in respx.calls] + + await json_request.aread() + await multipart_request.aread() + + self.assertEqual( + {'queries': queries, 'tags': [['a', 'b']]}, + json.loads(json_request.content), + ) + self.assertEqual( + [ + ('queries[0]', queries[0]), + ('queries[1]', queries[1]), + ('tags[0][0]', 'a'), + ('tags[0][1]', 'b'), + ], + parse_qsl(urlsplit(str(get_request.url)).query), + ) + multipart_body = multipart_request.content.decode() + self.assertIn('name="tags[0][0]"\r\n\r\na\r\n', multipart_body) + self.assertIn('name="tags[0][1]"\r\n\r\nb\r\n', multipart_body) + self.assertIn(f'name="queries[1]"\r\n\r\n{queries[1]}\r\n', multipart_body)