def test_event(self, gpg_mock, mocker): gpg_mock._gpg.encrypt.return_value = self.mock_response(mocker) subscription = util.subscribe_event(self.event_class) GPG.encrypt(gpg_mock, self.message, key="fingerprint") event = subscription() assert isinstance(event.gpg, GPG) assert event.result.data == self.ciphertext.decode()
def test_encrypt_message_with_default_key(self, gpg_mock, mocker, monkeypatch): gpg_mock._gpg.encrypt.return_value = self.mock_response(mocker) monkeypatch.setattr(gpg_mock.keys.secret, "current", "CURRENT_KEY") GPG.encrypt(gpg_mock, self.message, event=False) gpg_mock._gpg.encrypt.assert_called_once_with(self.message, "CURRENT_KEY", symmetric=False, sign=True)
def test_encrypt_message(self, gpg_mock, fingerprint, symmetric, sign, mocker): gpg_mock._gpg.encrypt.return_value = self.mock_response(mocker) result = GPG.encrypt( gpg_mock, self.message, key=fingerprint, symmetric=symmetric, sign=sign, event=False, ) gpg_mock._gpg.encrypt.assert_called_once_with(self.message, fingerprint, symmetric=symmetric, sign=sign) assert result == self.ciphertext.decode()
def test_failure_raises_exception(self, gpg_mock, mocker): gpg_mock._gpg.encrypt.return_value = self.mock_response( mocker, status="encryption failed", stderr="error output") with pytest.raises(exceptions.MessageEncryptError): GPG.encrypt(gpg_mock, self.message, "fingerprint")