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


Python ApiAccessRequest.deny方法代码示例

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


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

示例1: ApiAccessRequestSignalTests

# 需要导入模块: from openedx.core.djangoapps.api_admin.models import ApiAccessRequest [as 别名]
# 或者: from openedx.core.djangoapps.api_admin.models.ApiAccessRequest import deny [as 别名]
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,代码行数:67,代码来源:test_models.py


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