From 2d875546fe8a8cba1e03adf0d1a785b0eb3647e5 Mon Sep 17 00:00:00 2001 From: Alie Langston Date: Tue, 16 Nov 2021 10:00:46 -0500 Subject: [PATCH] feat: cut over to new name affirmation tasks --- CHANGELOG.rst | 4 ++ edx_name_affirmation/__init__.py | 2 +- edx_name_affirmation/handlers.py | 11 ++--- edx_name_affirmation/tests/test_handlers.py | 53 ++++++++++++--------- edx_name_affirmation/tests/test_tasks.py | 13 ++--- 5 files changed, 45 insertions(+), 38 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index ed1a130..fd8fcdb 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -14,6 +14,10 @@ Change Log Unreleased ~~~~~~~~~~ +[2.0.2] - 2021-11-16 +~~~~~~~~~~~~~~~~~~~~ +* Cut over to new celery tasks for IDV and proctoring handlers. + [2.0.1] - 2021-11-15 ~~~~~~~~~~~~~~~~~~~~ * If we receive a non-relevant status for either IDV or proctoring, do not diff --git a/edx_name_affirmation/__init__.py b/edx_name_affirmation/__init__.py index f682cf3..e31ee92 100644 --- a/edx_name_affirmation/__init__.py +++ b/edx_name_affirmation/__init__.py @@ -2,6 +2,6 @@ Django app housing name affirmation logic. """ -__version__ = '2.0.1' +__version__ = '2.0.2' default_app_config = 'edx_name_affirmation.apps.EdxNameAffirmationConfig' # pylint: disable=invalid-name diff --git a/edx_name_affirmation/handlers.py b/edx_name_affirmation/handlers.py index 2c9c949..0163793 100644 --- a/edx_name_affirmation/handlers.py +++ b/edx_name_affirmation/handlers.py @@ -11,7 +11,7 @@ from edx_name_affirmation.models import VerifiedName from edx_name_affirmation.signals import VERIFIED_NAME_APPROVED from edx_name_affirmation.statuses import VerifiedNameStatus -from edx_name_affirmation.tasks import idv_update_verified_name, proctoring_update_verified_name +from edx_name_affirmation.tasks import idv_update_verified_name_task, proctoring_update_verified_name_task User = get_user_model() @@ -54,7 +54,7 @@ def idv_attempt_handler(attempt_id, user_id, status, photo_id_name, full_name, * 'status': status } ) - idv_update_verified_name.delay(attempt_id, user_id, status, photo_id_name, full_name) + idv_update_verified_name_task.delay(attempt_id, user_id, trigger_status, photo_id_name, full_name) else: log.info('VerifiedName: idv_attempt_handler will not trigger Celery task for user %(user_id)s ' 'with photo_id_name %(photo_id_name)s because of status %(status)s', @@ -103,15 +103,12 @@ def proctoring_attempt_handler( # only trigger celery task if status is relevant to name affirmation if trigger_status: - proctoring_update_verified_name.delay( + proctoring_update_verified_name_task.delay( attempt_id, user_id, - status, + trigger_status, full_name, profile_name, - is_practice_exam, - is_proctored, - backend_supports_onboarding ) else: log.info('VerifiedName: proctoring_attempt_handler will not trigger Celery task for user %(user_id)s ' diff --git a/edx_name_affirmation/tests/test_handlers.py b/edx_name_affirmation/tests/test_handlers.py index 235ded9..1c1d823 100644 --- a/edx_name_affirmation/tests/test_handlers.py +++ b/edx_name_affirmation/tests/test_handlers.py @@ -201,7 +201,7 @@ def test_idv_update_one_verified_name(self, idv_status, expected_status): 'ready', 'must_retry', ) - @patch('edx_name_affirmation.tasks.idv_update_verified_name.delay') + @patch('edx_name_affirmation.tasks.idv_update_verified_name_task.delay') def test_idv_non_trigger_status(self, status, mock_task): """ Test that a celery task is not triggered if a non-relevant status is received @@ -280,39 +280,48 @@ def test_proctoring_create_verified_name(self): verified_name = verified_name_query.first() self.assertEqual(verified_name.status, VerifiedNameStatus.PENDING) + def test_proctoring_does_not_create_name(self): + """ + Test that if we receive a signal for an attempt id that we do not have a name for, we do not create a new + record. + """ + + proctoring_attempt_handler( + self.proctoring_attempt_id, + self.user.id, + 'created', + None, + None, + True, + True, + True + ) + + self.assertEqual(len(VerifiedName.objects.filter()), 0) + @ddt.data( - (None, None, True, True, True), - ('John', 'John', False, False, False), - ('John', 'John', False, True, True), - ('John', 'John', True, True, False) + (False, False, False), + (False, True, True), + (True, True, False) ) @ddt.unpack - def test_proctoring_does_not_create_name( - self, - verified_name, - profile_name, - is_practice, - is_proctored, - backend_supports_onboarding - ): + @patch('edx_name_affirmation.tasks.proctoring_update_verified_name_task.delay') + def test_proctoring_does_not_trigger_celery_task(self, is_practice, is_proctored, supports_onboarding, mock_task): """ - Test that if we receive a signal for an attempt id that we do not yet have a verified name for, - we do not create a verified name under certain conditions. + Test that a celery task is not triggered if the exam does not contain an id verification event """ - - # test for signal that does not contain verified or profile name proctoring_attempt_handler( self.proctoring_attempt_id, self.user.id, 'created', - verified_name, - profile_name, + 'John', + 'John', is_practice, is_proctored, - backend_supports_onboarding + supports_onboarding ) - self.assertEqual(len(VerifiedName.objects.filter()), 0) + mock_task.assert_not_called() @ddt.data( True, @@ -366,7 +375,7 @@ def test_proctoring_log_with_existing_approved_verified_name(self, should_names_ 'ready_to_submit', 'error', ) - @patch('edx_name_affirmation.tasks.proctoring_update_verified_name.delay') + @patch('edx_name_affirmation.tasks.proctoring_update_verified_name_task.delay') def test_proctoring_non_trigger_status(self, status, mock_task): """ Test that a celery task is not triggered if a non-relevant status is received diff --git a/edx_name_affirmation/tests/test_tasks.py b/edx_name_affirmation/tests/test_tasks.py index 89a9dcf..3b2ea13 100644 --- a/edx_name_affirmation/tests/test_tasks.py +++ b/edx_name_affirmation/tests/test_tasks.py @@ -9,7 +9,7 @@ from edx_name_affirmation.models import VerifiedName from edx_name_affirmation.statuses import VerifiedNameStatus -from edx_name_affirmation.tasks import idv_update_verified_name, proctoring_update_verified_name +from edx_name_affirmation.tasks import idv_update_verified_name_task, proctoring_update_verified_name_task User = get_user_model() @@ -28,9 +28,9 @@ def setUp(self): # pylint: disable=super-method-not-called self.idv_attempt_id = 1111111 self.proctoring_attempt_id = 2222222 - @patch('edx_name_affirmation.tasks.idv_update_verified_name.retry') + @patch('edx_name_affirmation.tasks.idv_update_verified_name_task.retry') def test_idv_retry(self, mock_retry): - idv_update_verified_name.delay( + idv_update_verified_name_task.delay( self.idv_attempt_id, # force an error with an invalid user ID 99999, @@ -40,17 +40,14 @@ def test_idv_retry(self, mock_retry): ) mock_retry.assert_called() - @patch('edx_name_affirmation.tasks.proctoring_update_verified_name.retry') + @patch('edx_name_affirmation.tasks.proctoring_update_verified_name_task.retry') def test_proctoring_retry(self, mock_retry): - proctoring_update_verified_name.delay( + proctoring_update_verified_name_task.delay( self.proctoring_attempt_id, # force an error with an invalid user ID 99999, VerifiedNameStatus.PENDING, self.verified_name_obj.verified_name, self.verified_name_obj.profile_name, - True, - True, - True, ) mock_retry.assert_called()