Skip to content

Commit

Permalink
feat: adds a test for missing program cert record
Browse files Browse the repository at this point in the history
* The test verifies the behavior should be acting correctly and not raising exceptions

FIXES: APER-718
  • Loading branch information
deborahgu committed Aug 31, 2023
1 parent 9d4e32e commit 57732b1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
17 changes: 17 additions & 0 deletions credentials/apps/records/tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from logging import INFO
import urllib

from django.contrib.contenttypes.models import ContentType
Expand All @@ -24,6 +25,7 @@
UserCredentialFactory,
)
from credentials.apps.records.constants import UserCreditPathwayStatus
from credentials.apps.records.models import ProgramCertRecord
from credentials.apps.records.tests.factories import ProgramCertRecordFactory, UserCreditPathwayFactory
from credentials.apps.records.tests.utils import dump_random_state
from credentials.apps.records.utils import (
Expand Down Expand Up @@ -75,6 +77,21 @@ def test_send_updated_email_when_program_finished(self):
self.assertIn(expected_record_link, email.body)
self.assertIn(expected_csv_link, email.body)

def test_skip_if_user_has_no_program_certificate(self):
"""Verify that if the user has no program certificate, we do nothing."""
# Mock sending an email to the partner
UserCreditPathwayFactory(user=self.user, pathway=self.pathway, status=UserCreditPathwayStatus.SENT)
self.assertEqual(0, len(mail.outbox))

# remover the fixture ProgramCertRecord
ProgramCertRecord.objects.get(program=self.program, user=self.user).delete()

with self.assertLogs(level=INFO):
send_updated_emails_for_program(self.request, self.USERNAME, self.pc)

# Check no other email was sent
self.assertEqual(0, len(mail.outbox))

def test_no_previous_email_sent(self):
"""
Test that no additional email is sent if the user hasn't previously sent one
Expand Down
2 changes: 1 addition & 1 deletion credentials/apps/records/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def send_updated_emails_for_program(request, username, program_certificate):
try:
pcr = ProgramCertRecord.objects.get(program=program, user=user)
except ProgramCertRecord.DoesNotExist:
logger.exception("Program Cert Record for user_uuid %s, program_uuid %s does not exist", user.id, program.uuid)
logger.info("Program Cert Record for user_uuid %s, program_uuid %s does not exist", user.id, program.uuid)
return

# Send emails for those already marked as "SENT"
Expand Down

0 comments on commit 57732b1

Please sign in to comment.