Skip to content

Commit

Permalink
Merge 012d21f into 7793934
Browse files Browse the repository at this point in the history
  • Loading branch information
arjankowski committed Apr 5, 2023
2 parents 7793934 + 012d21f commit f457dd4
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 18 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ on:

jobs:
build:
runs-on: ubuntu-20.04
runs-on: macos-latest
strategy:
matrix:
python-version:
- '3.6'
- 'pypy-3.6-v7.3.3'
- 'pypy-3.6'
- '3.7'
- 'pypy-3.7'
- '3.8'
Expand Down
16 changes: 8 additions & 8 deletions boxsdk/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,8 @@ def create_legal_hold_policy(
self,
policy_name: str,
description: Optional[str] = None,
filter_starting_at: Union[datetime, str] = None,
filter_ending_at: Union[datetime, str] = None,
filter_started_at: Union[datetime, str] = None,
filter_ended_at: Union[datetime, str] = None,
is_ongoing: Optional[bool] = None
) -> 'LegalHoldPolicy':
"""
Expand All @@ -319,10 +319,10 @@ def create_legal_hold_policy(
The legal hold policy's display name.
:param description:
The description of the legal hold policy.
:param filter_starting_at:
:param filter_started_at:
The start date filter for legal hold policy. Takes a datetime string supported by the dateutil library
or a datetime.datetime object. If no timezone info provided, local timezone will be applied.
:param filter_ending_at:
:param filter_ended_at:
The end date filter for legal hold policy. Takes a datetime string supported by the dateutil library
or a datetime.datetime object. If no timezone info provided, local timezone will be applied.
:param is_ongoing:
Expand All @@ -335,10 +335,10 @@ def create_legal_hold_policy(
policy_attributes = {'policy_name': policy_name}
if description is not None:
policy_attributes['description'] = description
if filter_starting_at is not None:
policy_attributes['filter_starting_at'] = normalize_date_to_rfc3339_format(filter_starting_at)
if filter_ending_at is not None:
policy_attributes['filter_ending_at'] = normalize_date_to_rfc3339_format(filter_ending_at)
if filter_started_at is not None:
policy_attributes['filter_started_at'] = normalize_date_to_rfc3339_format(filter_started_at)
if filter_ended_at is not None:
policy_attributes['filter_ended_at'] = normalize_date_to_rfc3339_format(filter_ended_at)
if is_ongoing is not None:
policy_attributes['is_ongoing'] = is_ongoing
box_response = self._session.post(url, data=json.dumps(policy_attributes))
Expand Down
2 changes: 2 additions & 0 deletions boxsdk/session/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ def delete(self, url: str, **kwargs: Any) -> '_BoxResponse':
"""
if 'expect_json_response' not in kwargs:
kwargs['expect_json_response'] = False
if 'skip_retry_codes' not in kwargs:
kwargs['skip_retry_codes'] = {202}
return self.request('DELETE', url, **kwargs)

def options(self, url: str, **kwargs: Any) -> '_BoxResponse':
Expand Down
36 changes: 36 additions & 0 deletions test/integration_new/object/legal_hold_policy_itest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from test.integration_new import util
from test.integration_new import CLIENT
from boxsdk.exception import BoxAPIException


def test_create_legal_hold_policy():
policy_name = 'Test Legal Hold Policy ' + util.random_name()
description = 'Test Legal Hold Policy Description'
filter_started_at = '2021-12-12T10:53:43-08:00'
filter_ended_at = '2022-12-18T10:53:43-08:00'

legal_hold_policy = CLIENT.create_legal_hold_policy(
policy_name=policy_name,
description=description,
filter_started_at=filter_started_at,
filter_ended_at=filter_ended_at
)

try:
assert legal_hold_policy.policy_name == policy_name
assert legal_hold_policy.description == description
assert legal_hold_policy.filter_started_at == filter_started_at
assert legal_hold_policy.filter_ended_at == filter_ended_at

new_policy_name = 'Test Legal Hold Policy ' + util.random_name()
new_policy_description = 'Test Legal Hold Policy Description'
legal_hold_policy.update_info(data={
'policy_name': new_policy_name,
'description': new_policy_description
})

legal_hold_policy = CLIENT.legal_hold_policy(policy_id=legal_hold_policy.object_id).get()
assert legal_hold_policy.policy_name == new_policy_name
assert legal_hold_policy.description == new_policy_description
finally:
legal_hold_policy.delete()
16 changes: 8 additions & 8 deletions test/unit/client/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,23 +609,23 @@ def test_create_group_returns_the_correct_group_object(mock_client, mock_box_ses


@pytest.mark.parametrize('description', ('My test policy',))
@pytest.mark.parametrize('filter_starting_at', ('2016-01-01T00:00:00+00:00', datetime.datetime(2016, 1, 1, tzinfo=pytz.UTC)))
@pytest.mark.parametrize('filter_ending_at', ('2020-01-01T00:00:00+00:00', datetime.datetime(2020, 1, 1, tzinfo=pytz.UTC)))
@pytest.mark.parametrize('filter_started_at', ('2016-01-01T00:00:00+00:00', datetime.datetime(2016, 1, 1, tzinfo=pytz.UTC)))
@pytest.mark.parametrize('filter_ended_at', ('2020-01-01T00:00:00+00:00', datetime.datetime(2020, 1, 1, tzinfo=pytz.UTC)))
@pytest.mark.parametrize('is_ongoing', ('True',))
def test_create_legal_hold_policy_returns_the_correct_policy_object(
mock_client,
mock_box_session,
create_policy_response,
description,
filter_starting_at,
filter_ending_at,
filter_started_at,
filter_ended_at,
is_ongoing
):
# pylint:disable=redefined-outer-name
params = {
'description': description,
'filter_starting_at': filter_starting_at,
'filter_ending_at': filter_ending_at,
'filter_started_at': filter_started_at,
'filter_ended_at': filter_ended_at,
'is_ongoing': is_ongoing
}

Expand All @@ -639,8 +639,8 @@ def test_create_legal_hold_policy_returns_the_correct_policy_object(
expected_body = {
'policy_name': test_policy_name,
'description': description,
'filter_starting_at': normalize_date_to_rfc3339_format(filter_starting_at),
'filter_ending_at': normalize_date_to_rfc3339_format(filter_ending_at),
'filter_started_at': normalize_date_to_rfc3339_format(filter_started_at),
'filter_ended_at': normalize_date_to_rfc3339_format(filter_ended_at),
'is_ongoing': is_ongoing
}
mock_box_session.post.assert_called_once_with(expected_url, data=ANY)
Expand Down
6 changes: 6 additions & 0 deletions test/unit/session/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,12 @@ def test_box_session_retries_response_after_retry_after(
test_url,
):
# pylint:disable=redefined-outer-name
try:
if retry_after_response.status_code == 202 and test_method.__name__ == 'delete':
pytest.xfail("Delete operation should not be retried on 202 status code")
except AttributeError:
pass

mock_network_layer.request.side_effect = [retry_after_response, generic_successful_response]
mock_network_layer.retry_after.side_effect = lambda delay, request, *args, **kwargs: request(*args, **kwargs)

Expand Down

0 comments on commit f457dd4

Please sign in to comment.