def test_send_beta_feedback_email_send_mail(self, mock_get_active_app, mock_json_response, mock_send_mail): mock_request = mock.MagicMock() mock_post = mock.MagicMock() mock_app = mock.MagicMock() mock_app.feedback_emails = '*****@*****.**' mock_app.name = 'foo_name' mock_request.POST = mock_post mock_post.get.side_effect = [ 'http://foo/beta', 'foo_betaUser', 'foo_betaSubmitLocalTime', 'foo_betaSubmitUTCOffset', 'foo_betaFormUrl', 'foo_betaFormUserAgent', 'foo_betaFormVendor', 'foo_betaUserComments' ] mock_get_active_app.return_value = mock_app mock_json_response.return_value = True mock_send_mail.return_value = True ret = send_beta_feedback_email(mock_request) self.assertTrue(ret) mock_post.get.assert_any_call('betaFormUrl') mock_get_active_app.assert_called_once_with(url='http://foo/beta') mock_post.get.assert_any_call('betaUser') mock_post.get.assert_any_call('betaSubmitLocalTime') mock_post.get.assert_any_call('betaSubmitUTCOffset') mock_post.get.assert_any_call('betaFormUrl') mock_post.get.assert_any_call('betaFormUserAgent') mock_post.get.assert_any_call('betaFormVendor') mock_post.get.assert_called_with('betaUserComments') expected_subject = 'User Feedback for {0}'.format( mock_app.name.encode('utf-8')) expected_message = 'User: {0}\n'\ 'User Local Time: {1}\n'\ 'UTC Offset in Hours: {2}\n'\ 'App URL: {3}\n'\ 'User Agent: {4}\n'\ 'Vendor: {5}\n'\ 'Comments:\n' \ '{6}'.\ format('foo_betaUser', 'foo_betaSubmitLocalTime', 'foo_betaSubmitUTCOffset', 'foo_betaFormUrl', 'foo_betaFormUserAgent', 'foo_betaFormVendor', 'foo_betaUserComments' ) mock_send_mail.assert_called_once_with( expected_subject, expected_message, from_email=None, recipient_list=mock_app.feedback_emails) mock_json_response.assert_called_once_with({ 'success': True, 'result': 'Emails sent to specified developers' })
def test_send_beta_feedback_email_app_none(self, mock_get_active_app, mock_json_response): mock_request = mock.MagicMock() mock_post = mock.MagicMock() mock_request.POST = mock_post mock_post.get.return_value = 'http://foo/beta' mock_get_active_app.return_value = None mock_json_response.return_value = True ret = send_beta_feedback_email(mock_request) self.assertTrue(ret) mock_post.get.assert_called_once_with('betaFormUrl') mock_get_active_app.assert_called_once_with(url='http://foo/beta') mock_json_response.assert_called_once_with({ 'success': False, 'error': 'App not found or feedback_emails not defined in app.py' })