Skip to content

Commit

Permalink
files-schema: hide uri from serialization
Browse files Browse the repository at this point in the history
Co-Authored-By: Yash Lamba <[email protected]>
  • Loading branch information
slint and Yash Lamba committed May 6, 2024
1 parent 79d05a1 commit 124809e
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 10 deletions.
2 changes: 0 additions & 2 deletions invenio_records_resources/records/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
from invenio_records.systemfields import DictField, SystemField, SystemFieldsMixin
from invenio_records.systemfields.model import ModelField

# TODO move to systemfields folder


class Record(RecordBase, SystemFieldsMixin):
"""Base class for record APIs.
Expand Down
2 changes: 1 addition & 1 deletion invenio_records_resources/services/files/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class Meta:

key = Str(required=True)
storage_class = Str()
uri = Str()
uri = Str(load_only=True)
checksum = Str()
size = Integer()

Expand Down
2 changes: 1 addition & 1 deletion invenio_records_resources/services/files/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def fetch_file(service_id, record_id, file_key):
try:
service = current_service_registry.get(service_id)
file_record = service.read_file_metadata(system_identity, record_id, file_key)
source_url = file_record.data["uri"]
source_url = file_record._file.file.uri
# download file
# verify=True for self signed certificates by default
with requests.get(source_url, stream=True, allow_redirects=True) as response:
Expand Down
7 changes: 1 addition & 6 deletions tests/services/files/test_file_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ def test_file_flow(file_service, location, example_file_record, identity_simple,
result = file_service.read_file_metadata(identity_simple, recid, "article.txt")
assert result.to_dict()["key"] == file_to_initialise[0]["key"]
assert result.to_dict()["storage_class"] == "L"
assert "uri" not in result.to_dict()

# Retrieve file
result = file_service.get_file_content(identity_simple, recid, "article.txt")
Expand Down Expand Up @@ -293,7 +292,6 @@ def test_content_and_commit_external_file(
result = result.to_dict()
assert result["key"] == file_to_initialise[0]["key"]
assert result["storage_class"] == "F"
assert "uri" in result

# Set content as user
content = BytesIO(b"test file content")
Expand All @@ -317,7 +315,7 @@ def test_content_and_commit_external_file(
result = result.to_dict()
assert result["key"] == file_to_initialise[0]["key"]
assert result["storage_class"] == "F" # not commited yet
assert "uri" in result
assert "uri" not in result

# Commit as user
with pytest.raises(PermissionDeniedError):
Expand Down Expand Up @@ -369,7 +367,6 @@ def test_delete_not_committed_external_file(
result = result.to_dict()
assert result["key"] == file_to_initialise[0]["key"]
assert result["storage_class"] == "F"
assert "uri" in result

# Delete file
file_service.delete_file(identity_simple, recid, "article.txt")
Expand Down Expand Up @@ -440,7 +437,6 @@ def test_read_not_committed_external_file(
result = result.to_dict()
assert result["key"] == file_to_initialise[0]["key"]
assert result["storage_class"] == "F"
assert "uri" in result

# List files
result = file_service.list_files(identity_simple, recid)
Expand All @@ -451,7 +447,6 @@ def test_read_not_committed_external_file(
result = result.to_dict()
assert result["key"] == file_to_initialise[0]["key"]
assert result["storage_class"] == "F" # changed after commit
assert "uri" in result

# Retrieve file
with pytest.raises(PermissionDeniedError):
Expand Down

0 comments on commit 124809e

Please sign in to comment.