def test_get_keys_ambiguous(self): """Test gettings keys when when the key is ambiguous.""" key = crypto.get_key(FPR, validate=True, encrypt=True, signed_only=False) ui = mock.Mock() # Creat a ui.choice object that can satisfy twisted, but can also be # queried for calls as a mock @inlineCallbacks def choice(*args, **kwargs): yield None ui.choice = mock.Mock(wraps=choice) ids = [FPR] with mock.patch( 'alot.commands.utils.crypto.get_key', mock.Mock(side_effect=errors.GPGProblem( 'test', errors.GPGCode.AMBIGUOUS_NAME))): with mock.patch('alot.commands.utils.crypto.list_keys', mock.Mock(return_value=[key])): yield utils._get_keys(ui, ids, signed_only=False) ui.choice.assert_called_once()
def test_get_keys_missing(self): """Test that getting keys works when some keys are missing.""" expected = crypto.get_key(FPR, validate=True, encrypt=True, signed_only=False) ui = utilities.make_ui() ids = [FPR, "6F6B15509CF8E59E6E469F327F438280EF8D349F"] actual = yield utils._get_keys(ui, ids) self.assertIn(FPR, actual) self.assertEqual(actual[FPR].fpr, expected.fpr)
def test_get_keys(self): """Test that getting keys works when all keys are present.""" expected = crypto.get_key(FPR, validate=True, encrypt=True, signed_only=False) ui = utilities.make_ui() ids = [FPR] actual = yield utils._get_keys(ui, ids) self.assertIn(FPR, actual) self.assertEqual(actual[FPR].fpr, expected.fpr)
def test_get_keys_ambiguous(self): """Test gettings keys when when the key is ambiguous.""" key = crypto.get_key(FPR, validate=True, encrypt=True, signed_only=False) ui = utilities.make_ui() # Creat a ui.choice object that can satisfy twisted, but can also be # queried for calls as a mock @inlineCallbacks def choice(*args, **kwargs): yield None ui.choice = mock.Mock(wraps=choice) ids = [FPR] with mock.patch('alot.commands.utils.crypto.get_key', mock.Mock(side_effect=errors.GPGProblem( 'test', errors.GPGCode.AMBIGUOUS_NAME))): with mock.patch('alot.commands.utils.crypto.list_keys', mock.Mock(return_value=[key])): yield utils._get_keys(ui, ids, signed_only=False) ui.choice.assert_called_once()
def test_get_keys_signed_only(self): """Test gettings keys when signed only is required.""" ui = utilities.make_ui() ids = [FPR] actual = yield utils._get_keys(ui, ids, signed_only=True) self.assertEqual(actual, {})