Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: pass complete timestamp to Braze email trigger #639

Merged
merged 3 commits into from
Feb 13, 2025
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
2 changes: 1 addition & 1 deletion enterprise_access/apps/content_assignments/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,4 @@ class AssignmentAutomaticExpiredReason:

RETIRED_EMAIL_ADDRESS_FORMAT = 'retired_user{}@retired.invalid'

BRAZE_ACTION_REQUIRED_BY_TIMESTAMP_FORMAT = "%Y-%m-%dT%H:%M:%SZ"
BRAZE_TIMESTAMP_FORMAT = "%Y-%m-%dT%H:%M:%SZ"
11 changes: 8 additions & 3 deletions enterprise_access/apps/content_assignments/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
localized_utcnow
)

from .constants import BRAZE_ACTION_REQUIRED_BY_TIMESTAMP_FORMAT, LearnerContentAssignmentStateChoices
from .constants import BRAZE_TIMESTAMP_FORMAT, LearnerContentAssignmentStateChoices
from .utils import get_self_paced_normalized_start_date

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -225,7 +225,12 @@ def get_start_date(self):
f"course_run_metadata: {course_run_metadata}"
)
return get_human_readable_date(
get_self_paced_normalized_start_date(start_date, end_date, course_run_metadata)
get_self_paced_normalized_start_date(
start_date,
end_date,
course_run_metadata
),
BRAZE_TIMESTAMP_FORMAT
)

def get_action_required_by_timestamp(self):
Expand All @@ -238,7 +243,7 @@ def get_action_required_by_timestamp(self):
return None
return format_datetime_obj(
action_required_by_timestamp['date'],
output_pattern=BRAZE_ACTION_REQUIRED_BY_TIMESTAMP_FORMAT
output_pattern=BRAZE_TIMESTAMP_FORMAT
)

def get_course_partner(self):
Expand Down
17 changes: 9 additions & 8 deletions enterprise_access/apps/content_assignments/tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from enterprise_access.apps.api_client.braze_client import ENTERPRISE_BRAZE_ALIAS_LABEL
from enterprise_access.apps.api_client.tests.test_utils import MockResponse
from enterprise_access.apps.content_assignments.constants import (
BRAZE_ACTION_REQUIRED_BY_TIMESTAMP_FORMAT,
BRAZE_TIMESTAMP_FORMAT,
AssignmentActionErrors,
AssignmentActions,
LearnerContentAssignmentStateChoices
Expand Down Expand Up @@ -264,7 +264,7 @@ def setUpTestData(cls):
'card_image_url': 'https://itsanimage.com',
}
cls.mock_formatted_todays_date = get_human_readable_date(datetime.datetime.now().strftime(
BRAZE_ACTION_REQUIRED_BY_TIMESTAMP_FORMAT
BRAZE_TIMESTAMP_FORMAT
))

def setUp(self):
Expand Down Expand Up @@ -468,7 +468,8 @@ def test_send_reminder_email_for_pending_assignment(
'organization': self.enterprise_customer_name,
'course_title': assignment.content_title,
'enrollment_deadline': 'Jan 01, 2021',
'start_date': self.mock_formatted_todays_date,
'start_date':
datetime.datetime.now().strftime(BRAZE_TIMESTAMP_FORMAT),
'course_partner': 'Smart Folks, Good People, and Fast Learners',
'course_card_image': 'https://itsanimage.com',
'learner_portal_link': 'http://enterprise-learner-portal.example.com/test-slug',
Expand Down Expand Up @@ -532,15 +533,15 @@ def test_send_email_for_new_assignment(
'organization': self.enterprise_customer_name,
'course_title': assignment.content_title,
'enrollment_deadline': 'Jan 01, 2021',
'start_date': self.mock_formatted_todays_date,
'start_date': datetime.datetime.now().strftime(BRAZE_TIMESTAMP_FORMAT),
'course_partner': 'Smart Folks and Good People',
'course_card_image': self.mock_content_metadata['card_image_url'],
'learner_portal_link': '{}/{}'.format(
settings.ENTERPRISE_LEARNER_PORTAL_URL,
self.mock_enterprise_customer_data['slug']
),
'action_required_by_timestamp': '2021-01-01T12:00:00Z'
},
}
)
assert mock_braze_client.return_value.send_campaign_message.call_count == 1

