Skip to content

Commit 4b4425a

Browse files
committed
MPT-19058 Adopt notification templates in AWS Extension
1 parent eb4f6e0 commit 4b4425a

File tree

12 files changed

+48
-66
lines changed

12 files changed

+48
-66
lines changed

swo_aws_extension/flows/order_utils.py

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

6969

70-
def switch_order_status_to_query_and_notify(
70+
def switch_order_status_to_query(
7171
client: MPTClient, context: InitialAWSContext, template_name: str
7272
):
7373
"""Switch the order status to 'Querying' if it is not already in that status."""
@@ -83,11 +83,10 @@ def switch_order_status_to_query_and_notify(
8383
client,
8484
context.order_id,
8585
**kwargs,
86-
)
87-
MPTNotificationManager(client).send_notification(context)
86+
)
8887

8988

90-
def switch_order_status_to_failed_and_notify(
89+
def switch_order_status_to_failed(
9190
client: MPTClient, context: InitialAWSContext, error: dict
9291
):
9392
"""Switch the order status to 'Failed'."""
@@ -101,10 +100,9 @@ def switch_order_status_to_failed_and_notify(
101100
error,
102101
**kwargs,
103102
)
104-
MPTNotificationManager(client).send_notification(context)
105103

106104

107-
def switch_order_status_to_process_and_notify(
105+
def switch_order_status_to_process(
108106
client: MPTClient, context: InitialAWSContext, template_name: str
109107
):
110108
"""Switch the order status to 'Processing'."""
@@ -126,10 +124,9 @@ def switch_order_status_to_process_and_notify(
126124
error,
127125
)
128126
return
129-
MPTNotificationManager(client).send_notification(context)
130127

131128

132-
def switch_order_status_to_complete_and_notify(
129+
def switch_order_status_to_complete(
133130
client: MPTClient, context: InitialAWSContext, template_name: str
134131
):
135132
"""Updates the order status to completed."""
@@ -144,7 +141,6 @@ def switch_order_status_to_complete_and_notify(
144141
}
145142

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

150146

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 & 2 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,7 +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(
83+
switch_order_status_to_process(
8484
self.client, context, get_template_name(context)
8585
)
8686
return

swo_aws_extension/processors/querying/aws_channel_handshake.py

Lines changed: 4 additions & 4 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,7 +64,7 @@ def process(self, context: PurchaseContext) -> None:
6464
handshake_id,
6565
handshake.get("status"),
6666
)
67-
switch_order_status_to_process_and_notify(
67+
switch_order_status_to_process(
6868
self.client, context, get_template_name(context)
6969
)
7070
return
@@ -103,4 +103,4 @@ def _manage_querying_timeout(
103103
context.order = update_order(
104104
self.client, context.order_id, parameters=context.order["parameters"]
105105
)
106-
switch_order_status_to_process_and_notify(self.client, context, get_template_name(context))
106+
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 & 3 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,7 +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(
59+
switch_order_status_to_process(
6060
self.client, context, get_template_name(context)
6161
)
6262
return
@@ -85,7 +85,7 @@ def _manage_querying_timeout(self, context: PurchaseContext):
8585
self.client, context.order_id, parameters=context.order["parameters"]
8686
)
8787

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

9090
def _manage_customer_roles_ticket_timeout(self, context: PurchaseContext) -> None:
9191
"""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: 11 additions & 25 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,25 @@ 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,
112104
)
113-
notification_mock = mocker.patch(
114-
"swo_aws_extension.flows.order_utils.MPTNotificationManager",
115-
)
116105

117-
switch_order_status_to_failed_and_notify(client, context, "Failure reason") # act
106+
switch_order_status_to_failed(client, context, "Failure reason") # act
118107

119108
fail_order_mock.assert_called_with(
120109
client,
121110
context.order_id,
122111
"Failure reason",
123112
parameters=context.order["parameters"],
124113
)
125-
notification_mock.assert_called_once()
126114

127115

128116
def test_switch_order_to_process_and_notify(
@@ -146,15 +134,14 @@ def test_switch_order_to_process_and_notify(
146134
"swo_aws_extension.flows.order_utils.MPTNotificationManager",
147135
)
148136

149-
switch_order_status_to_process_and_notify(mpt_client, context, "TemplateName") # act
137+
switch_order_status_to_process(mpt_client, context, "TemplateName") # act
150138

151139
process_order_mock.assert_called_once_with(
152140
mpt_client,
153141
context.order_id,
154142
parameters=context.order["parameters"],
155143
template=new_template,
156144
)
157-
notification_mock.assert_called_once()
158145

159146

160147
def test_switch_order_to_process_and_notify_error(
@@ -178,7 +165,7 @@ def test_switch_order_to_process_and_notify_error(
178165
"swo_aws_extension.flows.order_utils.MPTNotificationManager",
179166
)
180167

181-
switch_order_status_to_process_and_notify(mpt_client, context, "TemplateName") # act
168+
switch_order_status_to_process(mpt_client, context, "TemplateName") # act
182169

183170
notification_mock.assert_not_called()
184171

@@ -203,15 +190,14 @@ def test_switch_order_status_to_complete(
203190
return_value=order,
204191
)
205192

206-
switch_order_status_to_complete_and_notify(client, context, "TemplateName") # act
193+
switch_order_status_to_complete(client, context, "TemplateName") # act
207194

208195
complete_order_mock.assert_called_with(
209196
client,
210197
context.order_id,
211198
parameters=context.order["parameters"],
212199
template=new_template,
213200
)
214-
notification_mock.assert_called_once()
215201

216202

217203
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)