Skip to content

Commit 7a1f883

Browse files
authored
Merge pull request #24 from softwareone-platform/MPT-10788_fix_ff_params_for_billing
MPT-10788 set billedPercentage param as text
2 parents 4d3b7a6 + b81c1fd commit 7a1f883

File tree

9 files changed

+28
-59
lines changed

9 files changed

+28
-59
lines changed

.env.sample

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ MPT_PORTAL_BASE_URL=http://devmock:8000
44
MPT_API_BASE_URL=http://devmock:8000
55
MPT_API_TOKEN=<vendor-api-token>
66
MPT_ORDERS_API_POLLING_INTERVAL_SECS=120
7+
MPT_NOTIFY_CATEGORIES={"ORDERS": "NTC-0000-0006"}
78
EXT_WEBHOOKS_SECRETS={"PRD-1111-1111": "<super-jwt-secret>"}
89
EXT_MSTEAMS_WEBHOOK_URL=https://whatever.webhook.office.com/webhookb2/<...>
910
EXT_FFC_SUB=FTKN-1111-1111
1011
EXT_FFC_OPERATIONS_API_BASE_URL=https://api.finops.s1.show/ops
1112
EXT_FFC_OPERATIONS_SECRET=supersecret
12-
MPT_NOTIFY_CATEGORIES={"ORDERS": "NTC-0000-0006"}
13-
DEFAULT_TRIAL_PERIOD_DURATION_DAYS=30
14-
DEFAULT_BILLED_PERCENTAGE=4
13+
EXT_DEFAULT_TRIAL_PERIOD_DURATION_DAYS=30
14+
EXT_DEFAULT_BILLED_PERCENTAGE=4

ffc/flows/steps/finops.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ def __call__(self, client, context, next_step):
3131
try:
3232
employee = ffc_client.get_employee(administrator["email"])
3333
context.order = set_is_new_user(context.order, True)
34-
update_order(
35-
client, context.order["id"], parameters=context.order["parameters"]
36-
)
34+
update_order(client, context.order["id"], parameters=context.order["parameters"])
3735
logger.info(f"{context}: employee exists {employee['id']}")
3836
except FinOpsNotFoundError:
3937
employee = ffc_client.create_employee(
@@ -88,9 +86,7 @@ def __call__(self, client, context, next_step):
8886
order = context.order
8987
agreement_id = order["agreement"]["id"]
9088

91-
organizations = ffc_client.get_organizations_by_external_id(
92-
agreement_id=agreement_id
93-
)
89+
organizations = ffc_client.get_organizations_by_external_id(agreement_id=agreement_id)
9490
organization = organizations and organizations[0]
9591

9692
if organization and organization["status"] != DELETED_ORGANIZATION:

ffc/flows/steps/order.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,7 @@ def __call__(self, client, context, next_step):
133133
]:
134134
parameter = get_ordering_parameter(order, param_name)
135135
if not parameter.get("value"):
136-
order = set_ordering_parameter_error(
137-
order, param_name, errors[param_name]
138-
)
136+
order = set_ordering_parameter_error(order, param_name, errors[param_name])
139137
context.validation_succeeded = False
140138

141139
next_step(client, context)
@@ -198,8 +196,8 @@ def _get_parameter_updates(order):
198196
updates = {}
199197

