summaryrefslogtreecommitdiff
path: root/service/test
diff options
context:
space:
mode:
Diffstat (limited to 'service/test')
-rw-r--r--service/test/functional/features/steps/mail_list.py6
-rw-r--r--service/test/functional/features/steps/mail_view.py6
-rw-r--r--service/test/unit/test_account_recovery.py14
3 files changed, 16 insertions, 10 deletions
diff --git a/service/test/functional/features/steps/mail_list.py b/service/test/functional/features/steps/mail_list.py
index 2953c1af..21694153 100644
--- a/service/test/functional/features/steps/mail_list.py
+++ b/service/test/functional/features/steps/mail_list.py
@@ -138,9 +138,3 @@ def impl(context):
@then('I should not see any email')
def impl(context):
_wait_for_mail_list_to_be_empty(context)
-
-
-@then(u'I see the mail has the recovery code')
-def step_impl(context):
- expected_body = 'Your code'
- context.execute_steps(u"Then I see that the body has '%s'" % expected_body)
diff --git a/service/test/functional/features/steps/mail_view.py b/service/test/functional/features/steps/mail_view.py
index d10f86e7..9b49e6e5 100644
--- a/service/test/functional/features/steps/mail_view.py
+++ b/service/test/functional/features/steps/mail_view.py
@@ -109,3 +109,9 @@ def impl(context):
assert cc is not None
assert bcc is not None
+
+
+@then(u'I see the mail has the recovery code')
+def step_impl(context):
+ expected_body = 'This code is they only way to recover access to your account in case you lose your password.'
+ context.execute_steps(u"Then I see that the body has '%s'" % expected_body)
diff --git a/service/test/unit/test_account_recovery.py b/service/test/unit/test_account_recovery.py
index 08298419..b0edc466 100644
--- a/service/test/unit/test_account_recovery.py
+++ b/service/test/unit/test_account_recovery.py
@@ -19,7 +19,7 @@ from twisted.internet import defer
from twisted.trial import unittest
from twisted.mail import smtp
-from mock import patch, Mock
+from mock import patch, Mock, mock_open
from mockito import when, any as ANY
from pixelated.account_recovery import AccountRecovery
@@ -50,15 +50,21 @@ class AccountRecoveryTest(unittest.TestCase):
yield self.account_recovery.update_recovery_code()
self.mock_bonafide_session.update_recovery_code.assert_called_once_with(self.generated_code)
+ @patch('pixelated.account_recovery.smtp.sendmail')
+ @patch('pixelated.account_recovery.pkg_resources.resource_filename')
@defer.inlineCallbacks
- def test_send_recovery_code_by_email(self):
+ def test_send_recovery_code_by_email(self, mock_resource, mock_sendmail):
+ mock_sendmail.return_value = defer.succeed(None)
+
sender = 'team@{}'.format(self.domain)
- msg = MIMEText('Your code %s' % self.generated_code)
+ mock_file_content = '{domain}, {recovery_code}, {account_recovery_url}'
+ recovery_code_email = 'test.com, 4645a2f8997e5d0d, test.com/account-recovery'
+ msg = MIMEText(recovery_code_email)
msg['Subject'] = 'Recovery Code'
msg['From'] = sender
msg['To'] = self.backup_email
- with patch.object(smtp, 'sendmail', return_value=defer.succeed(None)) as mock_sendmail:
+ with patch('pixelated.account_recovery.open', mock_open(read_data=mock_file_content), create=True):
yield self.account_recovery._send_mail(self.generated_code, self.backup_email)
mock_sendmail.assert_called_with(