Skip to content

Commit

Permalink
fix: datetime error in groups email reminder task (#485)
Browse files Browse the repository at this point in the history
  • Loading branch information
katrinan029 committed Jun 11, 2024
1 parent e421d97 commit 4454ee3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
3 changes: 2 additions & 1 deletion enterprise_access/apps/api_client/lms_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,8 @@ def get_pending_enterprise_group_memberships(self, enterprise_group_uuid):

recent_action_time = result['recent_action'].partition(': ')[2]

if should_send_email_to_pecu(recent_action_time):
if (settings.BRAZE_GROUP_EMAIL_FORCE_REMIND_ALL_PENDING_LEARNERS or
should_send_email_to_pecu(recent_action_time)):
results.append({
'pending_enterprise_customer_user_id': pending_learner_id,
'recent_action': recent_action,
Expand Down
21 changes: 11 additions & 10 deletions enterprise_access/apps/enterprise_groups/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,16 @@ def get_braze_campaign_properties(
"""
recent_action_time = recent_action.partition(": ")[2]
current_date = datetime.today().replace(hour=0, minute=0, second=0, microsecond=0)
invitation_end_date = datetime.strptime(
recent_action_time, "%B %d, %Y"
) + timedelta(days=DAYS_TO_PURGE_PII)
invitation_end_date = (datetime.strptime(recent_action_time, "%B %d, %Y") +
timedelta(days=DAYS_TO_PURGE_PII)).strftime("%B %d, %Y")
subsidy_expiration_date = datetime.strptime(subsidy_expiration_datetime, '%Y-%m-%dT%H:%M:%SZ').strftime("%B %d, %Y")
logger.info('get_braze_campaign_properties_1: recent_action_time {%s}, '
'current_date {%s}, invitation_end_date {%s}, catalog_count {%s}, subsidy_expiration_datetime {%s}',
recent_action_time,
current_date,
invitation_end_date,
catalog_count,
subsidy_expiration_datetime,)

subsidy_expiration_date,)
if settings.BRAZE_GROUP_EMAIL_FORCE_REMIND_ALL_PENDING_LEARNERS or current_date - timedelta(
days=BRAZE_GROUPS_EMAIL_CAMPAIGNS_FIRST_REMINDER_DAY
) == datetime.strptime(recent_action_time, "%B %d, %Y"):
Expand All @@ -55,7 +54,7 @@ def get_braze_campaign_properties(
"enterprise_customer": enterprise_customer_name,
"catalog_content_count": catalog_count,
"invitation_end_date": invitation_end_date,
"subsidy_expiration_datetime": subsidy_expiration_datetime,
"subsidy_expiration_datetime": subsidy_expiration_date,
},
}

Expand All @@ -70,7 +69,7 @@ def get_braze_campaign_properties(
"braze_trigger_properties": {
"catalog_content_count": catalog_count,
"invitation_end_date": invitation_end_date,
"subsidy_expiration_datetime": subsidy_expiration_datetime,
"subsidy_expiration_datetime": subsidy_expiration_date,
},
}

Expand All @@ -85,7 +84,7 @@ def get_braze_campaign_properties(
"braze_trigger_properties": {
"catalog_content_count": catalog_count,
"invitation_end_date": invitation_end_date,
"subsidy_expiration_datetime": subsidy_expiration_datetime,
"subsidy_expiration_datetime": subsidy_expiration_date,
},
}

Expand All @@ -101,7 +100,7 @@ def get_braze_campaign_properties(
"enterprise_customer": enterprise_customer_name,
"catalog_content_count": catalog_count,
"invitation_end_date": invitation_end_date,
"subsidy_expiration_datetime": subsidy_expiration_datetime,
"subsidy_expiration_datetime": subsidy_expiration_date,
},
}

Expand All @@ -116,7 +115,7 @@ def get_braze_campaign_properties(
"braze_trigger_properties": {
"catalog_content_count": catalog_count,
"invitation_end_date": invitation_end_date,
"subsidy_expiration_datetime": subsidy_expiration_datetime,
"subsidy_expiration_datetime": subsidy_expiration_date,
},
}

Expand Down Expand Up @@ -152,13 +151,15 @@ def send_group_reminder_emails(pending_enterprise_users):
pending_enterprise_user["catalog_count"],
pending_enterprise_user["subsidy_expiration_datetime"],
)
logger.info(f'get_braze_properties: {braze_properties} for recipient: {recipient}')
try:
logger.info(f'Sending braze campaign group reminder email to {recipient}.')
braze_client_instance.send_campaign_message(
braze_properties["braze_campaign_id"],
recipients=[recipient],
trigger_properties=braze_properties["braze_trigger_properties"],
)
logger.info(f'success: sent reminder email {braze_properties["braze_trigger_properties"]}')
except BrazeClientError as exc:
message = (
"Groups learner reminder email could not be sent "
Expand Down
10 changes: 7 additions & 3 deletions enterprise_access/apps/enterprise_groups/tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def setUp(self):
"recent_action": f'Invited: {self.recent_action}',
"enterprise_customer_name": "test enterprise",
"catalog_count": 5,
"subsidy_expiration_datetime": datetime.today(),
"subsidy_expiration_datetime": "2060-03-25T20:46:28Z",
})

super().setUp()
Expand All @@ -47,15 +47,19 @@ def test_send_group_reminder_emails(self, mock_braze_api_client):
self.pending_enterprise_customer_users,
)
recipient = self.pending_enterprise_customer_users[0]['user_email']
invitation_end_date = datetime.strptime(self.recent_action, '%B %d, %Y') + timedelta(days=90)
invitation_end_date = (datetime.strptime(self.recent_action, '%B %d, %Y') +
timedelta(days=90)).strftime("%B %d, %Y")
subsidy_expiration_date = datetime.strptime(
self.pending_enterprise_customer_users[0]['subsidy_expiration_datetime'],
'%Y-%m-%dT%H:%M:%SZ').strftime("%B %d, %Y")
calls = [mock.call(
settings.BRAZE_GROUPS_EMAIL_AUTO_REMINDER_DAY_5_CAMPAIGN,
recipients=[recipient],
trigger_properties={
'enterprise_customer': self.pending_enterprise_customer_users[0]['enterprise_customer_name'],
'catalog_content_count': self.pending_enterprise_customer_users[0]['catalog_count'],
'invitation_end_date': invitation_end_date,
'subsidy_expiration_datetime': self.pending_enterprise_customer_users[0]['subsidy_expiration_datetime'],
'subsidy_expiration_datetime': subsidy_expiration_date,
},
)]
mock_braze_api_client().send_campaign_message.assert_has_calls(calls)

0 comments on commit 4454ee3

Please sign in to comment.