Skip to content

Commit

Permalink
fix: remove unused create_alias task and fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
navinkarkera committed May 8, 2024
1 parent 97e02a5 commit 764857c
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 57 deletions.
23 changes: 0 additions & 23 deletions license_manager/apps/api/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,11 @@
from license_manager.apps.api import utils
from license_manager.apps.api.email import EmailClient
from license_manager.apps.api.models import BulkEnrollmentJob
from license_manager.apps.api_client.braze import BrazeApiClient
from license_manager.apps.api_client.enterprise import EnterpriseApiClient
from license_manager.apps.subscriptions.constants import (
ACTIVATED,
ASSIGNMENT_EMAIL_BATCH_SIZE,
DAYS_BEFORE_INITIAL_UTILIZATION_EMAIL_SENT,
ENTERPRISE_BRAZE_ALIAS_LABEL,
LICENSE_UTILIZATION_THRESHOLDS,
NOTIFICATION_CHOICE_AND_CAMPAIGN_BY_THRESHOLD,
NOTIFY_EMAIL_ACTION_TYPE,
Expand Down Expand Up @@ -83,27 +81,6 @@ class LoggedTaskWithRetry(LoggedTask): # pylint: disable=abstract-method
retry_jitter = True


@shared_task(base=LoggedTaskWithRetry, soft_time_limit=SOFT_TIME_LIMIT, time_limit=MAX_TIME_LIMIT)
def create_braze_aliases_task(user_emails):
"""
Creates a Braze alias for each email using the ENTERPRISE_BRAZE_ALIAS_LABEL.
A Braze alias must be created when sending emails to anonymous users.
Arguments:
user_emails (list of str): List of emails to create aliases for.
"""
try:
braze_client_instance = BrazeApiClient(logger_prefix=LICENSE_DEBUG_PREFIX)
braze_client_instance.create_braze_alias(
user_emails,
ENTERPRISE_BRAZE_ALIAS_LABEL,
)
except BrazeClientError as exc:
logger.exception(exc)
raise exc


@shared_task(base=LoggedTaskWithRetry, soft_time_limit=SOFT_TIME_LIMIT, time_limit=MAX_TIME_LIMIT)
def link_learners_to_enterprise_task(learner_emails, enterprise_customer_uuid):
"""
Expand Down
23 changes: 0 additions & 23 deletions license_manager/apps/api/tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,29 +74,6 @@ def setUp(self):
self.enterprise_sender_alias = 'Mock Enterprise Alias'
self.contact_email = '[email protected]'

@mock.patch('license_manager.apps.api.tasks.BrazeApiClient', return_value=mock.MagicMock())
def test_create_braze_aliases_task(self, mock_braze_client):
"""
Assert create_braze_aliases_task calls Braze API with the correct arguments.
"""
tasks.create_braze_aliases_task(
self.email_recipient_list
)
mock_braze_client().create_braze_alias.assert_any_call(
self.email_recipient_list,
ENTERPRISE_BRAZE_ALIAS_LABEL,
)

@mock.patch('license_manager.apps.api.tasks.BrazeApiClient', side_effect=BrazeClientError)
def test_create_braze_aliases_task_reraises_braze_exceptions(self, _):
"""
Assert create_braze_aliases_task reraises any braze exceptions.
"""
with self.assertRaises(BrazeClientError):
tasks.create_braze_aliases_task(
self.email_recipient_list
)

@mock.patch('license_manager.apps.api.tasks.EnterpriseApiClient', return_value=mock.MagicMock())
@mock.patch(
'license_manager.apps.api_client.braze.BrazeClient.send_campaign_message',
Expand Down
2 changes: 0 additions & 2 deletions license_manager/apps/api/v1/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1788,7 +1788,6 @@ def test_assign_dedupe_casing_input(self, mock_send_assignment_email_task, mock_
)
@ddt.unpack
@mock.patch('license_manager.apps.api.v1.views.link_learners_to_enterprise_task.si')
@mock.patch('license_manager.apps.api.v1.views.create_braze_aliases_task.si')
@mock.patch('license_manager.apps.api.v1.views.send_assignment_email_task.si')
def test_assign_notify_users(
self,
Expand All @@ -1797,7 +1796,6 @@ def test_assign_notify_users(
should_send_assignment_email,
mock_send_assignment_email_task,
_,
__,
):
"""
Verify that users are not sent a license assignment email if notify_users=False
Expand Down
13 changes: 4 additions & 9 deletions license_manager/apps/api/v1/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
from license_manager.apps.api.models import BulkEnrollmentJob
from license_manager.apps.api.permissions import CanRetireUser
from license_manager.apps.api.tasks import (
create_braze_aliases_task,
execute_post_revocation_tasks,
link_learners_to_enterprise_task,
revoke_all_licenses_task,
Expand Down Expand Up @@ -629,7 +628,7 @@ class LicenseAdminViewSet(BaseLicenseViewSet):
lookup_field = 'uuid'
lookup_url_kwarg = 'license_uuid'

permission_required = ''
permission_required = constants.SUBSCRIPTIONS_ADMIN_ACCESS_PERMISSION
allowed_roles = [constants.SUBSCRIPTIONS_ADMIN_ROLE]

pagination_class = LicensePagination
Expand Down Expand Up @@ -732,9 +731,9 @@ def _link_and_notify_assigned_emails(
custom_template_text,
):
"""
Helper to create async chains of link_learners_to_enterprise_task, create_braze_aliases_task,
and send_assignment_email_task for each batch of users. The task signatures are immutable,
hence the `si()` - we don't want the result of each task passed to the next task in the chain.
Helper to create async chains of link_learners_to_enterprise_task, and send_assignment_email_task
for each batch of users. The task signatures are immutable, hence the `si()` - we don't want the
result of each task passed to the next task in the chain.
If disable_onboarding_notifications is set to true on the CustomerAgreement or notify_users=False,
Braze aliases will be created but no license assignment email will be sent.
Expand All @@ -752,10 +751,6 @@ def _link_and_notify_assigned_emails(
)

if notify_users and not disable_onboarding_notifications:
# Braze aliases must be created before we attempt to send assignment emails.
tasks.link(
create_braze_aliases_task.si(pending_learner_batch),
)
tasks.link(
send_assignment_email_task.si(
custom_template_text,
Expand Down

0 comments on commit 764857c

Please sign in to comment.