Skip to content

Commit 8d0a165

Browse files
authored
Merge pull request #167 from Jeff-Meadows/folder_metadata
Support folder metadata
2 parents a918ccf + ead8a07 commit 8d0a165

File tree

5 files changed

+44
-34
lines changed

5 files changed

+44
-34
lines changed

AUTHORS.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ used to interact with the Box API. This is a list of contributors.
88
- `@potrebic <https://github.com/potrebic>`_
99
- `@nsundareswaran <https://github.com/nsundareswaran>`_
1010
- `@kelseymorris95 <https://github.com/kelseymorris95>`_
11+
- `@sp4x <https://github.com/sp4x>`_

HISTORY.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ Release History
3636
default ``Translator``.
3737

3838
- Added an ``Event`` class.
39+
- Moved `metadata` method to `Item` so it's now available for `Folder` as well as `File`.
3940

4041
**Other**
4142

boxsdk/object/file.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
from boxsdk.config import API
66
from .item import Item
7-
from .metadata import Metadata
87
from ..util.api_call_decorator import api_call
98

109

@@ -226,26 +225,6 @@ def unlock(self):
226225
data = {'lock': None}
227226
return self.update_info(data)
228227

229-
def metadata(self, scope='global', template='properties'):
230-
"""
231-
Instantiate a :class:`Metadata` object associated with this file.
232-
233-
:param scope:
234-
Scope of the metadata. Must be either 'global' or 'enterprise'.
235-
:type scope:
236-
`unicode`
237-
:param template:
238-
The name of the metadata template.
239-
See https://box-content.readme.io/reference#metadata-object for more details.
240-
:type template:
241-
`unicode`
242-
:return:
243-
A new metadata instance associated with this file.
244-
:rtype:
245-
:class:`Metadata`
246-
"""
247-
return Metadata(self._session, self, scope, template)
248-
249228
@api_call
250229
def get_shared_link_download_url(
251230
self,

boxsdk/object/item.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from .base_object import BaseObject
77
from ..config import API
88
from ..exception import BoxAPIException
9+
from .metadata import Metadata
910
from ..util.api_call_decorator import api_call
1011

1112

@@ -335,3 +336,23 @@ def delete(self, params=None, etag=None):
335336
"""
336337
headers = {'If-Match': etag} if etag is not None else None
337338
return super(Item, self).delete(params, headers)
339+
340+
def metadata(self, scope='global', template='properties'):
341+
"""
342+
Instantiate a :class:`Metadata` object associated with this item.
343+
344+
:param scope:
345+
Scope of the metadata. Must be either 'global' or 'enterprise'.
346+
:type scope:
347+
`unicode`
348+
:param template:
349+
The name of the metadata template.
350+
See https://docs.box.com/reference#metadata-object for more details.
351+
:type template:
352+
`unicode`
353+
:return:
354+
A new metadata instance associated with this item.
355+
:rtype:
356+
:class:`Metadata`
357+
"""
358+
return Metadata(self._session, self, scope, template)

test/unit/object/test_metadata.py

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,31 +26,39 @@ def metadata_scope(request):
2626
return request.param
2727

2828

29-
@pytest.fixture
30-
def metadata_template():
31-
return 'properties'
29+
@pytest.fixture(params=['properties', 'custom'])
30+
def metadata_template(request):
31+
return request.param
32+
33+
34+
@pytest.fixture(params=['file', 'folder'])
35+
def test_object(test_file, test_folder, request):
36+
if request.param == 'file':
37+
return test_file
38+
else:
39+
return test_folder
3240

3341

3442
@pytest.mark.parametrize('success', [True, False])
35-
def test_delete(mock_box_session, make_mock_box_request, test_file, metadata_scope, metadata_template, success):
43+
def test_delete(mock_box_session, make_mock_box_request, test_object, metadata_scope, metadata_template, success):
3644
# pylint:disable=redefined-outer-name
3745
mock_box_session.delete.return_value, _ = make_mock_box_request(response_ok=success)
38-
metadata = test_file.metadata(metadata_scope, metadata_template)
46+
metadata = test_object.metadata(metadata_scope, metadata_template)
3947
assert metadata.delete() is success
4048
mock_box_session.delete.assert_called_once_with(metadata.get_url())
4149

4250

4351
def test_create(
4452
mock_box_session,
4553
make_mock_box_request,
46-
test_file,
54+
test_object,
4755
metadata_scope,
4856
metadata_template,
4957
metadata_response,
5058
):
5159
# pylint:disable=redefined-outer-name
5260
mock_box_session.post.return_value, _ = make_mock_box_request(response=metadata_response)
53-
metadata = test_file.metadata(metadata_scope, metadata_template)
61+
metadata = test_object.metadata(metadata_scope, metadata_template)
5462
response = metadata.create(metadata_response)
5563
assert response is metadata_response
5664
mock_box_session.post.assert_called_once_with(
@@ -63,14 +71,14 @@ def test_create(
6371
def test_get(
6472
mock_box_session,
6573
make_mock_box_request,
66-
test_file,
74+
test_object,
6775
metadata_scope,
6876
metadata_template,
6977
metadata_response,
7078
):
7179
# pylint:disable=redefined-outer-name
7280
mock_box_session.get.return_value, _ = make_mock_box_request(response=metadata_response)
73-
metadata = test_file.metadata(metadata_scope, metadata_template)
81+
metadata = test_object.metadata(metadata_scope, metadata_template)
7482
response = metadata.get()
7583
assert response is metadata_response
7684
mock_box_session.get.assert_called_once_with(metadata.get_url())
@@ -89,15 +97,15 @@ def metadata_update():
8997
def test_update(
9098
mock_box_session,
9199
make_mock_box_request,
92-
test_file,
100+
test_object,
93101
metadata_scope,
94102
metadata_template,
95103
metadata_response,
96104
metadata_update,
97105
):
98106
# pylint:disable=redefined-outer-name
99107
mock_box_session.put.return_value, _ = make_mock_box_request(response=metadata_response)
100-
metadata = test_file.metadata(metadata_scope, metadata_template)
108+
metadata = test_object.metadata(metadata_scope, metadata_template)
101109
response = metadata.update(metadata_update)
102110
assert response is metadata_response
103111
mock_box_session.put.assert_called_once_with(
@@ -107,6 +115,6 @@ def test_update(
107115
)
108116

109117

110-
def test_start_update(test_file):
111-
update = test_file.metadata().start_update()
118+
def test_start_update(test_object):
119+
update = test_object.metadata().start_update()
112120
assert isinstance(update, MetadataUpdate)

0 commit comments

Comments
 (0)