当前位置: 首页>>代码示例>>Python>>正文


Python models.ApiAccessRequest类代码示例

本文整理汇总了Python中openedx.core.djangoapps.api_admin.models.ApiAccessRequest的典型用法代码示例。如果您正苦于以下问题:Python ApiAccessRequest类的具体用法?Python ApiAccessRequest怎么用?Python ApiAccessRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ApiAccessRequest类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get

 def get(self, request):
     """
     If the requesting user has already requested API access, redirect
     them to the client creation page.
     """
     if ApiAccessRequest.api_access_status(request.user) is not None:
         return redirect(reverse('api_admin:api-status'))
     return super(ApiRequestView, self).get(request)
开发者ID:AndreySonetico,项目名称:edx-platform,代码行数:8,代码来源:views.py

示例2: post

    def post(self, request):
        """
        POST /api/user/v1/accounts/retire_misc/

        {
            'username': 'user_to_retire'
        }

        Retires the user with the given username in the LMS.
        """

        username = request.data['username']

        try:
            retirement = UserRetirementStatus.get_retirement_for_retirement_action(username)
            RevisionPluginRevision.retire_user(retirement.user)
            ArticleRevision.retire_user(retirement.user)
            PendingNameChange.delete_by_user_value(retirement.user, field='user')
            PasswordHistory.retire_user(retirement.user.id)
            course_enrollments = CourseEnrollment.objects.filter(user=retirement.user)
            ManualEnrollmentAudit.retire_manual_enrollments(course_enrollments, retirement.retired_email)

            CreditRequest.retire_user(retirement.original_username, retirement.retired_username)
            ApiAccessRequest.retire_user(retirement.user)
            CreditRequirementStatus.retire_user(retirement.user.username)

            # This signal allows code in higher points of LMS to retire the user as necessary
            USER_RETIRE_LMS_MISC.send(sender=self.__class__, user=retirement.user)

            # This signal allows code in higher points of LMS to unsubscribe the user
            # from various types of mailings.
            USER_RETIRE_MAILINGS.send(
                sender=self.__class__,
                email=retirement.original_email,
                new_email=retirement.retired_email,
                user=retirement.user
            )
        except UserRetirementStatus.DoesNotExist:
            return Response(status=status.HTTP_404_NOT_FOUND)
        except RetirementStateError as exc:
            return Response(text_type(exc), status=status.HTTP_400_BAD_REQUEST)
        except Exception as exc:  # pylint: disable=broad-except
            return Response(text_type(exc), status=status.HTTP_500_INTERNAL_SERVER_ERROR)

        return Response(status=status.HTTP_204_NO_CONTENT)
开发者ID:mreyk,项目名称:edx-platform,代码行数:45,代码来源:views.py

示例3: get

 def get(self, request):
     """
     If the user has not created an API request, redirect them to the
     request form. Otherwise, display the status of their API request.
     """
     status = ApiAccessRequest.api_access_status(request.user)
     if status is None:
         return redirect(reverse('api_admin:api-request'))
     return render_to_response('api_admin/status.html', {
         'status': status,
         'api_support_link': _('TODO'),
         'api_support_email': settings.API_ACCESS_MANAGER_EMAIL,
     })
开发者ID:Akif-Vohra,项目名称:edx-platform,代码行数:13,代码来源:views.py

示例4: wrapped_view

 def wrapped_view(view_obj, *args, **kwargs):
     """Wrapper for the view function."""
     if ApiAccessRequest.has_api_access(args[0].user):
         return view_func(view_obj, *args, **kwargs)
     return redirect(reverse('api_admin:api-request'))
开发者ID:Lektorium-LLC,项目名称:edx-platform,代码行数:5,代码来源:decorators.py

示例5: setUp

 def setUp(self):
     super(ApiAccessRequestSignalTests, self).setUp()
     self.user = UserFactory()
     self.api_access_request = ApiAccessRequest(user=self.user, site=SiteFactory())
     self.send_new_pending_email_function = 'openedx.core.djangoapps.api_admin.models._send_new_pending_email'
     self.send_decision_email_function = 'openedx.core.djangoapps.api_admin.models._send_decision_email'
开发者ID:Lektorium-LLC,项目名称:edx-platform,代码行数:6,代码来源:test_models.py

示例6: ApiAccessRequestSignalTests

