本文整理汇总了Python中feedback.Feedback._send_feedback方法的典型用法代码示例。如果您正苦于以下问题:Python Feedback._send_feedback方法的具体用法?Python Feedback._send_feedback怎么用?Python Feedback._send_feedback使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类feedback.Feedback
的用法示例。
在下文中一共展示了Feedback._send_feedback方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: FeedbackTest
# 需要导入模块: from feedback import Feedback [as 别名]
# 或者: from feedback.Feedback import _send_feedback [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]',
#.........这里部分代码省略.........