Skip to content
Merged
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
4 changes: 2 additions & 2 deletions ffc/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def create_organization(
return response.json()

@wrap_http_error
def get_organization_by_external_id(self, agreement_id):
def get_organizations_by_external_id(self, agreement_id):
headers = self._get_headers()

rql_filter = f"eq(operations_external_id,{agreement_id})"
Expand All @@ -120,7 +120,7 @@ def get_organization_by_external_id(self, agreement_id):

response.raise_for_status()

return response.json()["items"][0]
return response.json()["items"]

def _get_headers(self):
return {
Expand Down
3 changes: 2 additions & 1 deletion ffc/flows/steps/finops.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ def __call__(self, client, context, next_step):
order = context.order
agreement_id = order["agreement"]["id"]

organization = ffc_client.get_organization_by_external_id(
organizations = ffc_client.get_organizations_by_external_id(
agreement_id,
)
organization = organizations and organizations[0]
if not organization:
organization = ffc_client.create_organization(
get_ordering_parameter(order, PARAM_ORGANIZATION_NAME)["value"],
Expand Down
6 changes: 3 additions & 3 deletions tests/ffc/flows/steps/test_finops.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def test_create_organization(
):
mocked_ffc_client = mocker.MagicMock()
mocked_ffc_client.create_organization.return_value = ffc_organization
mocked_ffc_client.get_organization_by_external_id.return_value = []
mocked_ffc_client.get_organizations_by_external_id.return_value = []
mocker.patch(
"ffc.flows.steps.finops.get_ffc_client", return_value=mocked_ffc_client
)
Expand Down Expand Up @@ -120,7 +120,7 @@ def test_create_organization_exists(
ffc_organization,
):
mocked_ffc_client = mocker.MagicMock()
mocked_ffc_client.get_organization_by_external_id.return_value = ffc_organization
mocked_ffc_client.get_organizations_by_external_id.return_value = [ffc_organization]
mocker.patch(
"ffc.flows.steps.finops.get_ffc_client", return_value=mocked_ffc_client
)
Expand All @@ -133,7 +133,7 @@ def test_create_organization_exists(

assert ctx.organization == ffc_organization
mocked_next_step.assert_called_once()
mocked_ffc_client.get_organization_by_external_id.assert_called_once_with(
mocked_ffc_client.get_organizations_by_external_id.assert_called_once_with(
processing_purchase_order["agreement"]["id"],
)
mocked_ffc_client.create_organization.assert_not_called()
2 changes: 1 addition & 1 deletion tests/ffc/flows/test_fulfillment.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def test_purchase_order(

mocked_ffc_client = mocker.MagicMock()
mocked_ffc_client.get_employee.return_value = ffc_employee
mocked_ffc_client.get_organization_by_external_id.return_value = ffc_organization
mocked_ffc_client.get_organizations_by_external_id.return_value = [ffc_organization]
mocker.patch(
"ffc.flows.steps.finops.get_ffc_client", return_value=mocked_ffc_client
)
Expand Down
4 changes: 2 additions & 2 deletions tests/ffc/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,6 @@ def test_get_organization(mocker, mock_jwt_encoder, ffc_client_settings):
)

client = get_ffc_client()
organization = client.get_organization_by_external_id(agreement_id)
organizations = client.get_organizations_by_external_id(agreement_id)

assert organization == {"id": "test-organization"}
assert organizations == [{"id": "test-organization"}]
Loading