Skip to content

Commit af8cb9f

Browse files
committed
MPT-19058 Adopt notification templates in AWS Extension
1 parent 7efb758 commit af8cb9f

File tree

12 files changed

+48
-81
lines changed

12 files changed

+48
-81
lines changed

swo_aws_extension/flows/order_utils.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,7 @@ def set_order_template(
6767
return context.order
6868

6969

70-
def switch_order_status_to_query_and_notify(
71-
client: MPTClient, context: InitialAWSContext, template_name: str
72-
):
70+
def switch_order_status_to_query(client: MPTClient, context: InitialAWSContext, template_name: str):
7371
"""Switch the order status to 'Querying' if it is not already in that status."""
7472
context.order = set_order_template(client, context, MPT_ORDER_STATUS_QUERYING, template_name)
7573
kwargs = {
@@ -84,12 +82,9 @@ def switch_order_status_to_query_and_notify(
8482
context.order_id,
8583
**kwargs,
8684
)
87-
MPTNotificationManager(client).send_notification(context)
8885

8986

90-
def switch_order_status_to_failed_and_notify(
91-
client: MPTClient, context: InitialAWSContext, error: dict
92-
):
87+
def switch_order_status_to_failed(client: MPTClient, context: InitialAWSContext, error: dict):
9388
"""Switch the order status to 'Failed'."""
9489
kwargs = {
9590
"parameters": context.order["parameters"],
@@ -101,10 +96,9 @@ def switch_order_status_to_failed_and_notify(
10196
error,
10297
**kwargs,
10398
)
104-
MPTNotificationManager(client).send_notification(context)
10599

106100

107-
def switch_order_status_to_process_and_notify(
101+
def switch_order_status_to_process(
108102
client: MPTClient, context: InitialAWSContext, template_name: str
109103
):
110104
"""Switch the order status to 'Processing'."""
@@ -126,10 +120,9 @@ def switch_order_status_to_process_and_notify(
126120
error,
127121
)
128122
return
129-
MPTNotificationManager(client).send_notification(context)
130123

131124

132-
def switch_order_status_to_complete_and_notify(
125+
def switch_order_status_to_complete(
133126
client: MPTClient, context: InitialAWSContext, template_name: str
134127
):
135128
"""Updates the order status to completed."""
@@ -144,7 +137,6 @@ def switch_order_status_to_complete_and_notify(
144137
}
145138

146139
context.order = complete_order(client, context.order_id, **kwargs)
147-
MPTNotificationManager(client).send_notification(context)
148140
logger.info("%s - Action - Set order to completed", context.order_id)
149141

150142

swo_aws_extension/flows/steps/base.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
InitialAWSContext,
1212
)
1313
from swo_aws_extension.flows.order_utils import (
14-
switch_order_status_to_failed_and_notify,
15-
switch_order_status_to_query_and_notify,
14+
switch_order_status_to_failed,
15+
switch_order_status_to_query,
1616
)
1717
from swo_aws_extension.flows.steps.errors import (
1818
AlreadyProcessedStepError,
@@ -99,7 +99,7 @@ def _run_process(self, context: InitialAWSContext) -> bool:
9999
return False
100100
except QueryStepError as error:
101101
logger.info("%s - Query Order: %s", context.order_id, error.message)
102-
switch_order_status_to_query_and_notify(self._client, context, error.template_id)
102+
switch_order_status_to_query(self._client, context, error.template_id)
103103
return False
104104
except FailStepError as error:
105105
logger.info("%s - Fail Order: %s", context.order_id, error)
@@ -108,6 +108,6 @@ def _run_process(self, context: InitialAWSContext) -> bool:
108108
"id": error.id,
109109
"message": error.message,
110110
}
111-
switch_order_status_to_failed_and_notify(self._client, context, fail_error)
111+
switch_order_status_to_failed(self._client, context, fail_error)
112112
return False
113113
return True

swo_aws_extension/flows/steps/complete_order.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from swo_aws_extension.config import Config
88
from swo_aws_extension.constants import ChannelHandshakeDeployed, OrderCompletedTemplate, PhasesEnum
99
from swo_aws_extension.flows.order import InitialAWSContext
10-
from swo_aws_extension.flows.order_utils import switch_order_status_to_complete_and_notify
10+
from swo_aws_extension.flows.order_utils import switch_order_status_to_complete
1111
from swo_aws_extension.flows.steps.base import BasePhaseStep
1212
from swo_aws_extension.flows.steps.errors import SkipStepError
1313
from swo_aws_extension.parameters import (
@@ -49,7 +49,7 @@ def process(self, client: MPTClient, context: InitialAWSContext) -> None:
4949
context.order_id,
5050
mpa_id,
5151
)
52-
switch_order_status_to_complete_and_notify(client, context, template_name)
52+
switch_order_status_to_complete(client, context, template_name)
5353

5454
@override
5555
def post_step(self, client: MPTClient, context: InitialAWSContext) -> None:
@@ -72,7 +72,7 @@ def process(self, client: MPTClient, context: InitialAWSContext) -> None:
7272
template = OrderCompletedTemplate.TERMINATION
7373
else:
7474
template = OrderCompletedTemplate.TERMINATION_WITHOUT_HANDSHAKE
75-
switch_order_status_to_complete_and_notify(client, context, template)
75+
switch_order_status_to_complete(client, context, template)
7676

7777
@override
7878
def post_step(self, client: MPTClient, context: InitialAWSContext) -> None:

swo_aws_extension/processors/querying/aws_billing_transfer_invitation.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
ResponsibilityTransferStatus,
1111
)
1212
from swo_aws_extension.flows.order import PurchaseContext
13-
from swo_aws_extension.flows.order_utils import switch_order_status_to_process_and_notify
13+
from swo_aws_extension.flows.order_utils import switch_order_status_to_process
1414
from swo_aws_extension.parameters import get_responsibility_transfer_id
1515
from swo_aws_extension.processors.processor import Processor
1616
from swo_aws_extension.processors.querying.helper import get_template_name
@@ -80,9 +80,7 @@ def process_invitation(self, context: PurchaseContext, transfer_id: str):
8080
transfer_id,
8181
status,
8282
)
83-
switch_order_status_to_process_and_notify(
84-
self.client, context, get_template_name(context)
85-
)
83+
switch_order_status_to_process(self.client, context, get_template_name(context))
8684
return
8785

8886
logger.info(

swo_aws_extension/processors/querying/aws_channel_handshake.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
PhasesEnum,
1212
)
1313
from swo_aws_extension.flows.order import PurchaseContext
14-
from swo_aws_extension.flows.order_utils import switch_order_status_to_process_and_notify
14+
from swo_aws_extension.flows.order_utils import switch_order_status_to_process
1515
from swo_aws_extension.parameters import (
1616
get_channel_handshake_id,
1717
get_relationship_id,
@@ -52,7 +52,7 @@ def process(self, context: PurchaseContext) -> None:
5252
context.order_id,
5353
handshake_id,
5454
)
55-
switch_order_status_to_process_and_notify(
55+
switch_order_status_to_process(
5656
self.client, context, OrderProcessingTemplateEnum.EXISTING_ACCOUNT
5757
)
5858
return
@@ -64,9 +64,7 @@ def process(self, context: PurchaseContext) -> None:
6464
handshake_id,
6565
handshake.get("status"),
6666
)
67-
switch_order_status_to_process_and_notify(
68-
self.client, context, get_template_name(context)
69-
)
67+
switch_order_status_to_process(self.client, context, get_template_name(context))
7068
return
7169

7270
if is_querying_timeout(context, self._config.querying_timeout_days):
@@ -103,4 +101,4 @@ def _manage_querying_timeout(
103101
context.order = update_order(
104102
self.client, context.order_id, parameters=context.order["parameters"]
105103
)
106-
switch_order_status_to_process_and_notify(self.client, context, get_template_name(context))
104+
switch_order_status_to_process(self.client, context, get_template_name(context))

swo_aws_extension/processors/querying/aws_customer_roles.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
PhasesEnum,
99
)
1010
from swo_aws_extension.flows.order import PurchaseContext
11-
from swo_aws_extension.flows.order_utils import switch_order_status_to_process_and_notify
11+
from swo_aws_extension.flows.order_utils import switch_order_status_to_process
1212
from swo_aws_extension.flows.steps.crm_tickets.templates.deploy_roles import DEPLOY_ROLES_TEMPLATE
1313
from swo_aws_extension.flows.steps.crm_tickets.ticket_manager import TicketManager
1414
from swo_aws_extension.parameters import (
@@ -56,9 +56,7 @@ def process(self, context: PurchaseContext) -> None:
5656
logger.info(
5757
"%s - Customer roles are deployed. Updating order to processing.", context.order_id
5858
)
59-
switch_order_status_to_process_and_notify(
60-
self.client, context, get_template_name(context)
61-
)
59+
switch_order_status_to_process(self.client, context, get_template_name(context))
6260
return
6361

6462
if is_querying_timeout(context, self._config.customer_roles_querying_timeout_days):
@@ -85,7 +83,7 @@ def _manage_querying_timeout(self, context: PurchaseContext):
8583
self.client, context.order_id, parameters=context.order["parameters"]
8684
)
8785

88-
switch_order_status_to_process_and_notify(self.client, context, get_template_name(context))
86+
switch_order_status_to_process(self.client, context, get_template_name(context))
8987

9088
def _manage_customer_roles_ticket_timeout(self, context: PurchaseContext) -> None:
9189
"""Manage customer roles ticket timeout."""

tests/flows/steps/test_base_phase_step.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def test_query_step_error(mocker, initial_context):
106106
error = QueryStepError("msg", "template-id")
107107
step.proc_exc = error
108108
switch_mock = mocker.patch(
109-
"swo_aws_extension.flows.steps.base.switch_order_status_to_query_and_notify",
109+
"swo_aws_extension.flows.steps.base.switch_order_status_to_query",
110110
)
111111

112112
client, next_step = _run_step(mocker, step, initial_context) # act
@@ -120,7 +120,7 @@ def test_fail_step_error(mocker, initial_context):
120120
error = FailStepError("Error_id", "Error")
121121
step.proc_exc = error
122122
switch_mock = mocker.patch(
123-
"swo_aws_extension.flows.steps.base.switch_order_status_to_failed_and_notify",
123+
"swo_aws_extension.flows.steps.base.switch_order_status_to_failed",
124124
)
125125

126126
client, next_step = _run_step(mocker, step, initial_context) # act

tests/flows/steps/test_complete_order.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def test_complete_order_process_completed(
5555
):
5656
order = order_factory()
5757
mock_switch = mocker.patch(
58-
"swo_aws_extension.flows.steps.complete_order.switch_order_status_to_complete_and_notify"
58+
"swo_aws_extension.flows.steps.complete_order.switch_order_status_to_complete"
5959
)
6060
mocker.patch("swo_aws_extension.flows.steps.complete_order.update_agreement")
6161
context = initial_context(order)
@@ -99,7 +99,7 @@ def test_termination_process(
9999
),
100100
)
101101
mock_switch = mocker.patch(
102-
"swo_aws_extension.flows.steps.complete_order.switch_order_status_to_complete_and_notify"
102+
"swo_aws_extension.flows.steps.complete_order.switch_order_status_to_complete"
103103
)
104104
context = initial_context(order)
105105
step = CompleteTerminationOrder(config)
@@ -118,7 +118,7 @@ def test_termination_process_without_handshake(
118118
),
119119
)
120120
mock_switch = mocker.patch(
121-
"swo_aws_extension.flows.steps.complete_order.switch_order_status_to_complete_and_notify"
121+
"swo_aws_extension.flows.steps.complete_order.switch_order_status_to_complete"
122122
)
123123
context = initial_context(order)
124124
step = CompleteTerminationOrder(config)

