Skip to content

Commit

Permalink
Merge branch 'main' into sdk-2810-marker-in-trash-getitem
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszsocha2 committed Dec 22, 2022
2 parents 4cfd300 + 23d763a commit 523bb20
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
8 changes: 6 additions & 2 deletions boxsdk/object/terms_of_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ class TermsOfService(BaseObject):

_item_type = 'terms_of_service'

def get_user_status(self, user: Optional['User'] = None) -> 'TermsOfServiceUserStatus':
def get_user_status(self, user: Optional['User'] = None) -> Optional['TermsOfServiceUserStatus']:
"""
Get the terms of service user status.
:param user:
This is the user to get the status of the terms of service for. This defaults to current
user.
:returns:
A :class:`TermsOfServiceUserStatus` object
A :class:`TermsOfServiceUserStatus` object or None if no user status found.
"""
url = self._session.get_url('terms_of_service_user_statuses')
additional_params = {
Expand All @@ -45,6 +45,10 @@ def get_user_status(self, user: Optional['User'] = None) -> 'TermsOfServiceUserS
additional_params['user_id'] = user.object_id
box_response = self._session.get(url, params=additional_params)
response_object = box_response.json()

if not response_object['entries']:
return None

response = response_object['entries'][0]
return self.translator.translate(
session=self._session,
Expand Down
11 changes: 10 additions & 1 deletion test/unit/object/test_terms_of_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def test_get_user_status(test_terms_of_service, mock_user, test_terms_of_service
'created_at': created_at,
}
mock_box_session.get.return_value.json.return_value = {
'limit': 500,
'total_count': 2,
'entries': [mock_user_status],
}
new_terms_of_service_user_status = test_terms_of_service.get_user_status(user=mock_user)
Expand All @@ -121,6 +121,15 @@ def test_get_user_status(test_terms_of_service, mock_user, test_terms_of_service
assert new_terms_of_service_user_status.created_at == created_at


def test_get_empty_user_status(test_terms_of_service, mock_user, mock_box_session):
mock_box_session.get.return_value.json.return_value = {
'total_count': 1,
'entries': [],
}
new_terms_of_service_user_status = test_terms_of_service.get_user_status(user=mock_user)
assert new_terms_of_service_user_status is None


def test_set_user_status(test_terms_of_service, mock_user, mock_box_session):
expected_post_url = f"{API.BASE_API_URL}/terms_of_service_user_statuses"
expected_put_url = f"{API.BASE_API_URL}/terms_of_service_user_statuses/{test_terms_of_service.object_id}"
Expand Down

0 comments on commit 523bb20

Please sign in to comment.