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


Python Feedback.process_request方法代码示例

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


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

示例1: FeedbackTest

# 需要导入模块: from feedback import Feedback [as 别名]
# 或者: from feedback.Feedback import process_request [as 别名]
class FeedbackTest(unittest.TestCase):

    def setUp(self):
        self.fb = Feedback()

    def test_process_request__empty(self):
        """with an empty request"""
        data = dummy(None, None, None)
        data.form = {}
        result = self.fb.process_request(data)
        self.assertTrue(isinstance(result, dict))
        self.assertTrue('status' in result)
        self.assertEqual(result['status'], 'Error')
        self.assertTrue('data' in result)
        self.assertTrue(result['data'], 'No email was sent.')

    def test_process_request__incomplete(self):
        """with incomplete data"""
        result = self.fb.process_request(dummy(name=None))
        self.assertTrue(isinstance(result, dict))
        self.assertTrue('status' in result)
        self.assertEqual(result['status'], 'Error')
        self.assertTrue('data' in result)
        self.assertTrue(result['data'], 'No email was sent.')
        self.assertTrue('errors' in result)
        self.assertTrue('Not all required fields were found.' in result['errors'])

    def test_process_request__bademail(self):
        """with bad email address"""
        result = self.fb.process_request(dummy(email='[email protected]'))
        self.assertTrue(isinstance(result, dict))
        self.assertTrue('status' in result)
        self.assertEqual(result['status'], 'Error')
        self.assertTrue('data' in result)
        self.assertTrue(result['data'], 'No email was sent.')
        self.assertTrue('errors' in result)
        self.assertTrue('|[email protected]| is not a valid email address.' in result['errors'])

    @patch('feedback.Feedback._send_feedback')
    def test_process_request__valid(self, mock_send_feedback):
        """all data is correct"""

        def update_self():
            self.fb.status = 'OK'
            self.fb.data = 'Email was successfully sent.'

        mock_send_feedback.side_effect = update_self
        result = self.fb.process_request(dummy())
        self.assertTrue(isinstance(result, dict))
        self.assertTrue('status' in result)
        self.assertEqual(result['status'], 'OK')
        self.assertTrue('data' in result)
        self.assertTrue(result['data'], 'Email was successfully sent.')

    def test_send_feedback__nomail(self):
        """mail attr is None"""
        self.fb.mail = None
        result = self.fb._send_feedback()
        self.assertFalse(result)
        self.assertTrue(hasattr(self.fb, 'errors'))
        self.assertTrue('Mail object was not found. Cannot send mails out.' in getattr(self.fb, 'errors'))

    def test_send_feedback__witherrors(self):
        """ with some pre-existent errors"""
        self.fb.mail = 'dup'
        self.fb.errors.append('An error.')
        result = self.fb._send_feedback()
        self.assertFalse(result)
        self.assertTrue(hasattr(self.fb, 'errors'))
        self.assertTrue('An error.' in getattr(self.fb, 'errors'))

    def test_send_feedback__normal(self):
        """normal execution"""
        mail = dummy()
        mail.send = lambda x: 1
        self.fb.mail = mail
        self.fb.request = {
            'name': mail.form['name'],
            'email': mail.form['email'],
            'feedback': mail.form['feedback'],
        }
        result = self.fb._send_feedback()
        self.assertFalse(result)
        self.assertTrue(hasattr(self.fb, 'status'))
        self.assertTrue('OK' in getattr(self.fb, 'status'))
        self.assertTrue(hasattr(self.fb, 'data'))
        self.assertTrue('Email was successfully sent.' in getattr(self.fb, 'data'))

    def test_send_feedback__smtperror(self):
        """SMTP error"""

        def raise_error(self):
            raise socket.error

        mock = MagicMock()
        mock.send.side_effect = raise_error
        self.fb.mail = mock
        self.fb.request = {
            'name': 'Name',
            'email': '[email protected]',
#.........这里部分代码省略.........
开发者ID:fna,项目名称:oah-backend,代码行数:103,代码来源:test_feedback.py

示例2: feedback

# 需要导入模块: from feedback import Feedback [as 别名]
# 或者: from feedback.Feedback import process_request [as 别名]
def feedback():
    fb = Feedback(mail=mail)
    resp = make_response(jsonify(**fb.process_request(request)))
    resp.headers["Access-Control-Allow-Origin"] = "*"
    return resp
开发者ID:khandelwal,项目名称:oah-backend,代码行数:7,代码来源:app.py


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