Skip to content

Commit 95f7cdc

Browse files
Muhammad Faraz  MaqsoodMuhammad Faraz  Maqsood
Muhammad Faraz Maqsood
authored and
Muhammad Faraz Maqsood
committed
chore: rename braze_client to email_client
1 parent 2009e89 commit 95f7cdc

9 files changed

+68
-68
lines changed

common/djangoapps/student/management/commands/retrieve_unsubscribed_emails.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from django.core.management.base import BaseCommand, CommandError
1010
from django.template.loader import get_template
1111

12-
from lms.djangoapps.utils import get_braze_client
12+
from lms.djangoapps.utils import get_email_client
1313

1414
logger = logging.getLogger(__name__)
1515

@@ -69,12 +69,12 @@ def handle(self, *args, **options):
6969
logger.info(f'Retrieving unsubscribed emails from {start_date} to {end_date}')
7070

7171
try:
72-
braze_client = get_braze_client()
73-
if not braze_client:
74-
logger.info('No Braze client found. Unable to retrieve unsubscribed emails.')
72+
email_client = get_email_client()
73+
if not email_client:
74+
logger.info('No Email client found. Unable to retrieve unsubscribed emails.')
7575
return
7676

77-
emails = braze_client.retrieve_unsubscribed_emails(
77+
emails = email_client.retrieve_unsubscribed_emails(
7878
start_date=start_date,
7979
end_date=end_date,
8080
)

common/djangoapps/student/management/commands/unsubscribe_user_email.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from django.core.management.base import BaseCommand, CommandError
66

7-
from lms.djangoapps.utils import get_braze_client
7+
from lms.djangoapps.utils import get_email_client
88

99
logger = logging.getLogger(__name__)
1010
CHUNK_SIZE = 50
@@ -63,10 +63,10 @@ def handle(self, *args, **options):
6363
chunks = self._chunk_list(emails)
6464

6565
try:
66-
braze_client = get_braze_client()
67-
if braze_client:
66+
email_client = get_email_client()
67+
if email_client:
6868
for i, chunk in enumerate(chunks):
69-
braze_client.unsubscribe_user_email(
69+
email_client.unsubscribe_user_email(
7070
email=chunk,
7171
)
7272
logger.info(f"Successfully unsubscribed for chunk-{i + 1} consist of {len(chunk)} emails")

common/djangoapps/student/management/tests/test_retrieve_unsubscribed_emails.py

+20-20
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ def _write_test_csv(csv, lines):
3939
BRAZE_UNSUBSCRIBED_EMAILS_RECIPIENT_EMAIL=['[email protected]']
4040
)
4141
@patch('common.djangoapps.student.management.commands.retrieve_unsubscribed_emails.EmailMultiAlternatives.send')
42-
@patch('common.djangoapps.student.management.commands.retrieve_unsubscribed_emails.get_braze_client')
42+
@patch('common.djangoapps.student.management.commands.retrieve_unsubscribed_emails.get_email_client')
4343
@patch('common.djangoapps.student.management.commands.retrieve_unsubscribed_emails.logger.info')
44-
def test_retrieve_unsubscribed_emails_command(self, mock_logger_info, mock_get_braze_client, mock_send):
44+
def test_retrieve_unsubscribed_emails_command(self, mock_logger_info, mock_get_email_client, mock_send):
4545
"""
4646
Test the retrieve_unsubscribed_emails command
4747
"""
48-
mock_braze_client = mock_get_braze_client.return_value
49-
mock_braze_client.retrieve_unsubscribed_emails.return_value = [
48+
mock_email_client = mock_get_email_client.return_value
49+
mock_email_client.retrieve_unsubscribed_emails.return_value = [
5050
{'email': '[email protected]', 'unsubscribed_at': '2023-06-01 10:00:00'},
5151
{'email': '[email protected]', 'unsubscribed_at': '2023-06-02 12:00:00'},
5252
]
@@ -81,14 +81,14 @@ def test_retrieve_unsubscribed_emails_command(self, mock_logger_info, mock_get_b
8181
BRAZE_UNSUBSCRIBED_EMAILS_RECIPIENT_EMAIL=['[email protected]']
8282
)
8383
@patch('common.djangoapps.student.management.commands.retrieve_unsubscribed_emails.EmailMultiAlternatives.send')
84-
@patch('common.djangoapps.student.management.commands.retrieve_unsubscribed_emails.get_braze_client')
84+
@patch('common.djangoapps.student.management.commands.retrieve_unsubscribed_emails.get_email_client')
8585
@patch('common.djangoapps.student.management.commands.retrieve_unsubscribed_emails.logger.info')
86-
def test_retrieve_unsubscribed_emails_command_with_dates(self, mock_logger_info, mock_get_braze_client, mock_send):
86+
def test_retrieve_unsubscribed_emails_command_with_dates(self, mock_logger_info, mock_get_email_client, mock_send):
8787
"""
8888
Test the retrieve_unsubscribed_emails command with custom start and end dates.
8989
"""
90-
mock_braze_client = mock_get_braze_client.return_value
91-
mock_braze_client.retrieve_unsubscribed_emails.return_value = [
90+
mock_email_client = mock_get_email_client.return_value
91+
mock_email_client.retrieve_unsubscribed_emails.return_value = [
9292
{'email': '[email protected]', 'unsubscribed_at': '2023-06-03 08:00:00'},
9393
{'email': '[email protected]', 'unsubscribed_at': '2023-06-04 14:00:00'},
9494
]
@@ -123,15 +123,15 @@ def test_retrieve_unsubscribed_emails_command_with_dates(self, mock_logger_info,
123123
self.assertIn('[email protected],2023-06-04 14:00:00', csv_data)
124124

125125
@patch('common.djangoapps.student.management.commands.retrieve_unsubscribed_emails.EmailMultiAlternatives.send')
126-
@patch('common.djangoapps.student.management.commands.retrieve_unsubscribed_emails.get_braze_client')
126+
@patch('common.djangoapps.student.management.commands.retrieve_unsubscribed_emails.get_email_client')
127127
@patch('common.djangoapps.student.management.commands.retrieve_unsubscribed_emails.logger.exception')
128-
def test_retrieve_unsubscribed_emails_command_braze_exception(self, mock_logger_exception, mock_get_braze_client,
128+
def test_retrieve_unsubscribed_emails_command_braze_exception(self, mock_logger_exception, mock_get_email_client,
129129
mock_send):
130130
"""
131131
Test the retrieve_unsubscribed_emails command when an exception is raised.
132132
"""
133-
mock_braze_client = mock_get_braze_client.return_value
134-
mock_braze_client.retrieve_unsubscribed_emails.side_effect = Exception('Braze API error')
133+
mock_email_client = mock_get_email_client.return_value
134+
mock_email_client.retrieve_unsubscribed_emails.side_effect = Exception('Braze API error')
135135
mock_send.return_value = MagicMock()
136136

137137
with self.assertRaises(CommandError):
@@ -143,14 +143,14 @@ def test_retrieve_unsubscribed_emails_command_braze_exception(self, mock_logger_
143143
mock_send.assert_not_called()
144144

145145
@patch('common.djangoapps.student.management.commands.retrieve_unsubscribed_emails.EmailMultiAlternatives.send')
146-
@patch('common.djangoapps.student.management.commands.retrieve_unsubscribed_emails.get_braze_client')
146+
@patch('common.djangoapps.student.management.commands.retrieve_unsubscribed_emails.get_email_client')
147147
@patch('common.djangoapps.student.management.commands.retrieve_unsubscribed_emails.logger.info')
148-
def test_retrieve_unsubscribed_emails_command_no_data(self, mock_logger_info, mock_get_braze_client, mock_send):
148+
def test_retrieve_unsubscribed_emails_command_no_data(self, mock_logger_info, mock_get_email_client, mock_send):
149149
"""
150150
Test the retrieve_unsubscribed_emails command when no unsubscribed emails are returned.
151151
"""
152-
mock_braze_client = mock_get_braze_client.return_value
153-
mock_braze_client.retrieve_unsubscribed_emails.return_value = []
152+
mock_email_client = mock_get_email_client.return_value
153+
mock_email_client.retrieve_unsubscribed_emails.return_value = []
154154
mock_send.return_value = MagicMock()
155155

156156
call_command('retrieve_unsubscribed_emails')
@@ -166,15 +166,15 @@ def test_retrieve_unsubscribed_emails_command_no_data(self, mock_logger_info, mo
166166
BRAZE_UNSUBSCRIBED_EMAILS_RECIPIENT_EMAIL=['[email protected]']
167167
)
168168
@patch('common.djangoapps.student.management.commands.retrieve_unsubscribed_emails.EmailMultiAlternatives.send')
169-
@patch('common.djangoapps.student.management.commands.retrieve_unsubscribed_emails.get_braze_client')
169+
@patch('common.djangoapps.student.management.commands.retrieve_unsubscribed_emails.get_email_client')
170170
@patch('common.djangoapps.student.management.commands.retrieve_unsubscribed_emails.logger.exception')
171171
def test_retrieve_unsubscribed_emails_command_error_sending_email(self, mock_logger_exception,
172-
mock_get_braze_client, mock_send):
172+
mock_get_email_client, mock_send):
173173
"""
174174
Test the retrieve_unsubscribed_emails command when an error occurs during email sending.
175175
"""
176-
mock_braze_client = mock_get_braze_client.return_value
177-
mock_braze_client.retrieve_unsubscribed_emails.return_value = [
176+
mock_email_client = mock_get_email_client.return_value
177+
mock_email_client.retrieve_unsubscribed_emails.return_value = [
178178
{'email': '[email protected]', 'unsubscribed_at': '2023-06-01 10:00:00'},
179179
]
180180
mock_send.side_effect = Exception('Email sending error')

common/djangoapps/student/management/tests/test_unsubscribe_user_email.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ def _write_test_csv(csv, lines):
3737
csv.seek(0)
3838
return csv
3939

40-
@patch("common.djangoapps.student.management.commands.unsubscribe_user_email.get_braze_client")
41-
def test_unsubscribe_user_email(self, mock_get_braze_client):
40+
@patch("common.djangoapps.student.management.commands.unsubscribe_user_email.get_email_client")
41+
def test_unsubscribe_user_email(self, mock_get_email_client):
4242
""" Test CSV file to unsubscribe user's email"""
4343

4444
with NamedTemporaryFile() as csv:
@@ -50,7 +50,7 @@ def test_unsubscribe_user_email(self, mock_get_braze_client):
5050
csv.name
5151
)
5252

53-
mock_get_braze_client.assert_called_once()
53+
mock_get_email_client.assert_called_once()
5454

5555
def test_command_error_for_csv_path(self):
5656
""" Test command error raised if csv_path is not valid"""

common/djangoapps/student/signals/receivers.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from django.dispatch import receiver
1313

1414
from lms.djangoapps.courseware.toggles import courseware_mfe_progress_milestones_are_active
15-
from lms.djangoapps.utils import get_braze_client
15+
from lms.djangoapps.utils import get_email_client
1616
from common.djangoapps.student.helpers import EMAIL_EXISTS_MSG_FMT, USERNAME_EXISTS_MSG_FMT, AccountValidationError
1717
from common.djangoapps.student.models import (
1818
CourseAccessRole,
@@ -145,8 +145,8 @@ def _listen_for_user_email_changed(sender, user, request, **kwargs):
145145
attributes = [{'email': email, 'external_id': user_id}]
146146

147147
try:
148-
braze_client = get_braze_client()
149-
if braze_client:
150-
braze_client.track_user(attributes=attributes)
148+
email_client = get_email_client()
149+
if email_client:
150+
email_client.track_user(attributes=attributes)
151151
except Exception as exc: # pylint: disable=broad-except
152152
logger.exception(f'Unable to sync new email [{email}] with Braze for user [{user_id}]')

common/djangoapps/student/tasks.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
get_course_dates_for_email,
1515
get_instructors,
1616
)
17-
from lms.djangoapps.utils import get_braze_client
17+
from lms.djangoapps.utils import get_email_client
1818
from openedx.core.djangoapps.catalog.utils import (
1919
get_course_uuid_for_course,
2020
get_owners_for_course,
@@ -131,9 +131,9 @@ def send_course_enrollment_email(
131131

132132
try:
133133
recipients = [{"external_user_id": user_id}]
134-
braze_client = get_braze_client()
135-
if braze_client:
136-
braze_client.send_canvas_message(
134+
email_client = get_email_client()
135+
if email_client:
136+
email_client.send_canvas_message(
137137
canvas_id=settings.BRAZE_COURSE_ENROLLMENT_CANVAS_ID,
138138
recipients=recipients,
139139
canvas_entry_properties=canvas_entry_properties,

common/djangoapps/student/tests/test_receivers.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ def test_listen_for_verified_name_approved(self):
7272
assert profile.name == new_name
7373

7474
@skip_unless_lms
75-
@patch('common.djangoapps.student.signals.receivers.get_braze_client')
76-
def test_listen_for_user_email_changed(self, mock_get_braze_client):
75+
@patch('common.djangoapps.student.signals.receivers.get_email_client')
76+
def test_listen_for_user_email_changed(self, mock_get_email_client):
7777
"""
7878
Ensure that USER_EMAIL_CHANGED signal triggers correct calls to
79-
get_braze_client and update email in session.
79+
get_email_client and update email in session.
8080
"""
8181
user = UserFactory(email='[email protected]', username='jdoe')
8282
request = get_mock_request(user=user)
@@ -88,5 +88,5 @@ def test_listen_for_user_email_changed(self, mock_get_braze_client):
8888

8989
USER_EMAIL_CHANGED.send(sender=None, user=user, request=request)
9090

91-
assert mock_get_braze_client.called
91+
assert mock_get_email_client.called
9292
assert request.session.get('email', None) == user.email

common/djangoapps/student/tests/test_tasks.py

+19-19
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,10 @@ def _get_canvas_properties(
173173
@patch("common.djangoapps.student.tasks.get_owners_for_course")
174174
@patch("common.djangoapps.student.tasks.get_course_run_details")
175175
@patch("common.djangoapps.student.tasks.get_course_dates_for_email")
176-
@patch("common.djangoapps.student.tasks.get_braze_client")
176+
@patch("common.djangoapps.student.tasks.get_email_client")
177177
def test_success_calls_for_canvas_properties(
178178
self,
179-
mock_get_braze_client,
179+
mock_get_email_client,
180180
mock_get_course_dates_for_email,
181181
mock_get_course_run_details,
182182
mock_get_owners_for_course,
@@ -194,7 +194,7 @@ def test_success_calls_for_canvas_properties(
194194
send_course_enrollment_email.apply_async(
195195
kwargs=self.send_course_enrollment_email_kwargs
196196
)
197-
mock_get_braze_client.return_value.send_canvas_message.assert_called_with(
197+
mock_get_email_client.return_value.send_canvas_message.assert_called_with(
198198
canvas_id=BRAZE_COURSE_ENROLLMENT_CANVAS_ID,
199199
recipients=[
200200
{
@@ -207,14 +207,14 @@ def test_success_calls_for_canvas_properties(
207207
@patch("common.djangoapps.student.tasks.get_course_uuid_for_course")
208208
@patch("common.djangoapps.student.tasks.get_owners_for_course")
209209
@patch("common.djangoapps.student.tasks.get_course_run_details")
210-
@patch("common.djangoapps.student.tasks.get_braze_client")
210+
@patch("common.djangoapps.student.tasks.get_email_client")
211211
@patch(
212212
"common.djangoapps.student.tasks.get_course_dates_for_email",
213213
Mock(side_effect=Exception),
214214
)
215215
def test_canvas_properties_without_course_dates(
216216
self,
217-
mock_get_braze_client,
217+
mock_get_email_client,
218218
mock_get_course_run_details,
219219
mock_get_owners_for_course,
220220
mock_get_course_uuid_for_course,
@@ -230,7 +230,7 @@ def test_canvas_properties_without_course_dates(
230230
send_course_enrollment_email.apply_async(
231231
kwargs=self.send_course_enrollment_email_kwargs
232232
)
233-
mock_get_braze_client.return_value.send_canvas_message.assert_called_with(
233+
mock_get_email_client.return_value.send_canvas_message.assert_called_with(
234234
canvas_id=BRAZE_COURSE_ENROLLMENT_CANVAS_ID,
235235
recipients=[
236236
{
@@ -243,14 +243,14 @@ def test_canvas_properties_without_course_dates(
243243
@patch("common.djangoapps.student.tasks.get_course_uuid_for_course")
244244
@patch("common.djangoapps.student.tasks.get_owners_for_course")
245245
@patch("common.djangoapps.student.tasks.get_course_dates_for_email")
246-
@patch("common.djangoapps.student.tasks.get_braze_client")
246+
@patch("common.djangoapps.student.tasks.get_email_client")
247247
@patch(
248248
"common.djangoapps.student.tasks.get_course_run_details",
249249
Mock(side_effect=Exception),
250250
)
251251
def test_canvas_properties_on_get_course_run_details_failure(
252252
self,
253-
mock_get_braze_client,
253+
mock_get_email_client,
254254
mock_get_course_dates_for_email,
255255
mock_get_owners_for_course,
256256
mock_get_course_uuid_for_course,
@@ -266,7 +266,7 @@ def test_canvas_properties_on_get_course_run_details_failure(
266266
send_course_enrollment_email.apply_async(
267267
kwargs=self.send_course_enrollment_email_kwargs
268268
)
269-
mock_get_braze_client.return_value.send_canvas_message.assert_called_with(
269+
mock_get_email_client.return_value.send_canvas_message.assert_called_with(
270270
canvas_id=BRAZE_COURSE_ENROLLMENT_CANVAS_ID,
271271
recipients=[
272272
{
@@ -280,12 +280,12 @@ def test_canvas_properties_on_get_course_run_details_failure(
280280

281281
@patch("common.djangoapps.student.tasks.get_course_uuid_for_course")
282282
@patch("common.djangoapps.student.tasks.get_course_dates_for_email")
283-
@patch("common.djangoapps.student.tasks.get_braze_client")
283+
@patch("common.djangoapps.student.tasks.get_email_client")
284284
@patch(TASK_LOGGER)
285285
def test_email_task_when_course_uuid_is_missing(
286286
self,
287287
mocked_logger,
288-
mock_get_braze_client,
288+
mock_get_email_client,
289289
mock_get_course_dates_for_email,
290290
mock_get_course_uuid_for_course,
291291
):
@@ -304,7 +304,7 @@ def test_email_task_when_course_uuid_is_missing(
304304
f"[Course Enrollment] Course run call failed for "
305305
f"user: {self.user.id} course: {self.course.id} error: Missing course_uuid"
306306
)
307-
mock_get_braze_client.return_value.send_canvas_message.assert_called_with(
307+
mock_get_email_client.return_value.send_canvas_message.assert_called_with(
308308
canvas_id=BRAZE_COURSE_ENROLLMENT_CANVAS_ID,
309309
recipients=[
310310
{
@@ -318,12 +318,12 @@ def test_email_task_when_course_uuid_is_missing(
318318
@patch("common.djangoapps.student.tasks.get_owners_for_course")
319319
@patch("common.djangoapps.student.tasks.get_course_run_details")
320320
@patch("common.djangoapps.student.tasks.get_course_dates_for_email")
321-
@patch("common.djangoapps.student.tasks.get_braze_client")
321+
@patch("common.djangoapps.student.tasks.get_email_client")
322322
@patch(TASK_LOGGER)
323323
def test_email_task_when_course_run_is_missing(
324324
self,
325325
mocked_logger,
326-
mock_get_braze_client,
326+
mock_get_email_client,
327327
mock_get_course_dates_for_email,
328328
mock_get_course_run_details,
329329
mock_get_owners_for_course,
@@ -346,7 +346,7 @@ def test_email_task_when_course_run_is_missing(
346346
f"[Course Enrollment] Course run call failed for "
347347
f"user: {self.user.id} course: {self.course.id} error: Missing course_run"
348348
)
349-
mock_get_braze_client.return_value.send_canvas_message.assert_called_with(
349+
mock_get_email_client.return_value.send_canvas_message.assert_called_with(
350350
canvas_id=BRAZE_COURSE_ENROLLMENT_CANVAS_ID,
351351
recipients=[
352352
{
@@ -360,7 +360,7 @@ def test_email_task_when_course_run_is_missing(
360360
@patch("common.djangoapps.student.tasks.get_owners_for_course")
361361
@patch("common.djangoapps.student.tasks.get_course_run_details")
362362
@patch("common.djangoapps.student.tasks.get_course_dates_for_email")
363-
def test_retry_with_braze_client_exception(
363+
def test_retry_with_email_client_exception(
364364
self,
365365
mock_get_course_dates_for_email,
366366
mock_get_course_run_details,
@@ -377,12 +377,12 @@ def test_retry_with_braze_client_exception(
377377
mock_get_course_dates_for_email.return_value = self._get_course_dates()
378378

379379
with patch(
380-
'common.djangoapps.student.tasks.get_braze_client',
380+
'common.djangoapps.student.tasks.get_email_client',
381381
new_callable=PropertyMock,
382382
side_effect=Exception('Braze Client Exception')
383-
) as mock_get_braze_client:
383+
) as mock_get_email_client:
384384
task = send_course_enrollment_email.apply_async(
385385
kwargs=self.send_course_enrollment_email_kwargs
386386
)
387387
pytest.raises(Exception, task.get)
388-
self.assertEqual(mock_get_braze_client.call_count, (MAX_RETRIES + 1))
388+
self.assertEqual(mock_get_email_client.call_count, (MAX_RETRIES + 1))

0 commit comments

Comments
 (0)