Beispiel #1
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
Beispiel #2
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"
Beispiel #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")
Beispiel #4
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"))
Beispiel #5
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)
Beispiel #6
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")
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
Beispiel #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"))
Beispiel #9
0
def _configured_file_sources(conf_file=FILE_SOURCES_CONF):
    file_sources_config = ConfiguredFileSourcesConfig()
    return ConfiguredFileSources(file_sources_config, conf_file=conf_file)
Beispiel #10
0
def configured_file_sources(conf_file):
    file_sources_config = ConfiguredFileSourcesConfig()
    return ConfiguredFileSources(file_sources_config, conf_file=conf_file)
Beispiel #11
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self.file_sources = ConfiguredFileSources(
         ConfiguredFileSourcesConfig.from_app_config(
             self.config))  # type: ignore[assignment]