Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 4 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,25 +176,25 @@ def construct_fragment_update_sidecar(pid):


def get_cp_name(or_id: str, ctx: Context) -> str:
"""Retrieves the CP MAM Name for a given OR ID.
"""Retrieves the CP Name for a given OR ID.

The mapping between the OR ID and the CP MAM Name is cached.
The mapping between the OR ID and the CP Name is cached.
If the mapping is not found, The organisations API will be queried to retrieve
that information. That information will be cached in a dictionary.

Arguments:
or_id {str} -- The OR ID
ctx {Context} -- The context
Returns:
str -- The CP MAM Name
str -- The CP Name
"""
if or_id in cp_names:
cp_name = cp_names[or_id]
else:
try:
org_service = OrganisationsService(ctx)
try:
cp_name = org_service.get_mam_label(or_id)
cp_name = org_service.get_org_label(or_id)
except OrgApiError as e:
raise NackException(str(e))
else:
Expand Down
10 changes: 5 additions & 5 deletions meemoo/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,20 +104,20 @@ def __init__(self, ctx):
super().__init__(ctx)

def _construct_query(self, or_id: str):
"""Construct the Graphql query to retrieve the CP name defined in the MAM
"""Construct the Graphql query to retrieve the CP name
Args:
or_id: The cp-id for which to retrieve the CP name.
Returns:
The graphql query.
"""
query = f"""{{
organizations(id:"{or_id}") {{
mam_label
label
}}
}}"""
return query

def get_mam_label(self, or_id):
def get_org_label(self, or_id):
# Make sure the OR is uppercase. Organisation api needs it.
or_id = or_id[:2].upper() + or_id[2:]

Expand All @@ -128,10 +128,10 @@ def get_mam_label(self, or_id):
json=data_payload,
)
try:
mam_label = response.json()["data"]["organizations"][0]["mam_label"]
org_label = response.json()["data"]["organizations"][0]["label"]
except (KeyError, IndexError) as e:
raise OrgApiError(f"Could not fetch the mam label for OR ID '{or_id}': {e}")
return mam_label
return org_label

class MediahavenService(Service):
""" Abstraction for the mediahaven-api. """
Expand Down
4 changes: 2 additions & 2 deletions tests/mocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ def mock_put(self, content_bytes, destination_path, destination_filename):

@pytest.fixture
def mock_organisations_api(monkeypatch):
def mock_get_mam_label(self, or_id):
def mock_get_org_label(self, or_id):
print(f"getting name for {or_id}")
if or_id == "or_id_none":
return None
return "UNITTEST"

from meemoo.services import OrganisationsService

monkeypatch.setattr(OrganisationsService, "get_mam_label", mock_get_mam_label)
monkeypatch.setattr(OrganisationsService, "get_org_label", mock_get_org_label)


@pytest.fixture
Expand Down