From 264da7ad65744ebdf7f1f467b0a86e6565d7d7a5 Mon Sep 17 00:00:00 2001 From: Tulio Casagrande Date: Mon, 10 Apr 2017 17:38:50 -0300 Subject: [#927] Send recovery code using provider domain with @deniscostadsc --- .../unit/resources/test_backup_account_resource.py | 8 ++++++-- service/test/unit/test_account_recovery.py | 19 +++++++++++-------- 2 files changed, 17 insertions(+), 10 deletions(-) (limited to 'service/test') diff --git a/service/test/unit/resources/test_backup_account_resource.py b/service/test/unit/resources/test_backup_account_resource.py index e5e2793a..d6999c96 100644 --- a/service/test/unit/resources/test_backup_account_resource.py +++ b/service/test/unit/resources/test_backup_account_resource.py @@ -28,7 +28,10 @@ from test.unit.resources import DummySite class TestBackupAccountResource(unittest.TestCase): def setUp(self): self.services_factory = MagicMock() - self.resource = BackupAccountResource(self.services_factory, MagicMock()) + self.authenticator = MagicMock() + self.leap_provider = MagicMock() + self.leap_provider.server_name = 'test.com' + self.resource = BackupAccountResource(self.services_factory, self.authenticator, self.leap_provider) self.web = DummySite(self.resource) def test_get(self): @@ -59,7 +62,8 @@ class TestBackupAccountResource(unittest.TestCase): self.resource._authenticator.bonafide_session, self.resource.soledad(request), self.resource._service(request, '_leap_session').smtp_config, - self.resource._get_backup_email(request)) + self.resource._get_backup_email(request), + self.leap_provider.server_name) mock_account_recovery.update_recovery_code.assert_called() d.addCallback(assert_update_recovery_code_called) diff --git a/service/test/unit/test_account_recovery.py b/service/test/unit/test_account_recovery.py index f113169a..cd6835a9 100644 --- a/service/test/unit/test_account_recovery.py +++ b/service/test/unit/test_account_recovery.py @@ -32,14 +32,16 @@ class AccountRecoveryTest(unittest.TestCase): self.mock_soledad = Mock() self.mock_smtp_config = Mock() self.keymanager = Mock() - self.mock_smtp_config.remote_smtp_host = 'test.com' + self.mock_smtp_config.remote_smtp_host = 'localhost' self.mock_soledad.create_recovery_code.return_value = self.generated_code self.backup_email = 'test@test.com' + self.domain = 'test.com' self.account_recovery = AccountRecovery( self.mock_bonafide_session, self.mock_soledad, self.mock_smtp_config, - self.backup_email) + self.backup_email, + self.domain) self.mock_smtp = Mock() @defer.inlineCallbacks @@ -50,9 +52,10 @@ class AccountRecoveryTest(unittest.TestCase): @defer.inlineCallbacks def test_send_recovery_code_by_email(self): + sender = 'team@{}'.format(self.domain) msg = MIMEText('Your code %s' % self.generated_code) msg['Subject'] = 'Recovery Code' - msg['From'] = 'team@pixelated-project.org' + msg['From'] = sender msg['To'] = self.backup_email result = MagicMock() @@ -60,8 +63,8 @@ class AccountRecoveryTest(unittest.TestCase): with patch.object(smtp, 'sendmail', return_value=deferred_sendmail) as mock_sendmail: response = yield self.account_recovery._send_mail(self.generated_code, self.backup_email) - mock_sendmail.assert_called_with( - 'test.com', - 'team@pixelated-project.org', - [self.backup_email], - msg.as_string()) + mock_sendmail.assert_called_with( + self.mock_smtp_config.remote_smtp_host, + sender, + [self.backup_email], + msg.as_string()) -- cgit v1.2.3