Skip to content

Commit

Permalink
feat: replace cdd task in order to use the v2 version (#220)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrey-canon authored Oct 2, 2024
1 parent 25fd850 commit 0cf0bc7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
22 changes: 11 additions & 11 deletions eox_nelp/user_profile/api/v1/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ def tearDown(self): # pylint: disable=invalid-name

@override_settings(
ENABLE_OTP_VALIDATION=False,
PEARSON_RTI_ACTIVATE_COMPLETION_GATE=True,
USE_PEARSON_ENGINE_SERVICE=True,
)
@patch("eox_nelp.user_profile.api.v1.views.cdd_task")
@patch("eox_nelp.user_profile.api.v1.views.real_time_import_task_v2")
def test_update_fields_successfully(self, cdd_task_mock):
"""
Test that the request completes its execution successfully.
Expand All @@ -52,10 +52,10 @@ def test_update_fields_successfully(self, cdd_task_mock):
self.assertDictEqual(response.json(), {"message": "User's fields has been updated successfully"})
self.assertEqual(response.status_code, status.HTTP_200_OK)
accounts.api.update_account_settings.assert_called_once_with(self.user, payload)
cdd_task_mock.delay.assert_called_with(user_id=self.user.id)
cdd_task_mock.delay.assert_called_with(user_id=self.user.id, action_name="cdd")

@override_settings(ENABLE_OTP_VALIDATION=False)
@patch("eox_nelp.user_profile.api.v1.views.cdd_task")
@patch("eox_nelp.user_profile.api.v1.views.real_time_import_task_v2")
def test_account_validation_error(self, cdd_task_mock):
"""
Test that a bad request is returned when an AccountValidationError is raised.
Expand All @@ -80,7 +80,7 @@ def test_account_validation_error(self, cdd_task_mock):
cdd_task_mock.delay.assert_not_called()

@override_settings(ENABLE_OTP_VALIDATION=False)
@patch("eox_nelp.user_profile.api.v1.views.cdd_task")
@patch("eox_nelp.user_profile.api.v1.views.real_time_import_task_v2")
def test_account_update_error(self, cdd_task_mock):
"""
Test that a bad request is returned when an AccountUpdateError is raised.
Expand Down Expand Up @@ -111,9 +111,9 @@ def test_account_update_error(self, cdd_task_mock):
@override_settings(
ENABLE_OTP_VALIDATION=False,
EXTRA_ACCOUNT_USER_FIELDS=["first_name", "last_name"],
PEARSON_RTI_ACTIVATE_GRADED_GATE=True,
USE_PEARSON_ENGINE_SERVICE=True,
)
@patch("eox_nelp.user_profile.api.v1.views.cdd_task")
@patch("eox_nelp.user_profile.api.v1.views.real_time_import_task_v2")
def test_account_update_extra_fields(self, cdd_task_mock):
"""
Test that extra account user fields has been set.
Expand All @@ -140,14 +140,14 @@ def test_account_update_extra_fields(self, cdd_task_mock):
accounts.api.update_account_settings.assert_called_once_with(self.user, payload)
self.assertEqual(self.user.first_name, payload["first_name"])
self.assertEqual(self.user.last_name, payload["last_name"])
cdd_task_mock.delay.assert_called_with(user_id=self.user.id)
cdd_task_mock.delay.assert_called_with(user_id=self.user.id, action_name="cdd")

@override_settings(
ENABLE_OTP_VALIDATION=False,
USER_PROFILE_API_EXTRA_INFO_FIELDS=["arabic_first_name", "arabic_last_name"],
PEARSON_RTI_ACTIVATE_GRADED_GATE=True,
USE_PEARSON_ENGINE_SERVICE=True,
)
@patch("eox_nelp.user_profile.api.v1.views.cdd_task")
@patch("eox_nelp.user_profile.api.v1.views.real_time_import_task_v2")
def test_update_extra_info_fields(self, cdd_task_mock):
"""
Test that extra account user fields has been set.
Expand All @@ -173,4 +173,4 @@ def test_update_extra_info_fields(self, cdd_task_mock):
accounts.api.update_account_settings.assert_called_once_with(self.user, payload)
self.assertEqual(self.user.extrainfo.arabic_first_name, payload["arabic_first_name"])
self.assertEqual(self.user.extrainfo.arabic_last_name, payload["arabic_last_name"])
cdd_task_mock.delay.assert_called_with(user_id=self.user.id)
cdd_task_mock.delay.assert_called_with(user_id=self.user.id, action_name="cdd")
11 changes: 7 additions & 4 deletions eox_nelp/user_profile/api/v1/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

from eox_nelp.edxapp_wrapper.user_api import accounts, errors
from eox_nelp.one_time_password.view_decorators import validate_otp
from eox_nelp.pearson_vue.tasks import cdd_task
from eox_nelp.pearson_vue.tasks import real_time_import_task_v2
from eox_nelp.utils import save_extrainfo_field

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -83,9 +83,12 @@ def update_user_data(request):
status=status.HTTP_400_BAD_REQUEST
)
if (
getattr(settings, "PEARSON_RTI_ACTIVATE_COMPLETION_GATE", False)
or getattr(settings, "PEARSON_RTI_ACTIVATE_GRADED_GATE", False)
getattr(settings, "USE_PEARSON_ENGINE_SERVICE", False)
and getattr(settings, "PEARSON_ENGINE_UPDATE_USER_PROFILE_ENABLED", True)
):
cdd_task.delay(user_id=request.user.id) # Send cdd request with user updated.
real_time_import_task_v2.delay(
user_id=request.user.id,
action_name="cdd",
)

return Response({"message": "User's fields has been updated successfully"}, status=status.HTTP_200_OK)

0 comments on commit 0cf0bc7

Please sign in to comment.