コード例 #1
0
ファイル: test_gpgedit.py プロジェクト: jaryaman/gpgedit
def test__file_changed():
    test_file = File(Path(RESOURCES) / 'test.txt')
    original_message = 'test text\n'
    test_file.path.write_text(original_message)
    test_file.get_stats()

    try:
        assert not _file_changed(test_file)
        test_file.path.write_text('new message')
        assert _file_changed(test_file)
        assert not _file_changed(test_file)
    except Exception as e:
        raise e
    finally:
        os.remove(test_file.path)
コード例 #2
0
ファイル: test_gpgedit.py プロジェクト: jaryaman/gpgedit
def test__encrypt_temp_to_data():
    temp_file = File(Path(TMP_DIR) / 'data-test.txt')
    temp_file.mkdir(exist_ok=True)
    temp_file.path.write_text('test text')

    data_file = File(Path(RESOURCES) / 'test.gpg')
    passwd = 'test-pswd'
    try:
        _encrypt_temp_to_data(temp_file, data_file, passwd)
        assert temp_file.path.exists()
    except Exception as e:
        raise e
    finally:
        if data_file.path.exists():
            os.remove(data_file.path)
        shutil.rmtree(temp_file.path.parent)
コード例 #3
0
ファイル: test_gpgedit.py プロジェクト: jaryaman/gpgedit
def test__augment_with_no_change(mocker):
    mocker.patch('gpgedit._launch_editor')

    test_file = File(Path(RESOURCES) / 'test.txt')
    test_file.path.write_text('test text\n')
    with pytest.raises(Exception) as _:
        _augment(test_file)
コード例 #4
0
ファイル: test_gpgedit.py プロジェクト: jaryaman/gpgedit
def test__augment_with_change(mocker):
    test_file = File(Path(RESOURCES) / 'test.txt')
    original_message = 'test text\n'
    test_file.path.write_text(original_message)
    mocker.patch('gpgedit._launch_editor', new=overwrite_file)

    try:
        _augment(test_file)
        assert test_file.path.read_text() != original_message
    except Exception as e:
        raise e
    finally:
        if test_file.path.exists():
            os.remove(test_file.path)
コード例 #5
0
ファイル: test_gpgedit.py プロジェクト: jaryaman/gpgedit
def test_edit_encrypted(mocker):
    encrypted_file_path = Path(RESOURCES) / 'test.gpg'
    decrypted_file_path = Path(RESOURCES) / 'decrypted.txt'
    pswd = 'test-pass'
    msg_original = 'this is a test'

    generate_encrypted_dummy(mocker,
                             encrypted_file_path,
                             pswd=pswd,
                             msg=msg_original)

    mocker.patch('getpass.getpass', return_value=pswd)
    mocker.patch('gpgedit._augment', new=overwrite_file)

    try:
        edit_encrypted(encrypted_file_path)
        _decrypt_data_to_temp(File(encrypted_file_path),
                              File(decrypted_file_path), pswd)
        assert decrypted_file_path.read_text() == MESSAGE
    except Exception as e:
        raise e
    finally:
        os.remove(encrypted_file_path)
        os.remove(decrypted_file_path)
コード例 #6
0
ファイル: test_gpgedit.py プロジェクト: jaryaman/gpgedit
def test__decrypt_data_to_temp():
    original_file = File(Path(RESOURCES) / 'test.txt')
    original_file.path.write_text('test text')

    data_file = File(Path(TMP_DIR) / 'test.gpg')
    data_file.mkdir(exist_ok=True)
    passwd = 'test-pswd'

    enc_dec_file = File(Path(RESOURCES) / 'test-dec.txt')
    try:
        _encrypt_temp_to_data(original_file, data_file, passwd)
        _decrypt_data_to_temp(data_file, enc_dec_file, passwd)
        assert original_file.path.read_text() == enc_dec_file.path.read_text()
    except Exception as e:
        raise e
    finally:
        shutil.rmtree(data_file.path.parent)
        os.remove(original_file.path)
        if enc_dec_file.path.exists():
            os.remove(enc_dec_file.path)
コード例 #7
0
ファイル: test_gpgedit.py プロジェクト: jaryaman/gpgedit
def make_file_struct(name: str = TEST_FILE):
    path = Path(name)
    out_file = File(path)
    return out_file