Skip to content

Commit

Permalink
Merge pull request #16 from viaacode/mhpy-22-get-org-ext-id
Browse files Browse the repository at this point in the history
MHPY-22 Add get_by_external_id method
  • Loading branch information
spacid authored Mar 12, 2024
2 parents 6c01d25 + a38717e commit a1fde9c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
18 changes: 18 additions & 0 deletions mediahaven/resources/organisations.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,24 @@ def get(
)
return MediaHavenSingleObjectCreator.create_object(response, accept_format)

def get_by_external_id(
self,
external_id: str,
accept_format=DEFAULT_ACCEPT_FORMAT,
) -> MediaHavenSingleObject:
"""Get a single organisation.
Args:
external_id: The ExternalId of an organisation.
accept_format: The "Accept" request header.
Returns:
A single organisation.
"""
response = self.mh_client._get(
self._construct_path(f"ExternalId:{external_id}"),
accept_format,
)
return MediaHavenSingleObjectCreator.create_object(response, accept_format)

def search(
self, accept_format: str = DEFAULT_ACCEPT_FORMAT, **query_params
) -> MediaHavenPageObject:
Expand Down
17 changes: 17 additions & 0 deletions tests/test_organisations.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,23 @@ def test_get(self, object_creator_mock, organisations: Organisations):
mh_client_mock._get(), AcceptFormat.JSON
)

@patch("mediahaven.resources.organisations.MediaHavenSingleObjectCreator")
def test_get_by_external_id(self, object_creator_mock, organisations: Organisations):
# Arrange
external_id = "OR-a11111a"
mh_client_mock = organisations.mh_client

# Act
organisations.get_by_external_id(external_id)

# Assert
mh_client_mock._get.assert_called_once_with(
f"{organisations.name}/ExternalId:{external_id}", AcceptFormat.JSON
)
object_creator_mock.create_object.assert_called_once_with(
mh_client_mock._get(), AcceptFormat.JSON
)

@patch("mediahaven.resources.organisations.MediaHavenPageObjectCreator")
def test_search(self, object_creator_mock, organisations: Organisations):
# Arrange
Expand Down

0 comments on commit a1fde9c

Please sign in to comment.