Esempio n. 1
0
def test_plugin_init(s3_mock: S3Path) -> None:
    config_loader = mock_config("""
[mirror]
directory = /tmp/pypi
json = true
master = https://pypi.org
timeout = 60
global-timeout = 18000
workers = 3
hash-index = true
stop-on-error = true
storage-backend = swift
verifiers = 3
keep_index_versions = 2
compare-method = hash
[s3]
region_name = us-east-1
aws_access_key_id = 123456
aws_secret_access_key = 123456
endpoint_url = http://localhost:9090
signature_version = s3v4
""")
    backend = s3.S3Storage(config=config_loader.config)
    backend.initialize_plugin()

    path = s3.S3Path("/tmp/pypi")
    resource, _ = path._accessor.configuration_map.get_configuration(path)
    assert resource.meta.client.meta.endpoint_url == "http://localhost:9090"

    config_loader = mock_config("""
[mirror]
directory = /tmp/pypi
json = true
master = https://pypi.org
timeout = 60
global-timeout = 18000
workers = 3
hash-index = true
stop-on-error = true
storage-backend = swift
verifiers = 3
keep_index_versions = 2
compare-method = hash
[s3]
endpoint_url = http://localhost:9090
""")
    backend = s3.S3Storage(config=config_loader.config)
    backend.initialize_plugin()

    path = s3.S3Path("/tmp/pypi")
    resource, _ = path._accessor.configuration_map.get_configuration(path)
    assert resource.meta.client.meta.endpoint_url == "http://localhost:9090"
Esempio n. 2
0
def test_path_glob(s3_mock: S3Path) -> None:
    files = [
        "index.html",
        "s1/index.html",
        "s3/index.html",
        "s3/index.html",
        "s3/not.html",
    ]
    for f in files:
        s3.S3Path(f"/{s3_mock.bucket}/{f}").touch()

    glob_result = list(s3.S3Path(f"/{s3_mock.bucket}").glob("**/index.html"))
    assert s3.S3Path(f"/{s3_mock.bucket}/s1/index.html") in glob_result
    assert s3.S3Path(f"/{s3_mock.bucket}/s3/not.html") not in glob_result
Esempio n. 3
0
def test_update_safe(s3_mock: S3Path) -> None:
    backend = s3.S3Storage()
    with backend.update_safe(f"/{s3_mock.bucket}/todo",
                             mode="w+",
                             encoding="utf-8") as fp:
        fp.write("flask\n")
    assert s3.S3Path(f"/{s3_mock.bucket}/todo").read_text() == "flask\n"
Esempio n. 4
0
def test_rewrite(s3_mock: S3Path) -> None:
    backend = s3.S3Storage()
    with backend.rewrite(f"/{s3_mock.bucket}/test") as fp:
        fp.write("testcontent\n")
    assert s3.S3Path("/test-bucket/test").read_text() == "testcontent\n"
Esempio n. 5
0
def test_path_mkdir(s3_mock: S3Path) -> None:
    new_folder = s3.S3Path(f"/{s3_mock.bucket}/test_folder")
    assert not new_folder.is_dir()
    new_folder.mkdir()
    assert new_folder.is_dir()