def testSendAmpEmail(self): """Test basic logging with minimal fields, with text, HTML, and AMP HTML.""" mail_service = mail_stub.MailServiceStub() results = [] message = self.CreateRequest(sender='*****@*****.**', to=['*****@*****.**'], subject='a subject', body='a body', html='<html>', amp_html='<html ⚡4email></html>') mail_service._Send(message.ToProto(), None, results.append, self.smtp, self.popen) self.assertListEqual([ 'MailService.Send\n' ' From: [email protected]\n' ' To: [email protected]\n' ' Subject: a subject\n' ' Body:\n' ' Content-type: text/plain\n' ' Data length: %d\n' % len(u'a body') + ' Body:\n' ' Content-type: text/x-amp-html\n' ' Data length: %d\n' % len(u'<html ⚡4email></html>') + ' Body:\n' ' Content-type: text/html\n' ' Data length: %d' % len(u'<html>') ], results)
def testGetSentMessagesFilteredByHtmlField(self): mail_service = mail_stub.MailServiceStub() message = self.CreateRequest(sender='*****@*****.**', to=['*****@*****.**'], subject='a subject', body='a body', html='<html>Hi!</html>') mail_service._CacheMessage(message) self.assertLen(mail_service.get_sent_messages(), 1) filtered_messages = mail_service.get_sent_messages(html='Hi') self.assertLen(filtered_messages, 1) self.CompareMessages(message, filtered_messages[0]) missing_messages = mail_service.get_sent_messages(html='nothing') self.assertFalse(missing_messages) mail_service._CacheMessage(message) filtered_messages = mail_service.get_sent_messages(html='Hi') self.assertLen(filtered_messages, 2) non_html_message = self.CreateRequest(sender='*****@*****.**', to=['*****@*****.**'], subject='a subject', body='a body') mail_service._CacheMessage(non_html_message) filtered_messages = mail_service.get_sent_messages(html='Hi!') self.assertLen(filtered_messages, 2) self.CompareMessages(message, filtered_messages[0]) self.CompareMessages(message, filtered_messages[1])
def testDynamicGetSentMessages(self): """Tests that a call to _Dynamic_GetSentMessages returns all messages.""" mail_service = mail_stub.MailServiceStub() message1 = self.CreateRequest(sender='*****@*****.**', to=['*****@*****.**'], subject='a subject', body='a body', html='<html>') mail_service._CacheMessage(message1) message2 = self.CreateRequest(sender='*****@*****.**', to=['*****@*****.**'], subject='peekaboo', body='boomeroo', html='<html></html>') mail_service._CacheMessage(message2) request = api_base_pb2.VoidProto() response = mail_stub_service_pb2.GetSentMessagesResponse() mail_service._Dynamic_GetSentMessages(request, response) retrieved_messages = list( map(_EmailMessageFromProto, response.sent_message)) self.assertLen(retrieved_messages, 2) self.CompareMessages(message1, retrieved_messages[0]) self.CompareMessages(message2, retrieved_messages[1])
def testGetSentMessagesFilteredByToFieldList(self): mail_service = mail_stub.MailServiceStub() message = self.CreateRequest( sender='*****@*****.**', to=['*****@*****.**', 'anotherto@nowhere,com'], subject='a subject', body='a body', html='<html>') mail_service._CacheMessage(message) filtered_messages = mail_service.get_sent_messages(to='*****@*****.**') self.assertLen(filtered_messages, 1) self.CompareMessages(message, filtered_messages[0]) filtered_messages = mail_service.get_sent_messages( to='*****@*****.**') self.assertLen(filtered_messages, 1) self.CompareMessages(message, filtered_messages[0]) missing_messages = mail_service.get_sent_messages( to='*****@*****.**') self.assertFalse(missing_messages) mail_service._CacheMessage(message) filtered_messages = mail_service.get_sent_messages(to='*****@*****.**') self.assertLen(filtered_messages, 2) filtered_messages = mail_service.get_sent_messages( to='*****@*****.**') self.assertLen(filtered_messages, 2)
def setup_gae_services(): """Setups all google app engine services required for testing.""" from google.appengine.api import apiproxy_stub_map from google.appengine.api import mail_stub from google.appengine.api import user_service_stub from google.appengine.api import urlfetch_stub from google.appengine.api.capabilities import capability_stub from google.appengine.api.memcache import memcache_stub from google.appengine.api.taskqueue import taskqueue_stub from google.appengine.api import datastore_file_stub apiproxy_stub_map.apiproxy = apiproxy_stub_map.APIProxyStubMap() apiproxy_stub_map.apiproxy.RegisterStub( 'urlfetch', urlfetch_stub.URLFetchServiceStub()) apiproxy_stub_map.apiproxy.RegisterStub( 'user', user_service_stub.UserServiceStub()) apiproxy_stub_map.apiproxy.RegisterStub( 'memcache', memcache_stub.MemcacheServiceStub()) apiproxy_stub_map.apiproxy.RegisterStub( 'datastore', datastore_file_stub.DatastoreFileStub('test-app-run', None, None)) apiproxy_stub_map.apiproxy.RegisterStub('mail', mail_stub.MailServiceStub()) yaml_location = os.path.join(HERE, 'app') apiproxy_stub_map.apiproxy.RegisterStub( 'taskqueue', taskqueue_stub.TaskQueueServiceStub(root_path=yaml_location)) apiproxy_stub_map.apiproxy.RegisterStub( 'capability_service', capability_stub.CapabilityServiceStub())
def setUp(self): # Ensure we're in UTC. os.environ['TZ'] = 'UTC' time.tzset() # Start with a fresh api proxy. apiproxy_stub_map.apiproxy = apiproxy_stub_map.APIProxyStubMap() # Use a fresh stub datastore. self.__datastore_stub = datastore_file_stub.DatastoreFileStub( APP_ID, '/dev/null', '/dev/null') apiproxy_stub_map.apiproxy.RegisterStub('datastore_v3', self.__datastore_stub) os.environ['APPLICATION_ID'] = APP_ID # Use a fresh stub UserService. apiproxy_stub_map.apiproxy.RegisterStub( 'user', user_service_stub.UserServiceStub()) os.environ['AUTH_DOMAIN'] = AUTH_DOMAIN os.environ['USER_EMAIL'] = LOGGED_IN_USER # Use a fresh urlfetch stub. apiproxy_stub_map.apiproxy.RegisterStub( 'urlfetch', urlfetch_stub.URLFetchServiceStub()) # Use a fresh mail stub. apiproxy_stub_map.apiproxy.RegisterStub('mail', mail_stub.MailServiceStub())
def setUp(self): # Start with a fresh api proxy. apiproxy_stub_map.apiproxy = apiproxy_stub_map.APIProxyStubMap() # Use a fresh stub datastore. stub = datastore_file_stub.DatastoreFileStub(APP_ID, '/dev/null', '/dev/null') apiproxy_stub_map.apiproxy.RegisterStub('datastore_v3', stub) # Use a fresh stub UserService. apiproxy_stub_map.apiproxy.RegisterStub( 'user', user_service_stub.UserServiceStub()) os.environ['AUTH_DOMAIN'] = AUTH_DOMAIN os.environ['USER_EMAIL'] = LOGGED_IN_USER # Use a fresh urlfetch stub. apiproxy_stub_map.apiproxy.RegisterStub( 'urlfetch', urlfetch_stub.URLFetchServiceStub()) # Use a fresh mail stub. apiproxy_stub_map.apiproxy.RegisterStub('mail', mail_stub.MailServiceStub()) # Use a fresh memcache stub apiproxy_stub_map.apiproxy.RegisterStub( 'memcache', memcache_stub.MemcacheServiceStub()) # Create a fake remplate renderer self.render_calls = [] def template_render(filename, params, debug, template_dirs): self.render_calls.append(params) template.render = template_render
def init_env(): os.environ['AUTH_DOMAIN'] = 'gmail.com' os.environ['APPLICATION_ID'] = 'mobicagecloud' os.environ['SERVER_NAME'] = 'localhost' os.environ['SERVER_PORT'] = '8080' os.environ['SERVER_SOFTWARE'] = 'Development Server' os.environ["DEFAULT_VERSION_HOSTNAME"] = 'mobicagecloudhr.appspot.com' os.environ[ 'APPENGINE_RUNTIME'] = 'python27' # Needed to make webapp.template load ._internal.django if not apiproxy_stub_map.apiproxy.GetStub('user'): apiproxy_stub_map.apiproxy.RegisterStub( 'user', user_service_stub.UserServiceStub()) apiproxy_stub_map.apiproxy.RegisterStub( 'datastore_v3', datastore_file_stub.DatastoreFileStub('mobicagecloud', '/dev/null', '/dev/null')) apiproxy_stub_map.apiproxy.RegisterStub('mail', mail_stub.MailServiceStub()) apiproxy_stub_map.apiproxy.RegisterStub( 'blobstore', blobstore_stub.BlobstoreServiceStub( file_blob_storage.FileBlobStorage('/dev/null', 'mobicagecloud'))) apiproxy_stub_map.apiproxy.RegisterStub( 'memcache', memcache_stub.MemcacheServiceStub()) apiproxy_stub_map.apiproxy.RegisterStub( 'images', images_stub.ImagesServiceStub()) apiproxy_stub_map.apiproxy.RegisterStub( 'urlfetch', urlfetch_stub.URLFetchServiceStub()) apiproxy_stub_map.apiproxy.RegisterStub( 'taskqueue', taskqueue_stub.TaskQueueServiceStub())
def testGetSentMessagesFilteredByHtmlFieldMissing(self): mail_service = mail_stub.MailServiceStub() message = self.CreateRequest(sender='*****@*****.**', to=['*****@*****.**'], subject='a subject', body='a body') mail_service._CacheMessage(message) filtered_messages = mail_service.get_sent_messages(html='anything') self.assertFalse(filtered_messages)
def testSendExtensionlessAttachmentFails(self): """Test that a file without an extension fails.""" mail_service = mail_stub.MailServiceStub() message = mail_service_pb2.MailMessage() attachment = message.Attachment.add() attachment.FileName = 'uhoh' attachment.Data = u'uhoh'.encode('utf-8') self.assertRaises(apiproxy_errors.ApplicationError, mail_service._Send, message, None, logging.info, self.smtp, self.popen)
def testSendHiddenFileAttachmentFails(self): """Test that a filename starting with a period fails.""" mail_service = mail_stub.MailServiceStub() message = mail_service_pb2.MailMessage() attachment = message.Attachment.add() attachment.FileName = '.hidden' attachment.Data = u'uhoh'.encode('utf-8') self.assertRaises(apiproxy_errors.ApplicationError, mail_service._Send, message, None, logging.info, self.smtp, self.popen)
def testSendBlacklistedAttachmentFails(self): """Test that a blacklisted extension type fails.""" mail_service = mail_stub.MailServiceStub() message = mail_service_pb2.MailMessage() attachment = message.Attachment.add() attachment.FileName = 'uhoh.exe' attachment.Data = b'uhoh' self.assertRaises(apiproxy_errors.ApplicationError, mail_service._Send, message, None, logging.info, self.smtp, self.popen)
def get_dev_apiproxy(): _apiproxy = apiproxy_stub_map.APIProxyStubMap() _apiproxy.RegisterStub('datastore_v3', datastore_file_stub.DatastoreFileStub(APP_ID, None, None)) _apiproxy.RegisterStub('user', user_service_stub.UserServiceStub()) _apiproxy.RegisterStub('urlfetch', urlfetch_stub.URLFetchServiceStub()) _apiproxy.RegisterStub('mail', mail_stub.MailServiceStub()) _apiproxy.RegisterStub('memcache', memcache_stub.MemcacheServiceStub()) _apiproxy.RegisterStub('taskqueue', taskqueue_stub.TaskQueueServiceStub()) return _apiproxy
def main(): sys.path = extra_paths + sys.path os.environ['SERVER_SOFTWARE'] = 'Development via nose' os.environ['SERVER_NAME'] = 'Foo' os.environ['SERVER_PORT'] = '8080' os.environ['APPLICATION_ID'] = 'test-app-run' os.environ['USER_EMAIL'] = '*****@*****.**' os.environ['CURRENT_VERSION_ID'] = 'testing-version' os.environ['HTTP_HOST'] = 'some.testing.host.tld' import main as app_main from google.appengine.api import apiproxy_stub_map from google.appengine.api import datastore_file_stub from google.appengine.api import mail_stub from google.appengine.api import user_service_stub from google.appengine.api import urlfetch_stub from google.appengine.api.memcache import memcache_stub apiproxy_stub_map.apiproxy = apiproxy_stub_map.APIProxyStubMap() apiproxy_stub_map.apiproxy.RegisterStub( 'urlfetch', urlfetch_stub.URLFetchServiceStub()) apiproxy_stub_map.apiproxy.RegisterStub( 'user', user_service_stub.UserServiceStub()) apiproxy_stub_map.apiproxy.RegisterStub( 'datastore', datastore_file_stub.DatastoreFileStub('test-app-run', None, None)) apiproxy_stub_map.apiproxy.RegisterStub( 'memcache', memcache_stub.MemcacheServiceStub()) apiproxy_stub_map.apiproxy.RegisterStub('mail', mail_stub.MailServiceStub()) import django.test.utils django.test.utils.setup_test_environment() # register a core for the test modules to use from soc.modules import callback from soc.modules import core callback.registerCore(core.Core()) callback.getCore().registerModuleCallbacks() plugins = [AppEngineDatastoreClearPlugin()] if '--coverage' in sys.argv: from nose.plugins import cover plugin = cover.Coverage() plugins.append(plugin) args = [ '--with-coverage', '--cover-package=soc', '--cover-erase', '--cover-html', '--cover-html-dir=coverageResults' ] sys.argv.remove('--coverage') sys.argv += args nose.main(plugins=plugins)
def testGetSentMessagesWithUnicodeInPayload(self): mail_service = mail_stub.MailServiceStub() message = self.CreateRequest(sender='*****@*****.**', to=['*****@*****.**'], subject='a subject', body=u'a body using special chars: éèÉ©', html=u'<html>éèÉ©') mail_service._CacheMessage(message) retrieved_messages = mail_service.get_sent_messages() self.assertLen(retrieved_messages, 1) self.CompareMessages(message, retrieved_messages[0])
def setUp(self): apiproxy_stub_map.apiproxy = apiproxy_stub_map.APIProxyStubMap() apiproxy_stub_map.apiproxy.RegisterStub('urlfetch', urlfetch_stub.URLFetchServiceStub()) apiproxy_stub_map.apiproxy.RegisterStub('mail', mail_stub.MailServiceStub()) apiproxy_stub_map.apiproxy.RegisterStub('memcache', memcache_stub.MemcacheServiceStub()) apiproxy_stub_map.apiproxy.RegisterStub('datastore_v3', datastore_file_stub.DatastoreFileStub(u'myTemporaryDataStorage', '/dev/null', '/dev/null')) apiproxy_stub_map.apiproxy.RegisterStub('user', user_service_stub.UserServiceStub()) os.environ['AUTH_DOMAIN'] = 'gmail.com' os.environ['USER_EMAIL'] = '*****@*****.**' os.environ['SERVER_NAME'] = 'fakeserver.com' os.environ['SERVER_PORT'] = '9999'
def testGetSentMessagesWithSendToAdmin(self): """Test that get_sent_messages() gives back cached messages.""" mail_service = mail_stub.MailServiceStub() message = self.CreateRequest(sender='*****@*****.**', subject='a subject', body='a body', email_type=mail.AdminEmailMessage) self.assertFalse(mail_service.get_sent_messages()) mail_service._CacheMessage(message) retrieved_messages = mail_service.get_sent_messages() self.assertLen(retrieved_messages, 1) self.CompareMessages(message, retrieved_messages[0])
def testDynamicGetAndSetLogMailLevelInt(self): mail_service = mail_stub.MailServiceStub(enable_sendmail=True) request = mail_stub_service_pb2.SetLogMailLevelRequest() request.log_mail_level = '321' mail_service._Dynamic_SetLogMailLevel(request, api_base_pb2.VoidProto()) self.assertEqual(321, mail_service._log_fn.args[0]) response = mail_stub_service_pb2.GetLogMailLevelResponse() mail_service._Dynamic_GetLogMailLevel(api_base_pb2.VoidProto(), response) self.assertEqual(response.log_mail_level, '321')
def testGetSentMessages(self): """Test that get_sent_messages() gives back cached messages.""" mail_service = mail_stub.MailServiceStub() message = self.CreateRequest(sender='*****@*****.**', to=['*****@*****.**'], subject='a subject', body='a body', html='<html>') self.assertFalse(mail_service.get_sent_messages()) mail_service._CacheMessage(message) retrieved_messages = mail_service.get_sent_messages() self.assertLen(retrieved_messages, 1) self.CompareMessages(message, retrieved_messages[0])
def testGetSentMessagesWithUnicodeInHeader(self): mail_service = mail_stub.MailServiceStub() message = self.CreateRequest(sender=u'Áwêsöme <*****@*****.**>', to=[u'Vérÿ Cöôl <*****@*****.**>'], cc=[u'Vérÿ Cöôl <*****@*****.**>'], bcc=[u'Vérÿ Cöôl <*****@*****.**>'], reply_to=u'Áwêsöme <*****@*****.**>', subject=u'â sübje©t', body=u'a body using special chars: éèÉ©', html=u'<html>éèÉ©') mail_service._CacheMessage(message) retrieved_messages = mail_service.get_sent_messages() self.assertLen(retrieved_messages, 1) self.CompareMessages(message, retrieved_messages[0])
def testDynamicGetAndSetLogMailBody(self): mail_service = mail_stub.MailServiceStub(show_mail_body=False) response = mail_stub_service_pb2.GetLogMailBodyResponse() mail_service._Dynamic_GetLogMailBody(api_base_pb2.VoidProto(), response) self.assertEqual(response.log_mail_body, False) request = mail_stub_service_pb2.SetLogMailBodyRequest() request.log_mail_body = True mail_service._Dynamic_SetLogMailBody(request, api_base_pb2.VoidProto()) response = mail_stub_service_pb2.GetLogMailBodyResponse() mail_service._Dynamic_GetLogMailBody(api_base_pb2.VoidProto(), response) self.assertEqual(response.log_mail_body, True)
def testGetSentMessagesFilteredByMultipleFields(self): mail_service = mail_stub.MailServiceStub() message1 = self.CreateRequest(sender='*****@*****.**', to=['*****@*****.**'], subject='Subject 1', body='Hi!') message2 = self.CreateRequest(sender='*****@*****.**', to=['*****@*****.**'], subject='Subject 2', body='Hi again!') message3 = self.CreateRequest(sender='*****@*****.**', to=['*****@*****.**'], subject='Subject 1', body='Hi again!') mail_service._CacheMessage(message1) mail_service._CacheMessage(message2) mail_service._CacheMessage(message3) filtered_messages = mail_service.get_sent_messages() self.assertLen(mail_service.get_sent_messages(), 3) self.CompareMessages(message1, filtered_messages[0]) self.CompareMessages(message2, filtered_messages[1]) self.CompareMessages(message3, filtered_messages[2]) messages_to_nowhere = mail_service.get_sent_messages( to='*****@*****.**') self.assertLen(messages_to_nowhere, 2) messages_subject_1 = mail_service.get_sent_messages( subject='Subject 1') self.assertLen(messages_subject_1, 2) messages_subject_2 = mail_service.get_sent_messages( subject='Subject 2') self.assertLen(messages_subject_2, 1) filtered_messages = mail_service.get_sent_messages(to='*****@*****.**', subject='Subject 1') self.assertLen(filtered_messages, 1) filtered_messages = mail_service.get_sent_messages(to='*****@*****.**', subject='Subject 2') self.assertLen(filtered_messages, 1) filtered_messages = mail_service.get_sent_messages( to='*****@*****.**', subject='Subject 1') self.assertLen(filtered_messages, 1)
def init_mail_stub(self, enable=True, **stub_kw_args): """Enable the mail stub. The email service stub is only available in dev_appserver because it uses the subprocess module. Args: enable: True, if the fake service should be enabled, False if real service should be disabled. stub_kw_args: Keyword arguments passed on to the service stub. """ if not enable: self._disable_stub(MAIL_SERVICE_NAME) return stub = mail_stub.MailServiceStub(**stub_kw_args) self._register_stub(MAIL_SERVICE_NAME, stub)
def setUp(self): self.app = TestApp(application()) apiproxy_stub_map.apiproxy = apiproxy_stub_map.APIProxyStubMap() apiproxy_stub_map.apiproxy.RegisterStub('mail', mail_stub.MailServiceStub()) apiproxy_stub_map.apiproxy.RegisterStub( 'user', user_service_stub.UserServiceStub()) apiproxy_stub_map.apiproxy.RegisterStub( 'urlfetch', urlfetch_stub.URLFetchServiceStub()) apiproxy_stub_map.apiproxy.RegisterStub( 'memcache', memcache_stub.MemcacheServiceStub()) stub = datastore_file_stub.DatastoreFileStub('temp', '/dev/null', '/dev/null') apiproxy_stub_map.apiproxy.RegisterStub('datastore_v3', stub) os.environ['APPLICATION_ID'] = "temp"
def testSendAndGetMessageWithHeaders(self): """Retrieving a sent message with headers should return those headers.""" mail_service = mail_stub.MailServiceStub() message = mail_service_pb2.MailMessage() message.Sender = 'sender' message.To.append('to') header = message.Header.add() header.name = 'List-Id' header.value = 'serverless-cli' mail_service._Send(message, None) retrieved_message = mail_service.get_sent_messages()[0] self.assertIsInstance(retrieved_message, mail.EmailMessage) self.assertEqual(retrieved_message.headers['List-Id'], 'serverless-cli')
def testDynamicClearSentMessages(self): """Tests that _Dynamic_ClearSentMessages clears and returns a count.""" mail_service = mail_stub.MailServiceStub() message = self.CreateRequest(sender='*****@*****.**', to=['*****@*****.**'], subject='a subject', body='a body', html='<html>') self.assertFalse(mail_service.get_sent_messages()) mail_service._CacheMessage(message) request = api_base_pb2.VoidProto() response = mail_stub_service_pb2.ClearSentMessagesResponse() mail_service._Dynamic_ClearSentMessages(request, response) self.assertEqual(1, response.messages_cleared) self.assertEmpty(mail_service.get_sent_messages())
def testSendToAdmins(self): """Test basic logging with minimal fields, only text body for admins.""" mail_service = mail_stub.MailServiceStub() results = [] message = self.CreateRequest(sender='*****@*****.**', subject='a subject', body='a body', email_type=mail.AdminEmailMessage) mail_service._SendToAdmins(message.ToProto(), None, results.append) self.assertListEqual([ 'MailService.SendToAdmins\n' ' From: [email protected]\n' ' Subject: a subject\n' ' Body:\n' ' Content-type: text/plain\n' ' Data length: %d' % len('a body') ], results)
def testSendSendmail(self): """Tests sending via sendmail.""" mail_service = mail_stub.MailServiceStub(enable_sendmail=True) message = self.CreateRequest(sender='*****@*****.**', to=['*****@*****.**'], cc=['*****@*****.**', '*****@*****.**'], bcc=['blind <*****@*****.**>'], subject='a subject', body='a body', html='<html>') send = self.mox.CreateMockAnything() receive = self.mox.CreateMockAnything() child = self.mox.CreateMock(subprocess.Popen) child.stdin = send child.stdout = receive self.popen( 'sendmail \'[email protected]\' \'[email protected]\' ' '\'[email protected]\' \'blind <*****@*****.**>\'', shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE).AndReturn(child) send.write( mox.Regex(b'^(?s)(?!From ).*' + re.escape(b'MIME-Version: 1.0\n' b'To: [email protected]\n' b'Cc: [email protected], [email protected]\n' b'Bcc: blind <*****@*****.**>\n' b'From: [email protected]\n' b'Reply-To: \n' b'Subject: a subject\n\n'))) send.close() child.poll().AndReturn(None) receive.read(100) child.poll().AndReturn(None) receive.read(100) child.poll().AndReturn(0) receive.close() self.mox.ReplayAll() mail_service._Send(message.ToProto(), None, self.DoNothing, self.smtp, self.popen) self.mox.VerifyAll()
def setupMail(smtp_host, smtp_port, smtp_user, smtp_password, enable_sendmail=False, show_mail_body=False): """Sets up mail.""" from google.appengine.api import mail_stub apiproxy_stub_map.apiproxy.RegisterStub( 'mail', mail_stub.MailServiceStub(smtp_host, smtp_port, smtp_user, smtp_password, enable_sendmail=enable_sendmail, show_mail_body=show_mail_body))
def testGetSentMessagesWithUnicodeInPayloadWith8bitEncoding(self): backup_charset = charset.CHARSETS['utf-8'] charset.add_charset('utf-8', charset.SHORTEST, None, 'utf-8') mail_service = mail_stub.MailServiceStub() message = self.CreateRequest(sender=u'Áwêsöme <*****@*****.**>', to=[u'Vérÿ Cöôl <*****@*****.**>'], subject='a subject', body=u'a body using special chars: éèÉ©', html=u'<html>éèÉ©') mail_service._CacheMessage(message) retrieved_messages = mail_service.get_sent_messages() self.assertLen(retrieved_messages, 1) self.CompareMessages(message, retrieved_messages[0]) charset.add_charset('utf-8', backup_charset[0], backup_charset[1], backup_charset[2])