Expand Down Expand Up @@ -697,7 +698,7 @@ def test_get_action_required_by_subsidy_expires_soonest(

sender = BrazeCampaignSender(assignment)
action_required_by = sender.get_action_required_by_timestamp()
expected_result = format_datetime_obj(yesterday, output_pattern=BRAZE_ACTION_REQUIRED_BY_TIMESTAMP_FORMAT)
expected_result = format_datetime_obj(yesterday, output_pattern=BRAZE_TIMESTAMP_FORMAT)
self.assertEqual(expected_result, action_required_by)

@mock.patch('enterprise_access.apps.content_assignments.tasks.LmsApiClient')
Expand Down Expand Up @@ -756,7 +757,7 @@ def test_get_action_required_by_enrollment_deadline_soonest(

sender = BrazeCampaignSender(assignment)
action_required_by = sender.get_action_required_by_timestamp()
expected_result = format_datetime_obj(yesterday, output_pattern=BRAZE_ACTION_REQUIRED_BY_TIMESTAMP_FORMAT)
expected_result = format_datetime_obj(yesterday, output_pattern=BRAZE_TIMESTAMP_FORMAT)
self.assertEqual(expected_result, action_required_by)

@mock.patch('enterprise_access.apps.content_assignments.tasks.LmsApiClient')
Expand Down Expand Up @@ -817,6 +818,6 @@ def test_get_action_required_by_auto_cancellation_soonest(

expected_result = format_datetime_obj(
get_automatic_expiration_date_and_reason(assignment)['date'],
output_pattern=BRAZE_ACTION_REQUIRED_BY_TIMESTAMP_FORMAT
output_pattern=BRAZE_TIMESTAMP_FORMAT
)
self.assertEqual(expected_result, action_required_by)
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from django.test import TestCase

from enterprise_access.apps.api_client.tests.test_constants import DATE_FORMAT_ISO_8601
from enterprise_access.apps.content_assignments.constants import BRAZE_ACTION_REQUIRED_BY_TIMESTAMP_FORMAT
from enterprise_access.apps.content_assignments.constants import BRAZE_TIMESTAMP_FORMAT
from enterprise_access.apps.content_assignments.tests.factories import LearnerContentAssignmentFactory
from enterprise_access.apps.content_assignments.utils import (
get_self_paced_normalized_start_date,
Expand Down Expand Up @@ -189,7 +189,7 @@ def test_has_time_to_complete(self, end_date, curr_date, weeks_to_complete, expe
@ddt.unpack
def test_get_self_paced_normalized_start_date_empty_data(self, start_date, end_date, course_metadata):
assert get_self_paced_normalized_start_date(start_date, end_date, course_metadata) == \
_curr_date(BRAZE_ACTION_REQUIRED_BY_TIMESTAMP_FORMAT)
_curr_date(BRAZE_TIMESTAMP_FORMAT)

@ddt.data(
# self-paced, has time to complete
Expand Down Expand Up @@ -241,7 +241,7 @@ def test_get_self_paced_normalized_start_date_self_paced(self, start_date, end_d

if pacing_type == 'self_paced' and (can_complete_in_time or within_start_date_threshold):
assert get_self_paced_normalized_start_date(start_date, end_date, course_metadata) == \
_curr_date(BRAZE_ACTION_REQUIRED_BY_TIMESTAMP_FORMAT)
_curr_date(BRAZE_TIMESTAMP_FORMAT)
else:
assert get_self_paced_normalized_start_date(start_date, end_date, course_metadata) == \
start_date
Expand Down
6 changes: 3 additions & 3 deletions enterprise_access/apps/content_assignments/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from pytz import UTC

from enterprise_access.apps.content_assignments.constants import (
BRAZE_ACTION_REQUIRED_BY_TIMESTAMP_FORMAT,
BRAZE_TIMESTAMP_FORMAT,
START_DATE_DEFAULT_TO_TODAY_THRESHOLD_DAYS
)

Expand Down Expand Up @@ -48,9 +48,9 @@ def get_self_paced_normalized_start_date(start_date, end_date, course_metadata):
pacing_type = course_metadata.get('pacing_type', {}) or None
weeks_to_complete = course_metadata.get('weeks_to_complete', {}) or None
if not (start_date and end_date and pacing_type and weeks_to_complete):
return curr_date.strftime(BRAZE_ACTION_REQUIRED_BY_TIMESTAMP_FORMAT)
return curr_date.strftime(BRAZE_TIMESTAMP_FORMAT)
if pacing_type == "self_paced":
if has_time_to_complete(curr_date, end_date, weeks_to_complete) or \
is_within_minimum_start_date_threshold(curr_date, start_date):
return curr_date.strftime(BRAZE_ACTION_REQUIRED_BY_TIMESTAMP_FORMAT)
return curr_date.strftime(BRAZE_TIMESTAMP_FORMAT)
return start_date