def test_main_dir_different_path(files): encrypt.run("dir2") decrypt._main("dir2.gpg", "dir1/dir2") files["f_root"].append("dir2.gpg") files["f_dir1"].append("dir2") assert os.listdir("dir1/dir2") == os.listdir("dir2") assert_files_changes(files)
def process_IN_CREATE(self, event): if os.path.isdir(event.pathname): print("New mounted volume detected: " + event.pathname) # Wait for the volume to be mounted and avoid permission errors time.sleep(1) # Encrypt the volume self.led_manager.set_state(CryptopuckState.ENCRYPTING) try: encrypt.run(event.pathname, event.pathname, self.public_key) print("Finished volume encryption: " + event.pathname) except Exception as e: print(e) self.led_manager.set_state(CryptopuckState.ERROR) # Unmount the volume try: print("Syncing") run_system_cmd("sync") print("Unmounting " + event.pathname) run_system_cmd("umount " + event.pathname) except Exception as e: print(e) self.led_manager.set_state(CryptopuckState.ERROR) # If everything went well, indicate success through the LED state if self.led_manager.get_state() == CryptopuckState.ENCRYPTING: self.led_manager.set_state(CryptopuckState.IDLE)
def test_main_dir(files): encrypt.run("dir2", "encrypted") decrypt._main("encrypted", "dirnew") files["f_root"].append("encrypted") files["f_root"].append("dirnew") assert os.listdir("dirnew") == os.listdir("dir2") assert_files_changes(files)
def test_main(files): encrypt.run("file1") decrypt._main("file1.gpg", "file1decrypted") with open("file1", "r") as f1, open("file1decrypted", "r") as f2: assert f1.read() == f2.read() files["f_root"].append("file1.gpg") files["f_root"].append("file1decrypted") assert_files_changes(files)
def test_run(files): file = "file1" mock_parent = Mock() with patch("encrypt._parse_arguments", return_value=( file, file + ".gpg", )) as mock_parse: with patch("encrypt._main") as mock_main: mock_parent.attach_mock(mock_parse, "mock_parse") mock_parent.attach_mock(mock_main, "mock_main") encrypt.run(file) """Check if method 1 is called before method 2""" mock_parent.assert_has_calls([ call.mock_parse(file, ""), call.mock_main(file, file + ".gpg") ])
def test_main_different_path(files): encrypt.run("file1") decrypt._main("file1.gpg", "dir2/file1") files["f_root"].append("file1.gpg") files["f_dir2"].append("file1") assert_files_changes(files)
def test_parse_output_not_specified(files): encrypt.run("file1", "new.gpg") input_file, output_file = decrypt._parse_arguments("new.gpg") assert output_file == "new"