예제 #1
0
def test_user_ftp_explicit_config():
    file_sources_config = ConfiguredFileSourcesConfig(ftp_upload_purge=False, )
    plugin = {
        'type': 'gxftp',
    }
    tmp, root = setup_root()
    file_sources = ConfiguredFileSources(file_sources_config,
                                         conf_dict=[plugin])
    user_context = user_context_fixture(user_ftp_dir=root)
    write_file_fixtures(tmp, root)

    assert_realizes_as(file_sources,
                       "gxftp://a",
                       "a\n",
                       user_context=user_context)

    file_sources_remote = serialize_and_recover(file_sources,
                                                user_context=user_context)
    assert_realizes_as(file_sources_remote, "gxftp://a", "a\n")

    as_dict = file_sources.to_dict()
    assert len(as_dict["file_sources"]) == 1
    file_source_as_dict = as_dict["file_sources"][0]
    assert file_source_as_dict["uri_root"] == "gxftp://"
    assert file_source_as_dict["id"] == "_ftp"
예제 #2
0
def _configured_file_sources(
        include_allowlist=False,
        plugin_extra_config=None,
        per_user=False,
        writable=None,
        allow_subdir_creation=True) -> TestConfiguredFileSources:
    tmp, root = setup_root()
    config_kwd = {}
    if include_allowlist:
        config_kwd["symlink_allowlist"] = [tmp]
    file_sources_config = ConfiguredFileSourcesConfig(**config_kwd)
    plugin = {
        'type': 'posix',
    }
    if writable is not None:
        plugin['writable'] = writable
    if per_user:
        plugin['root'] = "%s/${user.username}" % root
        # setup files just for alice
        root = os.path.join(root, "alice")
        os.mkdir(root)
    else:
        plugin['root'] = root
    plugin.update(plugin_extra_config or {})
    write_file_fixtures(tmp, root)
    file_sources = TestConfiguredFileSources(file_sources_config,
                                             conf_dict={"test1": plugin},
                                             test_root=root)
    return file_sources
예제 #3
0
def test_import_dir_implicit_config():
    tmp, root = setup_root()
    file_sources_config = ConfiguredFileSourcesConfig(
        library_import_dir=root, )
    file_sources = ConfiguredFileSources(file_sources_config,
                                         conf_dict=[],
                                         load_stock_plugins=True)
    write_file_fixtures(tmp, root)

    assert_realizes_as(file_sources, "gximport://a", "a\n")
예제 #4
0
def _configured_file_sources() -> TestConfiguredFileSources:
    tmp, root = setup_root()
    file_sources_config = ConfiguredFileSourcesConfig()
    plugin = {
        'type': 'posix',
    }
    plugin['root'] = root
    write_file_fixtures(tmp, root)
    file_sources = TestConfiguredFileSources(file_sources_config,
                                             conf_dict={"test1": plugin},
                                             test_root=root)
    return file_sources
예제 #5
0
def test_import_dir_explicit_config():
    tmp, root = setup_root()
    file_sources_config = ConfiguredFileSourcesConfig(
        library_import_dir=root, )
    plugin = {
        'type': 'gximport',
    }
    file_sources = ConfiguredFileSources(file_sources_config,
                                         conf_dict=[plugin])
    write_file_fixtures(tmp, root)

    assert_realizes_as(file_sources, "gximport://a", "a\n")
예제 #6
0
def test_user_ftp_respects_upload_purge_on_by_default():
    tmp, root = setup_root()
    file_sources_config = ConfiguredFileSourcesConfig(ftp_upload_dir=root, )
    file_sources = ConfiguredFileSources(file_sources_config,
                                         conf_dict=[],
                                         load_stock_plugins=True)
    user_context = user_context_fixture(user_ftp_dir=root)
    write_file_fixtures(tmp, root)
    assert_realizes_as(file_sources,
                       "gxftp://a",
                       "a\n",
                       user_context=user_context)
    assert not os.path.exists(os.path.join(root, "a"))
예제 #7
0
def test_user_import_dir_implicit_config():
    tmp, root = setup_root()
    file_sources_config = ConfiguredFileSourcesConfig(
        user_library_import_dir=root, )
    file_sources = ConfiguredFileSources(file_sources_config,
                                         conf_dict=[],
                                         load_stock_plugins=True)

    write_file_fixtures(tmp, os.path.join(root, EMAIL))

    user_context = user_context_fixture()
    assert_realizes_as(file_sources,
                       "gxuserimport://a",
                       "a\n",
                       user_context=user_context)
예제 #8
0
def test_user_ftp_implicit_config():
    tmp, root = setup_root()
    file_sources_config = ConfiguredFileSourcesConfig(
        ftp_upload_dir=root,
        ftp_upload_purge=False,
    )
    file_sources = ConfiguredFileSources(file_sources_config,
                                         conf_dict=[],
                                         load_stock_plugins=True)
    user_context = user_context_fixture(user_ftp_dir=root)
    write_file_fixtures(tmp, root)
    assert os.path.exists(os.path.join(root, "a"))

    assert_realizes_as(file_sources,
                       "gxftp://a",
                       "a\n",
                       user_context=user_context)

    file_sources_remote = serialize_and_recover(file_sources,
                                                user_context=user_context)
    assert_realizes_as(file_sources_remote, "gxftp://a", "a\n")
    assert os.path.exists(os.path.join(root, "a"))