-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
111 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
test/integration_new/context_managers/box_retention_policy_assigment.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from typing import Any, Union | ||
|
||
from boxsdk.object.enterprise import Enterprise | ||
from boxsdk.object.folder import Folder | ||
from boxsdk.object.metadata_template import MetadataTemplate | ||
from boxsdk.object.retention_policy import RetentionPolicy | ||
from boxsdk.object.retention_policy_assignment import RetentionPolicyAssignment | ||
|
||
|
||
class BoxRetentionPolicyAssignment: | ||
|
||
def __init__( | ||
self, | ||
retention_policy: RetentionPolicy, | ||
assignee: Union['Folder', 'Enterprise', 'MetadataTemplate'] | ||
): | ||
self._retention_policy_assignment = retention_policy.assign(assignee) | ||
|
||
def __enter__(self) -> RetentionPolicyAssignment: | ||
return self._retention_policy_assignment | ||
|
||
def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> None: | ||
self._retention_policy_assignment.delete() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
test/integration_new/object/retention_policy_assignement_itest.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from datetime import datetime | ||
import pytest | ||
|
||
from boxsdk import BoxAPIException | ||
from test.integration_new.context_managers.box_retention_policy import BoxRetentionPolicy | ||
from test.integration_new.context_managers.box_test_file import BoxTestFile | ||
from test.integration_new.context_managers.box_test_folder import BoxTestFolder | ||
|
||
|
||
RETENTION_POLICY_ASSIGNMENT_TESTS_DIRECTORY_NAME = 'retention-policy-assignment-integration-tests' | ||
|
||
|
||
@pytest.fixture(scope="module", autouse=True) | ||
def parent_folder(): | ||
with BoxTestFolder(name=f'{RETENTION_POLICY_ASSIGNMENT_TESTS_DIRECTORY_NAME} {datetime.now()}') as folder: | ||
yield folder | ||
|
||
|
||
@pytest.fixture(scope="module", autouse=True) | ||
def test_file(parent_folder, small_file_path): | ||
with BoxTestFile(parent_folder=parent_folder, file_path=small_file_path) as file: | ||
yield file | ||
|
||
|
||
def test_delete_retention_policy_assignment(parent_folder, small_file_path): | ||
with BoxRetentionPolicy(disposition_action='permanently_delete', retention_length=1) as retention_policy: | ||
with BoxTestFolder(name=f'{RETENTION_POLICY_ASSIGNMENT_TESTS_DIRECTORY_NAME} {datetime.now()}') as folder_under_retention: | ||
retention_policy_assignment = retention_policy.assign(folder_under_retention) | ||
|
||
assignment = retention_policy_assignment.get() | ||
assert assignment.id is not None | ||
|
||
retention_policy_assignment.delete() | ||
|
||
with pytest.raises(BoxAPIException): | ||
retention_policy_assignment.get() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters