예제 #1
0
def test_gets_filepaths_from_os_walk(os_walk_mock, logger_mock, *_):
    zip_folder("my-test-file", "my/test/path")

    assert (
        logger_mock.info.call_args_list[1][0][0] ==
        "Zipping files: ['project-root/file-one.txt', 'project-root/file_two.txt']"
    )
예제 #2
0
def test_zips_files_with_flattened_paths(os_walk_mock, zipfile_mock, *_):
    zip_folder("my-test-file", "my/test/path")

    zipfile_mock.ZipFile.assert_called_once_with(
        "my-test-file-2019-06-28T000000.zip", "w")

    zipfile_mock.ZipFile.return_value.call_count == 2
    assert (zipfile_mock.ZipFile.return_value.write.call_args_list[0][0][0] ==
            "project-root/file-one.txt")
    assert (zipfile_mock.ZipFile.return_value.write.call_args_list[0][0][1] ==
            "file-one.txt")
    assert (zipfile_mock.ZipFile.return_value.write.call_args_list[1][0][0] ==
            "project-root/file-two.txt")
    assert (zipfile_mock.ZipFile.return_value.write.call_args_list[1][0][1] ==
            "file-two.txt")
예제 #3
0
def install_scripts(destination_username=None):
    """
    Zips scripts from project and installs them in the NAS device through
    several fabric actions. A username can be passed to specify which user's
    home to install the scripts to. If not passed, value will be taken from
    environment config.
    """
    syno_config = SynoConfig()
    destination_username = (destination_username
                            if destination_username else syno_config.username)

    # Build sftp and absolute paths
    (
        remote_sftp_destination_path,
        remote_absolute_destination_path,
    ) = build_destination_paths(destination_username)

    # Zip files
    zipped_scripts = zip_folder("synology-scripts", SCRIPTS_PATH,
                                ZIP_DESTINATION_PATH, [".py"])

    try:
        run_remote_installation_commands(
            syno_config,
            zipped_scripts,
            remote_sftp_destination_path,
            remote_absolute_destination_path,
        )

    except Exception as e:
        logger.error(f"An error occurred: {e}")
예제 #4
0
def test_excludes_files_by_passed_extension(os_walk_mock, logger_mock, *_):
    zip_folder("my-test-file", "my/test/path", None, [".py"])

    assert (logger_mock.info.call_args_list[1][0][0] ==
            "Zipping files: ['project-root/file-one.txt']")
예제 #5
0
def test_adds_path_to_filename_when_destination_dir_is_provided(
        os_walk_mock, zipfile_mock, *_):
    actual = zip_folder("my-test-file", "my/test/path", "my/destination/path")
    expected = "my/destination/path/my-test-file-2019-06-28T000000.zip"

    assert actual == expected
예제 #6
0
def test_creates_and_returns_zipname_with_passed_base_and_timestamp(
        os_walk_mock, *_):
    actual = zip_folder("my-test-file", "my/test/path")

    assert actual == "my-test-file-2019-06-28T000000.zip"