-
Notifications
You must be signed in to change notification settings - Fork 219
Add new Recents API to client #210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
a91ed99
f9431f7
b283a7d
08b9235
884f557
e7b396d
c2205b3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| # coding: utf-8 | ||
|
|
||
| from __future__ import unicode_literals, absolute_import | ||
|
|
||
| from .base_endpoint import BaseEndpoint | ||
| from .base_api_json_object import BaseAPIJSONObject | ||
|
|
||
|
|
||
| class RecentItem(BaseEndpoint, BaseAPIJSONObject): | ||
| """Represents a single recent item accessed by a Box user.""" | ||
|
|
||
| _item_type = 'recent_item' | ||
|
|
||
| @property | ||
| def item(self): | ||
| """ | ||
| Returns the Box Item which this recent item references. | ||
| :rtype: | ||
| :class:`Item` | ||
| """ | ||
| item = self._response_object['item'] | ||
| return self.translator.translate(item['type'])( | ||
| session=self._session, | ||
| object_id=item['id'], | ||
| response_object=item, | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,6 +23,7 @@ | |
| from boxsdk.object.group import Group | ||
| from boxsdk.object.user import User | ||
| from boxsdk.object.group_membership import GroupMembership | ||
| from boxsdk.pagination.marker_based_object_collection import MarkerBasedObjectCollection | ||
|
|
||
|
|
||
| @pytest.fixture | ||
|
|
@@ -60,6 +61,11 @@ def folder_id(): | |
| return '1022' | ||
|
|
||
|
|
||
| @pytest.fixture(scope='module') | ||
| def marker_id(): | ||
| return 'marker_1' | ||
|
|
||
|
|
||
| @pytest.fixture(scope='module') | ||
| def users_response(user_id_1, user_id_2): | ||
| # pylint:disable=redefined-outer-name | ||
|
|
@@ -145,6 +151,19 @@ def search_response(file_id, folder_id): | |
| return mock_network_response | ||
|
|
||
|
|
||
| @pytest.fixture(scope='module') | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, this doesn't seem like something that should be module scoped.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See above |
||
| def recent_items_response(file_id): | ||
| mock_network_response = Mock(DefaultNetworkResponse) | ||
| mock_network_response.json.return_value = { | ||
| 'entries': [ | ||
| {'type': 'recent_item', 'item': {'type': 'file', 'id': file_id}} | ||
| ], | ||
| 'next_marker': None, | ||
| 'limit': 100, | ||
| } | ||
| return mock_network_response | ||
|
|
||
|
|
||
| @pytest.mark.parametrize('test_class, factory_method_name', [ | ||
| (Folder, 'folder'), | ||
| (File, 'file'), | ||
|
|
@@ -262,6 +281,31 @@ def test_create_group_returns_the_correct_group_object(mock_client, mock_box_ses | |
| assert new_group.name == test_group_name | ||
|
|
||
|
|
||
| def test_get_recent_items_returns_the_correct_items(mock_client, mock_box_session, recent_items_response, file_id): | ||
| mock_box_session.get.return_value = recent_items_response | ||
| recent_items = mock_client.get_recent_items() | ||
| assert isinstance(recent_items, MarkerBasedObjectCollection) | ||
| recent_item = recent_items.next() | ||
| assert recent_item.item.object_id == file_id | ||
| next_pointer = recent_items.next_pointer() | ||
| assert next_pointer is None | ||
|
|
||
|
|
||
| def test_get_recent_items_sends_get_with_correct_params(mock_client, mock_box_session, recent_items_response, marker_id): | ||
| limit = 50 | ||
| marker = marker_id | ||
| fields = ['modified_at', 'name'] | ||
| expected_params = { | ||
| 'limit': limit, | ||
| 'marker': marker_id, | ||
| 'fields': ','.join(fields), | ||
| } | ||
| mock_box_session.get.return_value = recent_items_response | ||
| object_collection = mock_client.get_recent_items(limit=limit, marker=marker, fields=fields) | ||
| object_collection.next() | ||
| mock_box_session.get.assert_called_once_with('{0}/recent_items'.format(API.BASE_API_URL), params=expected_params) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize('password', (None, 'p4ssw0rd')) | ||
| def test_get_shared_item_returns_the_correct_item(mock_client, mock_box_session, shared_item_response, password): | ||
| # pylint:disable=redefined-outer-name | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| # coding: utf-8 | ||
|
|
||
| from __future__ import unicode_literals | ||
|
|
||
| from boxsdk.object.recent_item import RecentItem | ||
|
|
||
|
|
||
| def test_init_recent_item(mock_box_session, mock_object_id): | ||
| recent_item = RecentItem( | ||
| session=mock_box_session, | ||
| response_object={ | ||
| "type": "recent_item", | ||
| "item": {"type": "file", "id": mock_object_id} | ||
| }) | ||
| assert recent_item['type'] == 'recent_item' | ||
| assert recent_item.item.object_id == mock_object_id | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you also |
||
| assert recent_item.item.session is mock_box_session | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Won't this break if it is a module fixture? Because the
Mockwill retain its call spec between tests if we do this.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This
user_responseobject was pre-existing, git just reports me as adding it. I added the lines above, with the @pytext.fixture from there. So for the comment on scope below, I followed suit from this line you're commenting on here. Additionally, I believe most of these fixtures are used in a read-only sense, so reuse of them in the tests is inconsequential.