def test_get_by_token_not_found(test_pending_action_category):
     with pytest.raises(APIBaseException) as exec_info:
         PendingActionSelector.get_by_token(
             'anything',
             test_pending_action_category,
         )
     assert exec_info.value.detail.code == AccountsErrorCodes.INVALID_TOKEN.code
예제 #2
0
 def test_get_by_token_not_found(test_pending_action_category):
     with pytest.raises(SimpleValidationError) as exec_info:
         PendingActionSelector.get_by_token(
             'anything',
             test_pending_action_category,
         )
     assert exec_info.value.detail.code == INVALID_TOKEN['code']
 def test_get_by_token(test_pending_action_category):
     pending_action = PendingActionFactory(
         category=test_pending_action_category)
     selected_pending_action = PendingActionSelector.get_by_token(
         pending_action.token,
         test_pending_action_category,
     )
     assert selected_pending_action is not None
     assert selected_pending_action == pending_action
예제 #4
0
    def email_confirmation(self, request):
        """Confirms an email."""
        serializer = TokenSerializer(data=request.data)
        serializer.is_valid(raise_exception=True)

        pending_action = PendingActionSelector.get_by_token(
            token=serializer.validated_data['token'],
            category=ActionCategory.CONFIRM_EMAIL.value,
        )
        AuthService.confirm_email(pending_action)

        return Response(AccountsResponses.EMAIL_VERIFIED)
예제 #5
0
    def reset_password_confirm(self, request):
        """Confirms a password reset."""
        serializer = PasswordResetConfirmSerializer(data=request.data)
        serializer.is_valid(raise_exception=True)

        plain_password = serializer.validated_data['password']
        action_token = serializer.validated_data['token']

        pending_action = PendingActionSelector.get_by_token(
            action_token,
            category=ActionCategory.RESET_PASSWORD.value,
        )
        PasswordService.confirm_reset_password(pending_action, plain_password)

        return Response(AccountsResponses.PASSWORD_UPDATED)