Exemplo n.º 1
0
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)
Exemplo n.º 2
0
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)
Exemplo n.º 3
0
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)
Exemplo n.º 4
0
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)
Exemplo n.º 5
0
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)
Exemplo n.º 6
0
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)
Exemplo n.º 7
0
def make_file_struct(name: str = TEST_FILE):
    path = Path(name)
    out_file = File(path)
    return out_file