tests/flows/test_order_utils.py

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
from swo_aws_extension.flows.order import PurchaseContext
66
from swo_aws_extension.flows.order_utils import (
77
set_order_template,
8-
switch_order_status_to_complete_and_notify,
9-
switch_order_status_to_failed_and_notify,
10-
switch_order_status_to_process_and_notify,
11-
switch_order_status_to_query_and_notify,
8+
switch_order_status_to_complete,
9+
switch_order_status_to_failed,
10+
switch_order_status_to_process,
11+
switch_order_status_to_query,
1212
update_processing_template_and_notify,
1313
)
1414

@@ -50,19 +50,15 @@ def test_switch_order_to_query_and_notify(
5050
"swo_aws_extension.flows.order_utils.query_order",
5151
return_value=order,
5252
)
53-
notification_mock = mocker.patch(
54-
"swo_aws_extension.flows.order_utils.MPTNotificationManager",
55-
)
5653

57-
switch_order_status_to_query_and_notify(client, context, "TemplateName") # act
54+
switch_order_status_to_query(client, context, "TemplateName") # act
5855

5956
query_order_mock.assert_called_with(
6057
client,
6158
context.order_id,
6259
parameters=context.order["parameters"],
6360
template=new_template,
6461
)
65-
notification_mock.assert_called_once()
6662

