Skip to content

Commit

Permalink
fix: update enterprise model lookup in removal email task (#2101)
Browse files Browse the repository at this point in the history
* fix: update enterprise model lookup in removal email task
  • Loading branch information
katrinan029 authored May 13, 2024
1 parent df30964 commit db78497
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ Unreleased
----------
* nothing unreleased

[4.18.2]
--------
* fix: update enterprise model lookup in removal email task

[4.18.1]
--------
* chore: debugging log lines
Expand Down
2 changes: 1 addition & 1 deletion enterprise/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
Your project description goes here.
"""

__version__ = "4.18.1"
__version__ = "4.18.2"
2 changes: 1 addition & 1 deletion enterprise/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ def send_group_membership_removal_notification(enterprise_customer_uuid, members
] = enterprise_catalog_client.get_catalog_content_count(catalog_uuid)
pecu_emails = []
user_id_by_email = {}
membership_records = enterprise_group_membership_model().objects.filter(uuid__in=membership_uuids)
membership_records = enterprise_group_membership_model().all_objects.filter(uuid__in=membership_uuids)
for group_membership in membership_records:
if group_membership.pending_enterprise_customer_user is not None:
pecu_emails.append(group_membership.pending_enterprise_customer_user.user_email)
Expand Down
9 changes: 7 additions & 2 deletions tests/test_enterprise/api/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8084,12 +8084,17 @@ def test_successful_remove_learners_from_group(self, mock_send_group_membership_
membership = EnterpriseGroupMembershipFactory(group=self.group_2)
memberships_to_delete.append(membership)
existing_emails.append(membership.enterprise_customer_user.user.email)

request_data = {'learner_emails': existing_emails}
catalog_uuid = uuid.uuid4()
request_data = {'learner_emails': existing_emails, 'catalog_uuid': catalog_uuid}
response = self.client.post(url, data=request_data)
assert response.status_code == 200
assert response.data == {'records_deleted': 10}
assert mock_send_group_membership_removal_notification.call_count == 1
mock_send_group_membership_removal_notification.assert_called_once_with(
self.enterprise_customer.uuid,
[membership.uuid for membership in reversed(memberships_to_delete)],
catalog_uuid,
)
for membership in memberships_to_delete:
assert EnterpriseGroupMembership.all_objects.get(pk=membership.pk).status == 'removed'
assert EnterpriseGroupMembership.all_objects.get(pk=membership.pk).removed_at
Expand Down
8 changes: 5 additions & 3 deletions tests/test_enterprise/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,17 +273,19 @@ def test_send_group_membership_removal_notification(self, mock_braze_api_client,
"""
Verify send_group_membership_removal_notification hits braze client with expected args
"""
EnterpriseGroupMembershipFactory(
pecu_membership = EnterpriseGroupMembershipFactory(
group=self.enterprise_group,
pending_enterprise_customer_user=self.pending_enterprise_customer_user,
enterprise_customer_user=None,
)
EnterpriseGroupMembershipFactory(
ecu_membership = EnterpriseGroupMembershipFactory(
group=self.enterprise_group,
pending_enterprise_customer_user=None,
enterprise_customer_user__enterprise_customer=self.enterprise_customer,
activated_at=datetime.now()
)
pecu_membership.delete()
ecu_membership.delete()
admin_email = 'edx@example.org'
mock_braze_api_client().create_recipients.return_value = {
self.user.email: {
Expand Down Expand Up @@ -315,7 +317,7 @@ def test_send_group_membership_removal_notification(self, mock_braze_api_client,
mock_catalog_content_count = 5
mock_enterprise_catalog_client().get_catalog_content_count.return_value = (
mock_catalog_content_count)
membership_uuids = EnterpriseGroupMembership.objects.values_list('uuid', flat=True)
membership_uuids = EnterpriseGroupMembership.all_objects.values_list('uuid', flat=True)
catalog_uuid = uuid.uuid4()
send_group_membership_removal_notification(
self.enterprise_customer.uuid,
Expand Down

0 comments on commit db78497

Please sign in to comment.