200198
if not get_fulfillment_parameter(order, PARAM_BILLED_PERCENTAGE).get("value"):
201-
updates[PARAM_BILLED_PERCENTAGE] = int(
202-
settings.EXTENSION_CONFIG.get("DEFAULT_BILLED_PERCENTAGE")
199+
updates[PARAM_BILLED_PERCENTAGE] = settings.EXTENSION_CONFIG.get(
200+
"DEFAULT_BILLED_PERCENTAGE", "4"
203201
)
204202

205203
trial_start_date = get_fulfillment_parameter(order, PARAM_TRIAL_START_DATE).get("value")
@@ -209,7 +207,7 @@ def _get_parameter_updates(order):
209207

210208
if not get_fulfillment_parameter(order, PARAM_TRIAL_END_DATE).get("value"):
211209
trail_end_date = datetime.strptime(trial_start_date, "%Y-%m-%d").date() + timedelta(
212-
days=int(settings.EXTENSION_CONFIG.get("DEFAULT_TRIAL_PERIOD_DURATION_DAYS"))
210+
days=int(settings.EXTENSION_CONFIG.get("DEFAULT_TRIAL_PERIOD_DURATION_DAYS", "30"))
213211
)
214212
updates[PARAM_TRIAL_END_DATE] = trail_end_date.strftime("%Y-%m-%d")
215213

@@ -247,12 +245,9 @@ def __call__(self, client, context, next_step):
247245
current_template_id = context.order.get("template", {}).get("id")
248246
if template["id"] != current_template_id:
249247
context.order = set_template(context.order, template)
250-
update_order(
251-
client, context.order["id"], template=context.order["template"]
252-
)
248+
update_order(client, context.order["id"], template=context.order["template"])
253249
logger.info(
254-
f"{context}: processing template set to {self.template_name} "
255-
f"({template['id']})"
250+
f"{context}: processing template set to {self.template_name} " f"({template['id']})"
256251
)
257252
logger.info(f"{context}: processing template is ok, continue")
258253

ffc/flows/steps/subscription.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ def __call__(self, client, context, next_step):
3333
subscription,
3434
)
3535
logger.info(
36-
f'{context}: subscription {line["id"]} '
37-
f'({subscription["id"]}) created'
36+
f'{context}: subscription {line["id"]} ' f'({subscription["id"]}) created'
3837
)
3938
next_step(client, context)

tests/ffc/flows/steps/test_finops.py

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@ def test_create_employee_exists(
2424
):
2525
mocked_ffc_client = mocker.MagicMock()
2626
mocked_ffc_client.get_employee.return_value = ffc_employee
27-
mocker.patch(
28-
"ffc.flows.steps.finops.get_ffc_client", return_value=mocked_ffc_client
29-
)
27+
mocker.patch("ffc.flows.steps.finops.get_ffc_client", return_value=mocked_ffc_client)
3028
mocked_update_order = mocker.patch("ffc.flows.steps.finops.update_order")
3129

