Skip to content

Commit

Permalink
fix: Rename filter date params in legal hold creation according to th…
Browse files Browse the repository at this point in the history
…e documentation
  • Loading branch information
arjankowski committed Apr 4, 2023
1 parent 7793934 commit b33ff39
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 16 deletions.
16 changes: 8 additions & 8 deletions boxsdk/client/client.py
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
35 changes: 35 additions & 0 deletions test/integration_new/object/legal_hold_policy_itest.py
@@ -0,0 +1,35 @@
from test.integration_new import util
from test.integration_new import CLIENT


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
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

0 comments on commit b33ff39

Please sign in to comment.