Skip to content

Commit

Permalink
api: add 'file_id' into 'dumps()' method
Browse files Browse the repository at this point in the history
* Closes #68

Signed-off-by: Jan Okraska <jan.okraska@cern.ch>
  • Loading branch information
okraskaj authored and ntarocco committed May 22, 2019
1 parent 6bf5302 commit 989753b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions invenio_records_files/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@
... print(k)
bucket
checksum
file_id
filetype
key
size
Expand Down
1 change: 1 addition & 0 deletions invenio_records_files/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ def dumps(self):
'key': self.obj.key, # IMPORTANT it must stay here!
'size': self.obj.file.size,
'version_id': str(self.obj.version_id),
'file_id': str(self.obj.file.id)
})
return self.data

Expand Down
12 changes: 12 additions & 0 deletions tests/test_invenio_records_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,18 @@ def test_files_extra_data(app, db, location, record_with_bucket):
assert record.files['hello.txt'].get(k)


def test_files_extra_data_in_dump(app, db, location, record_with_bucket):
"""Test if all neccessary properties are included in dumps() method."""
record = record_with_bucket

# Create a file.
record.files['hello.txt'] = BytesIO(b'Hello world!')
record['_files'] = record.files.dumps()

for k in ['bucket', 'checksum', 'key', 'size', 'version_id', 'file_id']:
assert k in record['_files'][0]


def test_files_protection(app, db, location, record_with_bucket):
"""Test record files property protection."""
record = record_with_bucket
Expand Down

0 comments on commit 989753b

Please sign in to comment.