class ApiAccessRequestSignalTests(TestCase):
    def setUp(self):
        super(ApiAccessRequestSignalTests, self).setUp()
        self.user = UserFactory()
        self.api_access_request = ApiAccessRequest(user=self.user, site=SiteFactory())
        self.send_new_pending_email_function = 'openedx.core.djangoapps.api_admin.models._send_new_pending_email'
        self.send_decision_email_function = 'openedx.core.djangoapps.api_admin.models._send_decision_email'

    def test_save_signal_success_new_email(self):
        """ Verify that initial save sends new email and no decision email. """
        with mock.patch(self.send_new_pending_email_function) as mock_new_email:
            with mock.patch(self.send_decision_email_function) as mock_decision_email:
                self.api_access_request.save()

        mock_new_email.assert_called_once_with(self.api_access_request)
        self.assertFalse(mock_decision_email.called)

    def test_save_signal_success_decision_email(self):
        """ Verify that updating request status sends decision email and no new email. """
        self.api_access_request.save()

        with mock.patch(self.send_new_pending_email_function) as mock_new_email:
            with mock.patch(self.send_decision_email_function) as mock_decision_email:
                self.api_access_request.approve()

        mock_decision_email.assert_called_once_with(self.api_access_request)
        self.assertFalse(mock_new_email.called)

    def test_save_signal_success_no_emails(self):
        """ Verify that updating request status again sends no emails. """
        self.api_access_request.save()
        self.api_access_request.approve()

        with mock.patch(self.send_new_pending_email_function) as mock_new_email:
            with mock.patch(self.send_decision_email_function) as mock_decision_email:
                self.api_access_request.deny()

        self.assertFalse(mock_decision_email.called)
        self.assertFalse(mock_new_email.called)

    def test_save_signal_failure_email(self):
        """ Verify that saving still functions even on email errors. """
        self.assertIsNone(self.api_access_request.id)

        mail_function = 'openedx.core.djangoapps.api_admin.models.send_mail'
        with mock.patch(mail_function, side_effect=SMTPException):
            with mock.patch.object(model_log, 'exception') as mock_model_log_exception:
                self.api_access_request.save()

        # Verify that initial save logs email errors properly
        mock_model_log_exception.assert_called_once_with(
            'Error sending API user notification email for request [%s].', self.api_access_request.id
        )
        # Verify object saved
        self.assertIsNotNone(self.api_access_request.id)

        with mock.patch(mail_function, side_effect=SMTPException):
            with mock.patch.object(model_log, 'exception') as mock_model_log_exception:
                self.api_access_request.approve()
        # Verify that updating request status logs email errors properly
        mock_model_log_exception.assert_called_once_with(
            'Error sending API user notification email for request [%s].', self.api_access_request.id
        )
        # Verify object saved
        self.assertEqual(self.api_access_request.status, ApiAccessRequest.APPROVED)
开发者ID:Lektorium-LLC,项目名称:edx-platform,代码行数:65,代码来源:test_models.py

示例7: test_no_access

 def test_no_access(self):
     self.request.delete()  # pylint: disable=no-member
     self.assertIsNone(ApiAccessRequest.api_access_status(self.user))
开发者ID:Lektorium-LLC,项目名称:edx-platform,代码行数:3,代码来源:test_models.py

示例8: test_has_access

 def test_has_access(self, status, should_have_access):
     self.request.status = status
     self.request.save()  # pylint: disable=no-member
     self.assertEqual(ApiAccessRequest.has_api_access(self.user), should_have_access)
开发者ID:Lektorium-LLC,项目名称:edx-platform,代码行数:4,代码来源:test_models.py

示例9: test_nonexistent_request

 def test_nonexistent_request(self):
     """Test that users who have not requested API access do not get it."""
     other_user = UserFactory()
     self.assertFalse(ApiAccessRequest.has_api_access(other_user))
开发者ID:Lektorium-LLC,项目名称:edx-platform,代码行数:4,代码来源:test_models.py

示例10: test_default_status

 def test_default_status(self):
     self.assertEqual(self.request.status, ApiAccessRequest.PENDING)
     self.assertFalse(ApiAccessRequest.has_api_access(self.user))
开发者ID:Lektorium-LLC,项目名称:edx-platform,代码行数:3,代码来源:test_models.py

示例11: test_no_access

 def test_no_access(self):
     self.request.delete()
     self.assertIsNone(ApiAccessRequest.api_access_status(self.user))
开发者ID:digitalsatori,项目名称:edx-platform,代码行数:3,代码来源:test_models.py

示例12: test_has_access

 def test_has_access(self, status, should_have_access):
     self.request.status = status
     self.request.save()
     self.assertEqual(ApiAccessRequest.has_api_access(self.user), should_have_access)
开发者ID:digitalsatori,项目名称:edx-platform,代码行数:4,代码来源:test_models.py


注:本文中的openedx.core.djangoapps.api_admin.models.ApiAccessRequest类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。