Skip to content

Commit

Permalink
fix: allowing for existing pecus to be added to enterprise groups
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-sheehan-edx committed Apr 17, 2024
1 parent 43ac63e commit c96667f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion enterprise/api/v1/views/enterprise_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def assign_learners(self, request, group_uuid):
]
# According to Django docs, bulk created objects can't be used in future bulk creates as the in memory
# objects returned by bulk_create won't have PK's assigned.
models.PendingEnterpriseCustomerUser.objects.bulk_create(pecu_records)
models.PendingEnterpriseCustomerUser.objects.bulk_create(pecu_records, ignore_conflicts=True)
pecus = models.PendingEnterpriseCustomerUser.objects.filter(
user_email__in=emails_to_create_batch,
enterprise_customer=customer,
Expand Down
15 changes: 15 additions & 0 deletions tests/test_enterprise/api/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -7740,6 +7740,21 @@ def test_assign_learners_requires_learner_emails(self):
assert response.status_code == 400
assert response.data == "Error: missing request data: `learner_emails`."

def test_assign_learners_to_group_with_existing_pecu(self):
"""
Test that we can add existing pending ecus to groups
"""
url = settings.TEST_SERVER + reverse(
'enterprise-group-assign-learners',
kwargs={'group_uuid': self.group_2.uuid},
)
pcu = PendingEnterpriseCustomerUserFactory(enterprise_customer=self.enterprise_customer)
existing_email = pcu.user_email
request_data = {'learner_emails': existing_email}
response = self.client.post(url, data=request_data)
assert response.status_code == 201
assert response.json() == {'records_processed': 1, 'new_learners': 1, 'existing_learners': 0}

def test_successful_assign_learners_to_group(self):
"""
Test that both existing and new learners assigned to groups properly creates membership records
Expand Down

0 comments on commit c96667f

Please sign in to comment.