Skip to content

Commit

Permalink
Merge pull request #68 from edx/alangsto/cut_to_new_tasks
Browse files Browse the repository at this point in the history
feat: cut over to new name affirmation tasks
  • Loading branch information
alangsto authored Nov 17, 2021
2 parents b45a424 + 2d87554 commit 16f2197
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 38 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion edx_name_affirmation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 4 additions & 7 deletions edx_name_affirmation/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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 '
Expand Down
53 changes: 31 additions & 22 deletions edx_name_affirmation/tests/test_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
13 changes: 5 additions & 8 deletions edx_name_affirmation/tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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,
Expand All @@ -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()

0 comments on commit 16f2197

Please sign in to comment.