Skip to content
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

MHPY-26 Support passing includeDeleted to the records endpoint #19

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion mediahaven/resources/records.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,37 @@ def count(self, query: str) -> int:
)

def get(
self, record_id: str, accept_format=DEFAULT_ACCEPT_FORMAT
self,
record_id: str,
accept_format=DEFAULT_ACCEPT_FORMAT,
include_deleted=False,
**query_params,
) -> MediaHavenSingleObject:
"""Get a single record.

Args:
record_id: It can either be a MediaObjectId, FragmentId or RecordId.
accept_format: The "Accept" request header.
include_deleted: If true, also return the record if it has been
logically deleted.
**query_params: Further optional query parameters:
query_params["fields"]: Select only specific fields. Supports
Exif, dotted keys and Context. If the record has record
structure Data, the information for Exif is obtained from the
original representation. (Can be combined with profiles).
query_params["profiles"]: The profiles for which the fields
should be returned (Can be combined with fields).
query_params["source"]: The source from which the record should
be fetched.

Returns:
A single record.
"""
response = self.mh_client._get(
self._construct_path(record_id),
accept_format,
includeDeleted=str(include_deleted).lower(),
**query_params,
)
return MediaHavenSingleObjectCreator.create_object(response, accept_format)

Expand Down
19 changes: 18 additions & 1 deletion tests/test_records.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,24 @@ def test_get(self, object_creator_mock, records: Records):

# Assert
mh_client_mock._get.assert_called_once_with(
f"{records.name}/{record_id}", AcceptFormat.JSON
f"{records.name}/{record_id}", AcceptFormat.JSON, includeDeleted="false"
)
object_creator_mock.create_object.assert_called_once_with(
mh_client_mock._get(), AcceptFormat.JSON
)

@patch("mediahaven.resources.records.MediaHavenSingleObjectCreator")
def test_get_with_include_deleted(self, object_creator_mock, records: Records):
# Arrange
record_id = "1"
mh_client_mock = records.mh_client

# Act
records.get(record_id, include_deleted=True)

# Assert
mh_client_mock._get.assert_called_once_with(
f"{records.name}/{record_id}", AcceptFormat.JSON, includeDeleted="true"
)
object_creator_mock.create_object.assert_called_once_with(
mh_client_mock._get(), AcceptFormat.JSON
Expand Down