Skip to content

Commit

Permalink
fix: updated failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
katrinan029 committed Mar 27, 2024
1 parent 1bfa117 commit b5dcadc
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 45 deletions.
4 changes: 2 additions & 2 deletions enterprise/settings/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ def root(*args):
ENTERPRISE_SSO_ORCHESTRATOR_CONFIGURE_PATH = 'configure'
ENTERPRISE_SSO_ORCHESTRATOR_CONFIGURE_EDX_OAUTH_PATH = 'configure-edx-oauth'

EDX_BRAZE_API_KEY='894e2287-66d5-4e41-b04e-67aba70dabf4'
EDX_BRAZE_API_SERVER=None
EDX_BRAZE_API_KEY='test-api-key'
EDX_BRAZE_API_SERVER='test-api-server'
BRAZE_GROUPS_INVITATION_EMAIL_CAMPAIGN_ID = 'test-invitation-campaign-id'
BRAZE_GROUPS_REMOVAL_EMAIL_CAMPAIGN_ID = 'test-removal-campaign-id'
10 changes: 8 additions & 2 deletions enterprise/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

from enterprise.api_client.braze import ENTERPRISE_BRAZE_ALIAS_LABEL, BrazeAPIClient
from enterprise.api_client.enterprise_catalog import EnterpriseCatalogApiClient

from enterprise.constants import SSO_BRAZE_CAMPAIGN_ID
from enterprise.utils import get_enterprise_customer, send_email_notification_message

Expand Down Expand Up @@ -189,9 +188,16 @@ def send_sso_configured_email(

try:
braze_client_instance = BrazeAPIClient()
recipient = braze_client_instance.create_recipient_no_external_id(
contact_email,
)
braze_client_instance.create_braze_alias(
[contact_email],
ENTERPRISE_BRAZE_ALIAS_LABEL,
)
braze_client_instance.send_campaign_message(
braze_campaign_id,
recipients=[contact_email],
recipients=[recipient],
trigger_properties=braze_trigger_properties,
)
except BrazeClientError as exc:
Expand Down
41 changes: 0 additions & 41 deletions tests/test_enterprise/api/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
ENTERPRISE_OPERATOR_ROLE,
ENTERPRISE_REPORTING_CONFIG_ADMIN_ROLE,
PATHWAY_CUSTOMER_ADMIN_ENROLLMENT,
SSO_BRAZE_CAMPAIGN_ID,
)
from enterprise.models import (
ChatGPTResponse,
Expand Down Expand Up @@ -7961,46 +7960,6 @@ def test_sso_configuration_oauth_orchestration_complete(self, mock_braze_client)
assert enterprise_sso_orchestration_config.is_pending_configuration() is False
assert response.status_code == status.HTTP_200_OK

@mock.patch("enterprise.api_client.braze.BrazeAPIClient")
def test_sso_configuration_oauth_orchestration_email(self, mock_braze_client):
"""
Assert sso configuration calls Braze API with the correct arguments.
"""
mock_braze_client.return_value.get_braze_client.return_value = mock.MagicMock()
mock_send_campaign_message = mock_braze_client.return_value.send_campaign_message

self.set_jwt_cookie(ENTERPRISE_OPERATOR_ROLE, "*")
config_pk = uuid.uuid4()
enterprise_sso_orchestration_config = EnterpriseCustomerSsoConfigurationFactory(
uuid=config_pk,
enterprise_customer=self.enterprise_customer,
configured_at=None,
submitted_at=localized_utcnow(),
)
url = settings.TEST_SERVER + reverse(
self.SSO_CONFIGURATION_COMPLETE_ENDPOINT,
kwargs={'configuration_uuid': config_pk}
)
assert enterprise_sso_orchestration_config.is_pending_configuration()
self.client.post(url)

expected_trigger_properties = {
'enterprise_customer_slug': self.enterprise_customer.slug,
'enterprise_customer_name': self.enterprise_customer.name,
'enterprise_sender_alias': self.enterprise_customer.sender_alias,
'enterprise_contact_email': self.enterprise_customer.contact_email,
}

mock_send_campaign_message.assert_any_call(
SSO_BRAZE_CAMPAIGN_ID,
recipients=[self.enterprise_customer.contact_email],
trigger_properties=expected_trigger_properties,
)
enterprise_sso_orchestration_config.refresh_from_db()
assert enterprise_sso_orchestration_config.configured_at is not None

# -------------------------- retrieve test suite --------------------------

def test_sso_configuration_retrieve(self):
"""
Test expected response when successfully retrieving an existing sso configuration.
Expand Down
25 changes: 25 additions & 0 deletions tests/test_enterprise/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@

from pytest import mark

from enterprise.constants import (
SSO_BRAZE_CAMPAIGN_ID,
)
from enterprise.models import EnterpriseCourseEnrollment, EnterpriseEnrollmentSource
from enterprise.settings.test import BRAZE_GROUPS_INVITATION_EMAIL_CAMPAIGN_ID, BRAZE_GROUPS_REMOVAL_EMAIL_CAMPAIGN_ID
from enterprise.tasks import (
create_enterprise_enrollment,
send_enterprise_email_notification,
send_group_membership_invitation_notification,
send_group_membership_removal_notification,
send_sso_configured_email,
)
from enterprise.utils import serialize_notification_content
from test_utils.factories import (
Expand Down Expand Up @@ -272,3 +276,24 @@ def test_send_group_membership_removal_notification(self, mock_braze_api_client,
},
) for recipient in mock_recipients]
mock_braze_api_client().send_campaign_message.assert_has_calls(calls)

@mock.patch('enterprise.tasks.BrazeAPIClient', return_value=mock.MagicMock())
def test_sso_configuration_oauth_orchestration_email(self, mock_braze_client):
"""
Assert sso configuration calls Braze API with the correct arguments.
"""
mock_braze_client().create_recipient_no_external_id.return_value = (
self.enterprise_customer.contact_email)
expected_trigger_properties = {
'enterprise_customer_slug': self.enterprise_customer.slug,
'enterprise_customer_name': self.enterprise_customer.name,
'enterprise_sender_alias': self.enterprise_customer.sender_alias,
'enterprise_contact_email': self.enterprise_customer.contact_email,
}
send_sso_configured_email(self.enterprise_customer.uuid)
call = [mock.call(
SSO_BRAZE_CAMPAIGN_ID,
recipients=[self.enterprise_customer.contact_email],
trigger_properties=expected_trigger_properties
)]
mock_braze_client().send_campaign_message.assert_has_calls(call)

0 comments on commit b5dcadc

Please sign in to comment.