Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

codegen output dc17b3f3b2cb4c9daa19df363eb352c5 #35

Merged
merged 1 commit into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions box_sdk_gen/ccg_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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,
Expand Down
13 changes: 10 additions & 3 deletions box_sdk_gen/developer_token_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
8 changes: 4 additions & 4 deletions box_sdk_gen/jwt_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions box_sdk_gen/oauth.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
24 changes: 20 additions & 4 deletions docs/file_versions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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_
<!-- sample get_files_id_versions -->

```python
client.file_versions.get_file_versions(file_id=file.id)
```

### Arguments

Expand Down Expand Up @@ -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_
<!-- sample get_files_id_versions_id -->

```python
client.file_versions.get_file_version_by_id(file_id=file.id, file_version_id=file_versions.entries[0].id)
```

### Arguments

Expand Down Expand Up @@ -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_
<!-- sample delete_files_id_versions_id -->

```python
client.file_versions.delete_file_version_by_id(file_id=file.id, file_version_id=file_versions_restored.entries[0].id)
```

### Arguments

Expand Down Expand Up @@ -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_
<!-- sample post_files_id_versions_current -->

```python
client.file_versions.promote_file_version(file_id=file.id, id=file_versions.entries[0].id, type=PromoteFileVersionTypeArg.FILE_VERSION.value)
```

### Arguments

Expand Down
85 changes: 85 additions & 0 deletions test/file_versions.py
Original file line number Diff line number Diff line change
@@ -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)
Loading