def test_create_keys_if_path_is_passed_create_file_homedir(mocker, mock_call, mock_open): mock_call.return_value = ('', '') mock_tempdir = mocker.patch('passpie.crypt.tempdir', mock_open(), create=True) mocker.patch('passpie.crypt.export_keys', side_effect=['PUBLIC', 'PRIVATE']) mock_open = mocker.patch("passpie.crypt.open", mock_open(), create=True) mock_keysfile = mock_open().__enter__() mock_tempdir().__enter__().return_value = 'create_keys' create_keys('passphrase', 'path') assert mock_keysfile.write.called mock_keysfile.write.assert_any_call('PUBLIC') mock_keysfile.write.assert_any_call('PRIVATE')
def test_create_keys_export_public_and_secret_keys_into_stdout(mocker): passphrase = "passphrase" homedir = "mock/homedir" key_input = 'some key input' output = '--GPG--' mocker.patch('passpie.crypt.which', return_value='gpg') mocker.patch('passpie.crypt.make_key_input', return_value=key_input) mock_call = mocker.patch('passpie.crypt.process.call', return_value=(output, '')) mock_tempdir = mocker.patch('passpie.crypt.tempdir', return_value=homedir) command = [ 'gpg', '--batch', '--no-tty', '--homedir', homedir, '--gen-key', ] result = create_keys(passphrase) assert result == output assert mock_call.called mock_call.assert_called_once_with(command, input=key_input)
def test_create_keys_if_path_is_passed_create_file_homedir( mocker, mock_call, mock_open): mock_call.return_value = ('', '') mock_tempdir = mocker.patch('passpie.crypt.tempdir', mock_open(), create=True) mocker.patch('passpie.crypt.export_keys', side_effect=['PUBLIC']) mocker.patch('passpie.crypt.export_secret_keys', side_effect=['PRIVATE']) mock_open = mocker.patch("passpie.crypt.open", mock_open(), create=True) mock_keysfile = mock_open().__enter__() mock_tempdir().__enter__().return_value = 'create_keys' create_keys('passphrase', 'path') assert mock_keysfile.write.called mock_keysfile.write.assert_any_call('PUBLIC') mock_keysfile.write.assert_any_call('PRIVATE')
def test_create_keys_export_public_and_secret_keys_into_stdout(mocker): passphrase = "passphrase" homedir = "mock/homedir" key_input = 'some key input' output = '--GPG--' mocker.patch('passpie.crypt.which', return_value='gpg') mocker.patch('passpie.crypt.make_key_input', return_value=key_input) mock_call = mocker.patch('passpie.crypt.process.call', return_value=(output, '')) mock_tempdir = mocker.patch('passpie.crypt.tempdir', return_value=homedir) command = [ 'gpg', '--batch', '--no-tty', '--no-secmem-warning', '--no-permission-warning', '--no-mdc-warning', '--homedir', homedir, '--gen-key', ] result = create_keys(passphrase) assert result == output assert mock_call.called mock_call.assert_called_once_with(command, input=key_input)