[#927] Uses internal email date method for consistency
authorAnike Arni <aarni@thoughtworks.com>
Thu, 20 Apr 2017 19:24:47 +0000 (16:24 -0300)
committerAnike Arni <aarni@thoughtworks.com>
Thu, 20 Apr 2017 19:24:47 +0000 (16:24 -0300)
with @deniscostadsc

service/pixelated/account_recovery.py
service/test/unit/test_account_recovery.py

index f84aea1..58242a7 100644 (file)
 
 import pkg_resources
 import binascii
+from email import message_from_string
 
 from twisted.internet.defer import inlineCallbacks, returnValue
 from twisted.logger import Logger
 from twisted.mail import smtp
 
-from email import message_from_string
-from email.utils import formatdate
+from pixelated.support import date
 
 log = Logger()
 
@@ -71,6 +71,7 @@ class AccountRecovery(object):
             raise e
 
     def _get_recovery_mail(self, code, sender, backup_email):
+        email_date = date.mail_date_now()
         recovery_mail = pkg_resources.resource_filename(
             'pixelated.assets',
             'recovery.mail.%s' % (self._language))
@@ -81,4 +82,4 @@ class AccountRecovery(object):
                 recovery_code=binascii.hexlify(code),
                 backup_email=backup_email,
                 sender=sender,
-                date=formatdate(localtime=True)))
+                date=email_date))
index 4dc9621..2a18534 100644 (file)
@@ -85,13 +85,13 @@ class AccountRecoveryTest(unittest.TestCase):
             mock_resource.assert_called_once_with('pixelated.assets',
                                                   'recovery.mail.pt-BR')
 
-    @patch('pixelated.account_recovery.formatdate')
+    @patch('pixelated.account_recovery.date.mail_date_now')
     @patch('pixelated.account_recovery.smtp.sendmail')
     @patch('pixelated.account_recovery.pkg_resources.resource_filename')
     @defer.inlineCallbacks
-    def test_send_recovery_code_by_email(self, mock_resource, mock_sendmail, mock_formatdate):
+    def test_send_recovery_code_by_email(self, mock_resource, mock_sendmail, mock_date):
         mock_sendmail.return_value = defer.succeed(None)
-        mock_formatdate.return_value = 'Sat, 21 Mar 2015 19:30:09 -0300'
+        mock_date.return_value = 'Sat, 21 Mar 2015 19:30:09 -0300'
 
         sender = 'team@{}'.format(self.domain)
         mock_file_content = '{backup_email}, {sender}, {date}, {domain}, {recovery_code}'