3230
ctx = OrderContext(order=processing_purchase_order)
@@ -57,9 +55,7 @@ def test_create_employee(
5755
mocked_ffc_client = mocker.MagicMock()
5856
mocked_ffc_client.get_employee.side_effect = FinOpsNotFoundError("not-found")
5957
mocked_ffc_client.create_employee.return_value = ffc_employee
60-
mocker.patch(
61-
"ffc.flows.steps.finops.get_ffc_client", return_value=mocked_ffc_client
62-
)
58+
mocker.patch("ffc.flows.steps.finops.get_ffc_client", return_value=mocked_ffc_client)
6359
mocked_update_order = mocker.patch("ffc.flows.steps.finops.update_order")
6460

6561
ctx = OrderContext(order=processing_purchase_order)
@@ -94,9 +90,7 @@ def test_create_organization(
9490
mocked_ffc_client = mocker.MagicMock()
9591
mocked_ffc_client.create_organization.return_value = ffc_organization
9692
mocked_ffc_client.get_organizations_by_external_id.return_value = []
97-
mocker.patch(
98-
"ffc.flows.steps.finops.get_ffc_client", return_value=mocked_ffc_client
99-
)
93+
mocker.patch("ffc.flows.steps.finops.get_ffc_client", return_value=mocked_ffc_client)
10094

10195
ctx = OrderContext(order=processing_purchase_order)
10296
ctx.employee = ffc_employee
@@ -134,9 +128,7 @@ def test_create_organization_exists(
134128
):
135129
mocked_ffc_client = mocker.MagicMock()
136130
mocked_ffc_client.get_organizations_by_external_id.return_value = [ffc_organization]
137-
mocker.patch(
138-
"ffc.flows.steps.finops.get_ffc_client", return_value=mocked_ffc_client
139-
)
131+
mocker.patch("ffc.flows.steps.finops.get_ffc_client", return_value=mocked_ffc_client)
140132

141133
ctx = OrderContext(order=processing_purchase_order)
142134
ctx.employee = ffc_employee
@@ -162,9 +154,7 @@ def test_delete_organization(
162154
mocked_ffc_client = mocker.MagicMock()
163155
mocked_ffc_client.delete_organization.return_value = None
164156
mocked_ffc_client.get_organizations_by_external_id.return_value = [ffc_organization]
165-
mocker.patch(
166-
"ffc.flows.steps.finops.get_ffc_client", return_value=mocked_ffc_client
167-
)
157+
mocker.patch("ffc.flows.steps.finops.get_ffc_client", return_value=mocked_ffc_client)
168158

169159
ctx = OrderContext(order=processing_termination_order)
170160
step = DeleteOrganization()
@@ -175,9 +165,7 @@ def test_delete_organization(
175165
mocked_ffc_client.get_organizations_by_external_id.assert_called_once_with(
176166
agreement_id=processing_termination_order["agreement"]["id"],
177167
)
178-
mocked_ffc_client.delete_organization.assert_called_once_with(
179-
ffc_organization["id"]
180-
)
168+
mocked_ffc_client.delete_organization.assert_called_once_with(ffc_organization["id"])
181169

182170

183171
def test_delete_organization_deleted_or_not_found(
@@ -190,9 +178,7 @@ def test_delete_organization_deleted_or_not_found(
190178
ffc_organization["status"] = "deleted"
191179
mocked_ffc_client = mocker.MagicMock()
192180
mocked_ffc_client.get_organizations_by_external_id.return_value = [ffc_organization]
193-
mocker.patch(
194-
"ffc.flows.steps.finops.get_ffc_client", return_value=mocked_ffc_client
195-
)
181+
mocker.patch("ffc.flows.steps.finops.get_ffc_client", return_value=mocked_ffc_client)
196182

197183
ctx = OrderContext(order=processing_termination_order)
198184
step = DeleteOrganization()
@@ -207,9 +193,7 @@ def test_delete_organization_deleted_or_not_found(
207193
mocked_ffc_client.delete_organization.assert_not_called()
208194

209195
mocked_ffc_client.get_organizations_by_external_id.return_value = []
210-
mocker.patch(
211-
"ffc.flows.steps.finops.get_ffc_client", return_value=mocked_ffc_client
212-
)
196+
mocker.patch("ffc.flows.steps.finops.get_ffc_client", return_value=mocked_ffc_client)
213197

214198
step(mpt_client, ctx, mocked_next_step)
215199

tests/ffc/flows/steps/test_order.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -344,9 +344,9 @@ def test_setup_fulfillment_parameters_empty_values(
344344
processing_purchase_order,
345345
):
346346
param_defaults = {
347-
'trialStartDate': '2025-01-01',
348-
'trialEndDate': '2025-01-31',
349-
'billedPercentage': 4,
347+
"trialStartDate": "2025-01-01",
348+
"trialEndDate": "2025-01-31",
349+
"billedPercentage": "4",
350350
}
351351
for param in processing_purchase_order["parameters"]["fulfillment"]:
352352
if param["externalId"] in param_defaults:

tests/ffc/test_parameters.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,7 @@ def test_get_parameter(processing_purchase_order):
3131

3232

3333
def test_get_parameter_does_not_exist(processing_purchase_order):
34-
assert (
35-
get_parameter("fulfillment", processing_purchase_order, "unknownParameter")
36-
== {}
37-
)
34+
assert get_parameter("fulfillment", processing_purchase_order, "unknownParameter") == {}
3835

3936

4037
def test_set_ordering_parameter_error(processing_purchase_order):

tests/test_apps.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,4 @@ def test_webhook_secret_not_defined(settings):
3838
with pytest.raises(ImproperlyConfigured) as e:
3939
app.ready()
4040

41-
assert "Please, specify it in EXT_WEBHOOKS_SECRETS environment variable." in str(
42-
e.value
43-
)
41+
assert "Please, specify it in EXT_WEBHOOKS_SECRETS environment variable." in str(e.value)

tests/test_extension.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ def test_jwt_secret_callback(mocker, settings, mpt_client, webhook):
3232
"ffc.extension.get_webhook",
3333
return_value=webhook,
3434
)
35-
assert jwt_secret_callback(
36-
mpt_client, {"webhook_id": "WH-123-123"}
37-
) == get_for_product(settings, "WEBHOOKS_SECRETS", "PRD-1111-1111")
35+
assert jwt_secret_callback(mpt_client, {"webhook_id": "WH-123-123"}) == get_for_product(
36+
settings, "WEBHOOKS_SECRETS", "PRD-1111-1111"
37+
)
3838
mocked_webhook.assert_called_once_with(mpt_client, "WH-123-123")
3939

4040

0 commit comments

Comments
 (0)