diff options
Diffstat (limited to 'service/test/unit')
-rw-r--r-- | service/test/unit/bitmask_libraries/test_keymanager.py | 22 | ||||
-rw-r--r-- | service/test/unit/config/test_leap.py | 2 |
2 files changed, 11 insertions, 13 deletions
diff --git a/service/test/unit/bitmask_libraries/test_keymanager.py b/service/test/unit/bitmask_libraries/test_keymanager.py index 6b7c114e..c788697c 100644 --- a/service/test/unit/bitmask_libraries/test_keymanager.py +++ b/service/test/unit/bitmask_libraries/test_keymanager.py @@ -28,7 +28,8 @@ class KeymanagerTest(TestCase): self.provider = MagicMock() self.soledad = MagicMock() self.auth = MagicMock(token='token', auth='auth') - with patch('pixelated.bitmask_libraries.keymanager.KeyManager'): + self.leap_keymanager = MagicMock() + with patch('pixelated.bitmask_libraries.keymanager.KeyManager', return_value=self.leap_keymanager): self.keymanager = Keymanager(self.provider, self.soledad, 'test_user@some-server.test', @@ -108,33 +109,30 @@ class KeymanagerTest(TestCase): with self.assertRaises(UploadKeyError): yield self.keymanager.generate_openpgp_key() - self.keymanager.delete_key_pair.assert_called_once_with('test_user@some-server.test') + self.keymanager.delete_key_pair.assert_called_once() + @defer.inlineCallbacks def test_keymanager_regenerate_key_pair_if_current_key_expired(self): mock_open_pgp_key = MagicMock() mock_open_pgp_key.has_expired = MagicMock(return_value=True) when(self.keymanager)._key_exists('test_user@some-server.test').thenReturn(mock_open_pgp_key) - self.keymanager._regenerate_key = MagicMock() - self.keymanager._send_key_to_leap = MagicMock() - - self.keymanager.generate_openpgp_key() + yield self.keymanager.generate_openpgp_key() - self.keymanager._regenerate_key.assert_called_once() - self.keymanager._send_key_to_leap.assert_called_once() + self.leap_keymanager.regenerate_key.assert_called_once() + self.leap_keymanager.send_key.assert_called_once() @defer.inlineCallbacks def test_key_regeneration_does_not_delete_key_when_upload_fails(self): mock_open_pgp_key = MagicMock() mock_open_pgp_key.has_expired = MagicMock(return_value=True) - when(self.keymanager)._key_exists('test_user@some-server.test').thenReturn(mock_open_pgp_key) + self.leap_keymanager.get_key = MagicMock(return_value=defer.succeed(mock_open_pgp_key)) + self.leap_keymanager.send_key = MagicMock(side_effect=UploadKeyError('Could not upload key')) - self.keymanager._regenerate_key = MagicMock() self.keymanager.delete_key_pair = MagicMock() - when(self.keymanager)._send_key_to_leap().thenRaise(UploadKeyError('Could not upload key')) with self.assertRaises(UploadKeyError): yield self.keymanager.generate_openpgp_key() - self.keymanager._regenerate_key.assert_called_once() + self.leap_keymanager.regenerate_key.assert_called_once() self.keymanager.delete_key_pair.assert_not_called() diff --git a/service/test/unit/config/test_leap.py b/service/test/unit/config/test_leap.py index a6893194..7e073d26 100644 --- a/service/test/unit/config/test_leap.py +++ b/service/test/unit/config/test_leap.py @@ -18,7 +18,7 @@ class TestLeapInit(unittest.TestCase): with patch.object(LeapSessionFactory, '_create_new_session', return_value=session): yield create_leap_session(provider_mock, 'username', 'password', auth=auth_mock) - session.first_required_sync.assert_called_with() + session.first_required_sync.assert_called_once() self.assertEqual({'mocked key': session}, SessionCache.sessions) @patch('pixelated.config.sessions.SessionCache.lookup_session') |