6763

6864
def test_switch_order_to_query_and_notify_error(
@@ -86,11 +82,8 @@ def test_switch_order_to_query_and_notify_error(
8682
"swo_aws_extension.flows.order_utils.query_order",
8783
return_value=context.order,
8884
)
89-
notification_mock = mocker.patch(
90-
"swo_aws_extension.flows.order_utils.MPTNotificationManager",
91-
)
9285

93-
switch_order_status_to_query_and_notify(client, context, "TemplateName") # act
86+
switch_order_status_to_query(client, context, "TemplateName") # act
9487

9588
query_order_mock.assert_called_with(
9689
client,
@@ -99,30 +92,26 @@ def test_switch_order_to_query_and_notify_error(
9992
template=new_template,
10093
error=context.order["error"],
10194
)
102-
notification_mock.assert_called_once()
10395

10496

105-
def test_switch_order_to_failed_and_notify(mocker, order_factory, fulfillment_parameters_factory):
97+
def test_switch_order_to_failed(mocker, order_factory, fulfillment_parameters_factory):
10698
client = mocker.MagicMock(spec=MPTClient)
10799
order = order_factory(fulfillment_parameters=fulfillment_parameters_factory())
108100
context = PurchaseContext.from_order_data(order)
109101
fail_order_mock = mocker.patch(
110102
"swo_aws_extension.flows.order_utils.fail_order",
111103
return_value=order,
112-
)
113-
notification_mock = mocker.patch(
114-
"swo_aws_extension.flows.order_utils.MPTNotificationManager",
104+
autospec=True,
115105
)
116106

117-
switch_order_status_to_failed_and_notify(client, context, "Failure reason") # act
107+
switch_order_status_to_failed(client, context, "Failure reason") # act
118108

119109
fail_order_mock.assert_called_with(
120110
client,
121111
context.order_id,
122112
"Failure reason",
123113
parameters=context.order["parameters"],
124114
)
125-
notification_mock.assert_called_once()
126115

127116

128117
def test_switch_order_to_process_and_notify(
@@ -142,19 +131,15 @@ def test_switch_order_to_process_and_notify(
142131
"swo_aws_extension.flows.order_utils.process_order",
143132
return_value=order,
144133
)
145-
notification_mock = mocker.patch(
146-
"swo_aws_extension.flows.order_utils.MPTNotificationManager",
147-
)
148134

149-
switch_order_status_to_process_and_notify(mpt_client, context, "TemplateName") # act
135+
switch_order_status_to_process(mpt_client, context, "TemplateName") # act
150136

151137
process_order_mock.assert_called_once_with(
152138
mpt_client,
153139
context.order_id,
154140
parameters=context.order["parameters"],
155141
template=new_template,
156142
)
157-
notification_mock.assert_called_once()
158143

159144

160145
def test_switch_order_to_process_and_notify_error(
@@ -178,7 +163,7 @@ def test_switch_order_to_process_and_notify_error(
178163
"swo_aws_extension.flows.order_utils.MPTNotificationManager",
179164
)
180165

181-
switch_order_status_to_process_and_notify(mpt_client, context, "TemplateName") # act
166+
switch_order_status_to_process(mpt_client, context, "TemplateName") # act
182167

183168
notification_mock.assert_not_called()
184169

@@ -194,24 +179,20 @@ def test_switch_order_status_to_complete(
194179
return_value=new_template,
195180
)
196181
order = order_factory(template=default_template)
197-
notification_mock = mocker.patch(
198-
"swo_aws_extension.flows.order_utils.MPTNotificationManager",
199-
)
200182
context = PurchaseContext.from_order_data(order)
201183
complete_order_mock = mocker.patch(
202184
"swo_aws_extension.flows.order_utils.complete_order",
203185
return_value=order,
204186
)
205187

206-
switch_order_status_to_complete_and_notify(client, context, "TemplateName") # act
188+
switch_order_status_to_complete(client, context, "TemplateName") # act
207189

208190
complete_order_mock.assert_called_with(
209191
client,
210192
context.order_id,
211193
parameters=context.order["parameters"],
212194
template=new_template,
213195
)
214-
notification_mock.assert_called_once()
215196

216197

217198
def test_update_processing_template_and_notify(

tests/processor/querying/test_aws_billing_transfer_invitation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def test_process_invitation_status_requested(
141141
"ResponsibilityTransfer": {"Status": ResponsibilityTransferStatus.REQUESTED}
142142
}
143143
mock_switch = mocker.patch(
144-
"swo_aws_extension.processors.querying.aws_billing_transfer_invitation.switch_order_status_to_process_and_notify"
144+
"swo_aws_extension.processors.querying.aws_billing_transfer_invitation.switch_order_status_to_process"
145145
)
146146

147147
processor.process_invitation(mock_context, "tr-123") # act
@@ -158,7 +158,7 @@ def test_process_invitation_status_accepted(
158158
"ResponsibilityTransfer": {"Status": ResponsibilityTransferStatus.ACCEPTED}
159159
}
160160
mock_switch = mocker.patch(
161-
"swo_aws_extension.processors.querying.aws_billing_transfer_invitation.switch_order_status_to_process_and_notify"
161+
"swo_aws_extension.processors.querying.aws_billing_transfer_invitation.switch_order_status_to_process"
162162
)
163163

164164
processor.process_invitation(mock_context, "tr-123") # act

0 commit comments

Comments
 (0)