From b5dcadc564f860f71d85e4a0c607f47342460de8 Mon Sep 17 00:00:00 2001 From: katrinan029 Date: Wed, 27 Mar 2024 22:57:47 +0000 Subject: [PATCH] fix: updated failing test --- enterprise/settings/test.py | 4 +-- enterprise/tasks.py | 10 ++++-- tests/test_enterprise/api/test_views.py | 41 ------------------------- tests/test_enterprise/test_tasks.py | 25 +++++++++++++++ 4 files changed, 35 insertions(+), 45 deletions(-) diff --git a/enterprise/settings/test.py b/enterprise/settings/test.py index c60947507c..f6dae73273 100644 --- a/enterprise/settings/test.py +++ b/enterprise/settings/test.py @@ -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' diff --git a/enterprise/tasks.py b/enterprise/tasks.py index 3c8ef9fa00..28cbb1ed3d 100644 --- a/enterprise/tasks.py +++ b/enterprise/tasks.py @@ -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 @@ -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: diff --git a/tests/test_enterprise/api/test_views.py b/tests/test_enterprise/api/test_views.py index 3ee8e6bfbe..f76feada57 100644 --- a/tests/test_enterprise/api/test_views.py +++ b/tests/test_enterprise/api/test_views.py @@ -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, @@ -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. diff --git a/tests/test_enterprise/test_tasks.py b/tests/test_enterprise/test_tasks.py index bb288a4333..70a4ccafc6 100644 --- a/tests/test_enterprise/test_tasks.py +++ b/tests/test_enterprise/test_tasks.py @@ -10,6 +10,9 @@ 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 ( @@ -17,6 +20,7 @@ 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 ( @@ -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)