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
16 changes: 4 additions & 12 deletions swo_aws_extension/flows/order_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,7 @@ def set_order_template(
return context.order


def switch_order_status_to_query_and_notify(
client: MPTClient, context: InitialAWSContext, template_name: str
):
def switch_order_status_to_query(client: MPTClient, context: InitialAWSContext, template_name: str):
"""Switch the order status to 'Querying' if it is not already in that status."""
context.order = set_order_template(client, context, MPT_ORDER_STATUS_QUERYING, template_name)
kwargs = {
Expand All @@ -84,12 +82,9 @@ def switch_order_status_to_query_and_notify(
context.order_id,
**kwargs,
)
MPTNotificationManager(client).send_notification(context)


def switch_order_status_to_failed_and_notify(
client: MPTClient, context: InitialAWSContext, error: dict
):
def switch_order_status_to_failed(client: MPTClient, context: InitialAWSContext, error: dict):
"""Switch the order status to 'Failed'."""
kwargs = {
"parameters": context.order["parameters"],
Expand All @@ -101,10 +96,9 @@ def switch_order_status_to_failed_and_notify(
error,
**kwargs,
)
MPTNotificationManager(client).send_notification(context)


def switch_order_status_to_process_and_notify(
def switch_order_status_to_process(
client: MPTClient, context: InitialAWSContext, template_name: str
):
"""Switch the order status to 'Processing'."""
Expand All @@ -126,10 +120,9 @@ def switch_order_status_to_process_and_notify(
error,
)
return
MPTNotificationManager(client).send_notification(context)


def switch_order_status_to_complete_and_notify(
def switch_order_status_to_complete(
client: MPTClient, context: InitialAWSContext, template_name: str
):
"""Updates the order status to completed."""
Expand All @@ -144,7 +137,6 @@ def switch_order_status_to_complete_and_notify(
}

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


Expand Down
8 changes: 4 additions & 4 deletions swo_aws_extension/flows/steps/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
InitialAWSContext,
)
from swo_aws_extension.flows.order_utils import (
switch_order_status_to_failed_and_notify,
switch_order_status_to_query_and_notify,
switch_order_status_to_failed,
switch_order_status_to_query,
)
from swo_aws_extension.flows.steps.errors import (
AlreadyProcessedStepError,
Expand Down Expand Up @@ -99,7 +99,7 @@ def _run_process(self, context: InitialAWSContext) -> bool:
return False
except QueryStepError as error:
logger.info("%s - Query Order: %s", context.order_id, error.message)
switch_order_status_to_query_and_notify(self._client, context, error.template_id)
switch_order_status_to_query(self._client, context, error.template_id)
return False
except FailStepError as error:
logger.info("%s - Fail Order: %s", context.order_id, error)
Expand All @@ -108,6 +108,6 @@ def _run_process(self, context: InitialAWSContext) -> bool:
"id": error.id,
"message": error.message,
}
switch_order_status_to_failed_and_notify(self._client, context, fail_error)
switch_order_status_to_failed(self._client, context, fail_error)
return False
return True
6 changes: 3 additions & 3 deletions swo_aws_extension/flows/steps/complete_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from swo_aws_extension.config import Config
from swo_aws_extension.constants import ChannelHandshakeDeployed, OrderCompletedTemplate, PhasesEnum
from swo_aws_extension.flows.order import InitialAWSContext
from swo_aws_extension.flows.order_utils import switch_order_status_to_complete_and_notify
from swo_aws_extension.flows.order_utils import switch_order_status_to_complete
from swo_aws_extension.flows.steps.base import BasePhaseStep
from swo_aws_extension.flows.steps.errors import SkipStepError
from swo_aws_extension.parameters import (
Expand Down Expand Up @@ -49,7 +49,7 @@ def process(self, client: MPTClient, context: InitialAWSContext) -> None:
context.order_id,
mpa_id,
)
switch_order_status_to_complete_and_notify(client, context, template_name)
switch_order_status_to_complete(client, context, template_name)

@override
def post_step(self, client: MPTClient, context: InitialAWSContext) -> None:
Expand All @@ -72,7 +72,7 @@ def process(self, client: MPTClient, context: InitialAWSContext) -> None:
template = OrderCompletedTemplate.TERMINATION
else:
template = OrderCompletedTemplate.TERMINATION_WITHOUT_HANDSHAKE
switch_order_status_to_complete_and_notify(client, context, template)
switch_order_status_to_complete(client, context, template)

@override
def post_step(self, client: MPTClient, context: InitialAWSContext) -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
ResponsibilityTransferStatus,
)
from swo_aws_extension.flows.order import PurchaseContext
from swo_aws_extension.flows.order_utils import switch_order_status_to_process_and_notify
from swo_aws_extension.flows.order_utils import switch_order_status_to_process
from swo_aws_extension.parameters import get_responsibility_transfer_id
from swo_aws_extension.processors.processor import Processor
from swo_aws_extension.processors.querying.helper import get_template_name
Expand Down Expand Up @@ -80,9 +80,7 @@ def process_invitation(self, context: PurchaseContext, transfer_id: str):
transfer_id,
status,
)
switch_order_status_to_process_and_notify(
self.client, context, get_template_name(context)
)
switch_order_status_to_process(self.client, context, get_template_name(context))
return

logger.info(
Expand Down
10 changes: 4 additions & 6 deletions swo_aws_extension/processors/querying/aws_channel_handshake.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
PhasesEnum,
)
from swo_aws_extension.flows.order import PurchaseContext
from swo_aws_extension.flows.order_utils import switch_order_status_to_process_and_notify
from swo_aws_extension.flows.order_utils import switch_order_status_to_process
from swo_aws_extension.parameters import (
get_channel_handshake_id,
get_relationship_id,
Expand Down Expand Up @@ -52,7 +52,7 @@ def process(self, context: PurchaseContext) -> None:
context.order_id,
handshake_id,
)
switch_order_status_to_process_and_notify(
switch_order_status_to_process(
self.client, context, OrderProcessingTemplateEnum.EXISTING_ACCOUNT
)
return
Expand All @@ -64,9 +64,7 @@ def process(self, context: PurchaseContext) -> None:
handshake_id,
handshake.get("status"),
)
switch_order_status_to_process_and_notify(
self.client, context, get_template_name(context)
)
switch_order_status_to_process(self.client, context, get_template_name(context))
return

if is_querying_timeout(context, self._config.querying_timeout_days):
Expand Down Expand Up @@ -103,4 +101,4 @@ def _manage_querying_timeout(
context.order = update_order(
self.client, context.order_id, parameters=context.order["parameters"]
)
switch_order_status_to_process_and_notify(self.client, context, get_template_name(context))
switch_order_status_to_process(self.client, context, get_template_name(context))
8 changes: 3 additions & 5 deletions swo_aws_extension/processors/querying/aws_customer_roles.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
PhasesEnum,
)
from swo_aws_extension.flows.order import PurchaseContext
from swo_aws_extension.flows.order_utils import switch_order_status_to_process_and_notify
from swo_aws_extension.flows.order_utils import switch_order_status_to_process
from swo_aws_extension.flows.steps.crm_tickets.templates.deploy_roles import DEPLOY_ROLES_TEMPLATE
from swo_aws_extension.flows.steps.crm_tickets.ticket_manager import TicketManager
from swo_aws_extension.parameters import (
Expand Down Expand Up @@ -56,9 +56,7 @@ def process(self, context: PurchaseContext) -> None:
logger.info(
"%s - Customer roles are deployed. Updating order to processing.", context.order_id
)
switch_order_status_to_process_and_notify(
self.client, context, get_template_name(context)
)
switch_order_status_to_process(self.client, context, get_template_name(context))
return

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

switch_order_status_to_process_and_notify(self.client, context, get_template_name(context))
switch_order_status_to_process(self.client, context, get_template_name(context))

def _manage_customer_roles_ticket_timeout(self, context: PurchaseContext) -> None:
"""Manage customer roles ticket timeout."""
Expand Down
4 changes: 2 additions & 2 deletions tests/flows/steps/test_base_phase_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def test_query_step_error(mocker, initial_context):
error = QueryStepError("msg", "template-id")
step.proc_exc = error
switch_mock = mocker.patch(
"swo_aws_extension.flows.steps.base.switch_order_status_to_query_and_notify",
"swo_aws_extension.flows.steps.base.switch_order_status_to_query",
)

client, next_step = _run_step(mocker, step, initial_context) # act
Expand All @@ -120,7 +120,7 @@ def test_fail_step_error(mocker, initial_context):
error = FailStepError("Error_id", "Error")
step.proc_exc = error
switch_mock = mocker.patch(
"swo_aws_extension.flows.steps.base.switch_order_status_to_failed_and_notify",
"swo_aws_extension.flows.steps.base.switch_order_status_to_failed",
)

client, next_step = _run_step(mocker, step, initial_context) # act
Expand Down
6 changes: 3 additions & 3 deletions tests/flows/steps/test_complete_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def test_complete_order_process_completed(
):
order = order_factory()
mock_switch = mocker.patch(
"swo_aws_extension.flows.steps.complete_order.switch_order_status_to_complete_and_notify"
"swo_aws_extension.flows.steps.complete_order.switch_order_status_to_complete"
)
mocker.patch("swo_aws_extension.flows.steps.complete_order.update_agreement")
context = initial_context(order)
Expand Down Expand Up @@ -99,7 +99,7 @@ def test_termination_process(
),
)
mock_switch = mocker.patch(
"swo_aws_extension.flows.steps.complete_order.switch_order_status_to_complete_and_notify"
"swo_aws_extension.flows.steps.complete_order.switch_order_status_to_complete"
)
context = initial_context(order)
step = CompleteTerminationOrder(config)
Expand All @@ -118,7 +118,7 @@ def test_termination_process_without_handshake(
),
)
mock_switch = mocker.patch(
"swo_aws_extension.flows.steps.complete_order.switch_order_status_to_complete_and_notify"
"swo_aws_extension.flows.steps.complete_order.switch_order_status_to_complete"
)
context = initial_context(order)
step = CompleteTerminationOrder(config)
Expand Down
43 changes: 12 additions & 31 deletions tests/flows/test_order_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
from swo_aws_extension.flows.order import PurchaseContext
from swo_aws_extension.flows.order_utils import (
set_order_template,
switch_order_status_to_complete_and_notify,
switch_order_status_to_failed_and_notify,
switch_order_status_to_process_and_notify,
switch_order_status_to_query_and_notify,
switch_order_status_to_complete,
switch_order_status_to_failed,
switch_order_status_to_process,
switch_order_status_to_query,
update_processing_template_and_notify,
)

Expand Down Expand Up @@ -50,19 +50,15 @@ def test_switch_order_to_query_and_notify(
"swo_aws_extension.flows.order_utils.query_order",
return_value=order,
)
notification_mock = mocker.patch(
"swo_aws_extension.flows.order_utils.MPTNotificationManager",
)

switch_order_status_to_query_and_notify(client, context, "TemplateName") # act
switch_order_status_to_query(client, context, "TemplateName") # act

query_order_mock.assert_called_with(
client,
context.order_id,
parameters=context.order["parameters"],
template=new_template,
)
notification_mock.assert_called_once()


def test_switch_order_to_query_and_notify_error(
Expand All @@ -86,11 +82,8 @@ def test_switch_order_to_query_and_notify_error(
"swo_aws_extension.flows.order_utils.query_order",
return_value=context.order,
)
notification_mock = mocker.patch(
"swo_aws_extension.flows.order_utils.MPTNotificationManager",
)

switch_order_status_to_query_and_notify(client, context, "TemplateName") # act
switch_order_status_to_query(client, context, "TemplateName") # act

query_order_mock.assert_called_with(
client,
Expand All @@ -99,30 +92,26 @@ def test_switch_order_to_query_and_notify_error(
template=new_template,
error=context.order["error"],
)
notification_mock.assert_called_once()


def test_switch_order_to_failed_and_notify(mocker, order_factory, fulfillment_parameters_factory):
def test_switch_order_to_failed(mocker, order_factory, fulfillment_parameters_factory):
client = mocker.MagicMock(spec=MPTClient)
order = order_factory(fulfillment_parameters=fulfillment_parameters_factory())
context = PurchaseContext.from_order_data(order)
fail_order_mock = mocker.patch(
"swo_aws_extension.flows.order_utils.fail_order",
return_value=order,
)
notification_mock = mocker.patch(
"swo_aws_extension.flows.order_utils.MPTNotificationManager",
autospec=True,
)

switch_order_status_to_failed_and_notify(client, context, "Failure reason") # act
switch_order_status_to_failed(client, context, "Failure reason") # act

fail_order_mock.assert_called_with(
client,
context.order_id,
"Failure reason",
parameters=context.order["parameters"],
)
notification_mock.assert_called_once()


def test_switch_order_to_process_and_notify(
Expand All @@ -142,19 +131,15 @@ def test_switch_order_to_process_and_notify(
"swo_aws_extension.flows.order_utils.process_order",
return_value=order,
)
notification_mock = mocker.patch(
"swo_aws_extension.flows.order_utils.MPTNotificationManager",
)

switch_order_status_to_process_and_notify(mpt_client, context, "TemplateName") # act
switch_order_status_to_process(mpt_client, context, "TemplateName") # act

process_order_mock.assert_called_once_with(
mpt_client,
context.order_id,
parameters=context.order["parameters"],
template=new_template,
)
notification_mock.assert_called_once()


def test_switch_order_to_process_and_notify_error(
Expand All @@ -178,7 +163,7 @@ def test_switch_order_to_process_and_notify_error(
"swo_aws_extension.flows.order_utils.MPTNotificationManager",
)

switch_order_status_to_process_and_notify(mpt_client, context, "TemplateName") # act
switch_order_status_to_process(mpt_client, context, "TemplateName") # act

notification_mock.assert_not_called()

Expand All @@ -194,24 +179,20 @@ def test_switch_order_status_to_complete(
return_value=new_template,
)
order = order_factory(template=default_template)
notification_mock = mocker.patch(
"swo_aws_extension.flows.order_utils.MPTNotificationManager",
)
context = PurchaseContext.from_order_data(order)
complete_order_mock = mocker.patch(
"swo_aws_extension.flows.order_utils.complete_order",
return_value=order,
)

switch_order_status_to_complete_and_notify(client, context, "TemplateName") # act
switch_order_status_to_complete(client, context, "TemplateName") # act

complete_order_mock.assert_called_with(
client,
context.order_id,
parameters=context.order["parameters"],
template=new_template,
)
notification_mock.assert_called_once()


def test_update_processing_template_and_notify(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def test_process_invitation_status_requested(
"ResponsibilityTransfer": {"Status": ResponsibilityTransferStatus.REQUESTED}
}
mock_switch = mocker.patch(
"swo_aws_extension.processors.querying.aws_billing_transfer_invitation.switch_order_status_to_process_and_notify"
"swo_aws_extension.processors.querying.aws_billing_transfer_invitation.switch_order_status_to_process"
)

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

processor.process_invitation(mock_context, "tr-123") # act
Expand Down
Loading
Loading