Skip to content

Commit e40e82e

Browse files
authored
Merge pull request #6 from softwareone-platform/bugfix/MPT-9001/extension-fails-when-organization-was-created
MPT-9001 Extension fails when organization was created
2 parents 6c787eb + 7ab4fcb commit e40e82e

File tree

5 files changed

+10
-9
lines changed

5 files changed

+10
-9
lines changed

ffc/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def create_organization(
106106
return response.json()
107107

108108
@wrap_http_error
109-
def get_organization_by_external_id(self, agreement_id):
109+
def get_organizations_by_external_id(self, agreement_id):
110110
headers = self._get_headers()
111111

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

121121
response.raise_for_status()
122122

123-
return response.json()["items"][0]
123+
return response.json()["items"]
124124

125125
def _get_headers(self):
126126
return {

ffc/flows/steps/finops.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@ def __call__(self, client, context, next_step):
4848
order = context.order
4949
agreement_id = order["agreement"]["id"]
5050

51-
organization = ffc_client.get_organization_by_external_id(
51+
organizations = ffc_client.get_organizations_by_external_id(
5252
agreement_id,
5353
)
54+
organization = organizations and organizations[0]
5455
if not organization:
5556
organization = ffc_client.create_organization(
5657
get_ordering_parameter(order, PARAM_ORGANIZATION_NAME)["value"],

tests/ffc/flows/steps/test_finops.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def test_create_organization(
8080
):
8181
mocked_ffc_client = mocker.MagicMock()
8282
mocked_ffc_client.create_organization.return_value = ffc_organization
83-
mocked_ffc_client.get_organization_by_external_id.return_value = []
83+
mocked_ffc_client.get_organizations_by_external_id.return_value = []
8484
mocker.patch(
8585
"ffc.flows.steps.finops.get_ffc_client", return_value=mocked_ffc_client
8686
)
@@ -120,7 +120,7 @@ def test_create_organization_exists(
120120
ffc_organization,
121121
):
122122
mocked_ffc_client = mocker.MagicMock()
123-
mocked_ffc_client.get_organization_by_external_id.return_value = ffc_organization
123+
mocked_ffc_client.get_organizations_by_external_id.return_value = [ffc_organization]
124124
mocker.patch(
125125
"ffc.flows.steps.finops.get_ffc_client", return_value=mocked_ffc_client
126126
)
@@ -133,7 +133,7 @@ def test_create_organization_exists(
133133

134134
assert ctx.organization == ffc_organization
135135
mocked_next_step.assert_called_once()
136-
mocked_ffc_client.get_organization_by_external_id.assert_called_once_with(
136+
mocked_ffc_client.get_organizations_by_external_id.assert_called_once_with(
137137
processing_purchase_order["agreement"]["id"],
138138
)
139139
mocked_ffc_client.create_organization.assert_not_called()

tests/ffc/flows/test_fulfillment.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def test_purchase_order(
3333

3434
mocked_ffc_client = mocker.MagicMock()
3535
mocked_ffc_client.get_employee.return_value = ffc_employee
36-
mocked_ffc_client.get_organization_by_external_id.return_value = ffc_organization
36+
mocked_ffc_client.get_organizations_by_external_id.return_value = [ffc_organization]
3737
mocker.patch(
3838
"ffc.flows.steps.finops.get_ffc_client", return_value=mocked_ffc_client
3939
)

tests/ffc/test_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,6 @@ def test_get_organization(mocker, mock_jwt_encoder, ffc_client_settings):
232232
)
233233

234234
client = get_ffc_client()
235-
organization = client.get_organization_by_external_id(agreement_id)
235+
organizations = client.get_organizations_by_external_id(agreement_id)
236236

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

0 commit comments

Comments
 (0)