diff --git a/.codegen.json b/.codegen.json index 4e55a1e..a429885 100644 --- a/.codegen.json +++ b/.codegen.json @@ -1 +1 @@ -{ "engineHash": "f0bd1ce", "specHash": "1698c95", "version": "0.6.4" } +{ "engineHash": "267eec8", "specHash": "1698c95", "version": "0.6.4" } diff --git a/box_sdk_gen/internal/base_object.py b/box_sdk_gen/internal/base_object.py index f903465..3e266b4 100644 --- a/box_sdk_gen/internal/base_object.py +++ b/box_sdk_gen/internal/base_object.py @@ -48,7 +48,7 @@ def to_dict(self) -> dict: @classmethod def _deserialize(cls, key, value, annotation=None): - if annotation is None: + if annotation is None or value is None: return value if get_origin(annotation) == Optional: return cls._deserialize(key, value, get_args(annotation)) @@ -69,13 +69,15 @@ def _deserialize(cls, key, value, annotation=None): return cls._deserialize_datetime(key, value, annotation) elif annotation == date: return cls._deserialize_date(key, value, annotation) - else: + elif isinstance(annotation, type) and issubclass(annotation, BaseObject): return cls._deserialize_nested_type(key, value, annotation) + else: + return value @classmethod def _deserialize_list(cls, key, value, annotation: list): - list_type = get_args(annotation)[0] try: + list_type = get_args(annotation)[0] return [ cls._deserialize(key, list_entry, list_type) for list_entry in value ] @@ -84,27 +86,32 @@ def _deserialize_list(cls, key, value, annotation: list): @classmethod def _deserialize_union(cls, key, value, annotation): - possible_types = get_args(annotation) - if value is None: - if type(None) not in possible_types: - print('Value: ', value, 'should not be allowed in Union:', annotation) + try: + possible_types = get_args(annotation) + if value is None: + if type(None) not in possible_types: + print( + 'Value: ', value, 'should not be allowed in Union:', annotation + ) + return value + + for possible_type in possible_types: + if ( + isinstance(possible_type, type) + and issubclass(possible_type, BaseObject) + and value.get(possible_type._discriminator[0], None) + in possible_type._discriminator[1] + ): + return cls._deserialize(key, value, possible_type) + + for possible_type in possible_types: + try: + return cls._deserialize(key, value, possible_type) + except Exception: + continue + return value + except Exception: return value - - for possible_type in possible_types: - if ( - issubclass(possible_type, BaseObject) - and value.get(possible_type._discriminator[0], None) - in possible_type._discriminator[1] - ): - return cls._deserialize(key, value, possible_type) - - for possible_type in possible_types: - try: - return cls._deserialize(key, value, possible_type) - except Exception: - continue - - return value @classmethod def _deserialize_enum(cls, key, value, annotation): diff --git a/docs/tasks.md b/docs/tasks.md index 11d7a5d..34499f6 100644 --- a/docs/tasks.md +++ b/docs/tasks.md @@ -51,7 +51,7 @@ See the endpoint docs at ```python -client.tasks.create_task(CreateTaskItem(type=CreateTaskItemTypeField.FILE.value, id=file.id), action=CreateTaskAction.REVIEW.value, message='test message', due_at=date, completion_rule=CreateTaskCompletionRule.ALL_ASSIGNEES.value) +client.tasks.create_task(CreateTaskItem(type=CreateTaskItemTypeField.FILE.value, id=file.id), action=CreateTaskAction.REVIEW.value, message='test message', due_at=date_time, completion_rule=CreateTaskCompletionRule.ALL_ASSIGNEES.value) ``` ### Arguments diff --git a/test/legal_hold_policies.py b/test/legal_hold_policies.py index c2219d5..cfb62ff 100644 --- a/test/legal_hold_policies.py +++ b/test/legal_hold_policies.py @@ -2,6 +2,8 @@ from box_sdk_gen.schemas import LegalHoldPolicies +from box_sdk_gen.internal.utils import DateTime + from box_sdk_gen.internal.utils import get_uuid from box_sdk_gen.internal.utils import date_time_from_string @@ -47,23 +49,23 @@ def testCreateUpdateGetDeleteLegalHoldPolicy(): def testCreateNotOngoingLegalHoldPolicy(): legal_hold_policy_name: str = get_uuid() legal_hold_description: str = 'test description' + filter_started_at: DateTime = date_time_from_string('2021-01-01T00:00:00-08:00') + filter_ended_at: DateTime = date_time_from_string('2022-01-01T00:00:00-08:00') legal_hold_policy: LegalHoldPolicy = ( client.legal_hold_policies.create_legal_hold_policy( legal_hold_policy_name, description=legal_hold_description, - filter_started_at=date_time_from_string('2021-01-01T00:00:00-08:00'), - filter_ended_at=date_time_from_string('2022-01-01T00:00:00-08:00'), + filter_started_at=filter_started_at, + filter_ended_at=filter_ended_at, is_ongoing=False, ) ) assert legal_hold_policy.policy_name == legal_hold_policy_name assert legal_hold_policy.description == legal_hold_description - assert ( - date_time_to_string(legal_hold_policy.filter_started_at) - == '2021-01-01T00:00:00-08:00' - ) - assert ( - date_time_to_string(legal_hold_policy.filter_ended_at) - == '2022-01-01T00:00:00-08:00' - ) + assert date_time_to_string( + legal_hold_policy.filter_started_at + ) == date_time_to_string(filter_started_at) + assert date_time_to_string( + legal_hold_policy.filter_ended_at + ) == date_time_to_string(filter_ended_at) client.legal_hold_policies.delete_legal_hold_policy_by_id(legal_hold_policy.id) diff --git a/test/tasks.py b/test/tasks.py index d946189..f3e53fd 100644 --- a/test/tasks.py +++ b/test/tasks.py @@ -43,17 +43,17 @@ def testCreateUpdateGetDeleteTask(): generate_byte_stream(10), ) file: FileFull = files.entries[0] - date: DateTime = date_time_from_string('2035-01-01T00:00:00Z') + date_time: DateTime = date_time_from_string('2035-01-01T00:00:00Z') task: Task = client.tasks.create_task( CreateTaskItem(type=CreateTaskItemTypeField.FILE.value, id=file.id), action=CreateTaskAction.REVIEW.value, message='test message', - due_at=date, + due_at=date_time, completion_rule=CreateTaskCompletionRule.ALL_ASSIGNEES.value, ) assert task.message == 'test message' assert task.item.id == file.id - assert date_time_to_string(task.due_at) == '2035-01-01T00:00:00Z' + assert date_time_to_string(task.due_at) == date_time_to_string(date_time) task_by_id: Task = client.tasks.get_task_by_id(task.id) assert task_by_id.id == task.id task_on_file: Tasks = client.tasks.get_file_tasks(file.id)