From 1a9769b31c361c275daf871bb0677c32ce2052f1 Mon Sep 17 00:00:00 2001 From: box-sdk-build Date: Fri, 1 Sep 2023 05:30:10 -0700 Subject: [PATCH] generated with codegen at box/box-codegen@6219bf2 and spec at box/box-openapi@f01a34e --- box_sdk_gen/ccg_auth.py | 10 ++-- box_sdk_gen/developer_token_auth.py | 13 ++++- box_sdk_gen/jwt_auth.py | 8 +-- box_sdk_gen/oauth.py | 5 +- docs/file_versions.md | 24 ++++++-- test/file_versions.py | 85 +++++++++++++++++++++++++++++ 6 files changed, 127 insertions(+), 18 deletions(-) create mode 100644 test/file_versions.py diff --git a/box_sdk_gen/ccg_auth.py b/box_sdk_gen/ccg_auth.py index 03f5e75a..0b0a1cdd 100644 --- a/box_sdk_gen/ccg_auth.py +++ b/box_sdk_gen/ccg_auth.py @@ -76,8 +76,8 @@ def retrieve_token( ) -> AccessToken: """ Return a current token or get a new one when not available. - :return: - Access token + :param network_session: An object to keep network session state + :return: Access token """ if self.token is None: self.refresh_token(network_session=network_session) @@ -87,9 +87,9 @@ def refresh_token( self, network_session: Optional[NetworkSession] = None ) -> AccessToken: """ - Fetch a new access token - :return: - New access token + Return a current token or get a new one when not available. + :param network_session: An object to keep network session state + :return: Access token """ request_body = TokenRequest( grant_type=TokenRequestGrantType.CLIENT_CREDENTIALS, diff --git a/box_sdk_gen/developer_token_auth.py b/box_sdk_gen/developer_token_auth.py index 9ed8506a..3913226a 100644 --- a/box_sdk_gen/developer_token_auth.py +++ b/box_sdk_gen/developer_token_auth.py @@ -12,9 +12,16 @@ def __init__(self, token: str): def retrieve_token( self, network_session: Optional[NetworkSession] = None ) -> AccessToken: + """ + Retrieves stored developer token + :param network_session: An object to keep network session state + :return: Return a current token + """ return self.token - def refresh_token( - self, network_session: Optional[NetworkSession] = None - ) -> AccessToken: + def refresh_token(self, network_session: Optional[NetworkSession] = None): + """ + Developer token cannot be refreshed + :param network_session: An object to keep network session state + """ raise Exception("Developer token has expired. Please provide a new one.") diff --git a/box_sdk_gen/jwt_auth.py b/box_sdk_gen/jwt_auth.py index 1cc04622..e7f492dd 100644 --- a/box_sdk_gen/jwt_auth.py +++ b/box_sdk_gen/jwt_auth.py @@ -160,8 +160,8 @@ def retrieve_token( ) -> AccessToken: """ Return a current token or get a new one when not available. - :return: - Access token + :param network_session: An object to keep network session state + :return: Access token """ if self.token is None: self.refresh_token(network_session=network_session) @@ -172,8 +172,8 @@ def refresh_token( ) -> AccessToken: """ Fetch a new access token - :return: - New access token + :param network_session: An object to keep network session state + :return: New access token """ system_random = random.SystemRandom() jti_length = system_random.randint(16, 128) diff --git a/box_sdk_gen/oauth.py b/box_sdk_gen/oauth.py index c242e750..dcbfb0b4 100644 --- a/box_sdk_gen/oauth.py +++ b/box_sdk_gen/oauth.py @@ -1,6 +1,6 @@ import json from urllib.parse import urlencode, urlunsplit -from typing import Union, Optional +from typing import Optional from .auth import Authentication from .auth_schemas import TokenRequest, TokenRequestGrantType @@ -59,7 +59,7 @@ def __init__(self, config: OAuthConfig): Configuration object of OAuth. """ self.config = config - self.token: Union[None, AccessToken] = None + self.token: Optional[AccessToken] = None def get_authorize_url( self, options: Optional[GetAuthorizeUrlOptions] = None @@ -144,6 +144,7 @@ def refresh_token( """ Refresh outdated access token with refresh token :param network_session: An object to keep network session state + :param refresh_token: Refresh token, which can be used to obtain a new access token :return: Valid access token """ request_body = TokenRequest( diff --git a/docs/file_versions.md b/docs/file_versions.md index dbd6cdd5..e49d4b58 100644 --- a/docs/file_versions.md +++ b/docs/file_versions.md @@ -18,7 +18,11 @@ This operation is performed by calling function `get_file_versions`. See the endpoint docs at [API Reference](https://developer.box.com/reference/get-files-id-versions/). -_Currently we don't have an example for calling `get_file_versions` in integration tests_ + + +```python +client.file_versions.get_file_versions(file_id=file.id) +``` ### Arguments @@ -50,7 +54,11 @@ This operation is performed by calling function `get_file_version_by_id`. See the endpoint docs at [API Reference](https://developer.box.com/reference/get-files-id-versions-id/). -_Currently we don't have an example for calling `get_file_version_by_id` in integration tests_ + + +```python +client.file_versions.get_file_version_by_id(file_id=file.id, file_version_id=file_versions.entries[0].id) +``` ### Arguments @@ -115,7 +123,11 @@ This operation is performed by calling function `delete_file_version_by_id`. See the endpoint docs at [API Reference](https://developer.box.com/reference/delete-files-id-versions-id/). -_Currently we don't have an example for calling `delete_file_version_by_id` in integration tests_ + + +```python +client.file_versions.delete_file_version_by_id(file_id=file.id, file_version_id=file_versions_restored.entries[0].id) +``` ### Arguments @@ -159,7 +171,11 @@ This operation is performed by calling function `promote_file_version`. See the endpoint docs at [API Reference](https://developer.box.com/reference/post-files-id-versions-current/). -_Currently we don't have an example for calling `promote_file_version` in integration tests_ + + +```python +client.file_versions.promote_file_version(file_id=file.id, id=file_versions.entries[0].id, type=PromoteFileVersionTypeArg.FILE_VERSION.value) +``` ### Arguments diff --git a/test/file_versions.py b/test/file_versions.py new file mode 100644 index 00000000..8effaaa5 --- /dev/null +++ b/test/file_versions.py @@ -0,0 +1,85 @@ +from box_sdk_gen.schemas import Files + +from box_sdk_gen.managers.uploads import UploadFileAttributesArg + +from box_sdk_gen.managers.uploads import UploadFileAttributesArgParentField + +from box_sdk_gen.schemas import File + +from box_sdk_gen.managers.uploads import UploadFileVersionAttributesArg + +from box_sdk_gen.schemas import FileVersions + +from box_sdk_gen.schemas import FileVersionFull + +from box_sdk_gen.managers.file_versions import PromoteFileVersionTypeArg + +from box_sdk_gen.schemas import FileFull + +from box_sdk_gen.utils import decode_base_64 + +from box_sdk_gen.utils import get_env_var + +from box_sdk_gen.utils import get_uuid + +from box_sdk_gen.utils import generate_byte_stream + +from box_sdk_gen.client import Client + +from box_sdk_gen.jwt_auth import JWTAuth + +from box_sdk_gen.jwt_auth import JWTConfig + +jwt_config: JWTConfig = JWTConfig.from_config_json_string( + decode_base_64(get_env_var('JWT_CONFIG_BASE_64')) +) + +auth: JWTAuth = JWTAuth(config=jwt_config) + +client: Client = Client(auth=auth) + + +def testCreateListGetRestoreDeleteFileVersion(): + old_name: str = get_uuid() + new_name: str = get_uuid() + files: Files = client.uploads.upload_file( + attributes=UploadFileAttributesArg( + name=old_name, parent=UploadFileAttributesArgParentField(id='0') + ), + file=generate_byte_stream(10), + ) + file: File = files.entries[0] + assert file.name == old_name + assert file.size == 10 + new_files: Files = client.uploads.upload_file_version( + file_id=file.id, + attributes=UploadFileVersionAttributesArg(name=new_name), + file=generate_byte_stream(20), + ) + new_file: File = new_files.entries[0] + assert new_file.name == new_name + assert new_file.size == 20 + file_versions: FileVersions = client.file_versions.get_file_versions( + file_id=file.id + ) + assert file_versions.total_count == 1 + file_version: FileVersionFull = client.file_versions.get_file_version_by_id( + file_id=file.id, file_version_id=file_versions.entries[0].id + ) + assert file_version.id == file_versions.entries[0].id + client.file_versions.promote_file_version( + file_id=file.id, + id=file_versions.entries[0].id, + type=PromoteFileVersionTypeArg.FILE_VERSION.value, + ) + file_restored: FileFull = client.files.get_file_by_id(file_id=file.id) + assert file_restored.name == old_name + assert file_restored.size == 10 + file_versions_restored: FileVersions = client.file_versions.get_file_versions( + file_id=file.id + ) + client.file_versions.delete_file_version_by_id( + file_id=file.id, file_version_id=file_versions_restored.entries[0].id + ) + client.file_versions.get_file_versions(file_id=file.id) + client.files.delete_file_by_id(file_id=file.id)