Пример #1
0
def test_get_settings__no_args():
    """get_settings() requires one boolean and only one boolean to be True."""

    with pytest.raises(RuntimeError):
        pypicloud_tools.get_settings()
    with pytest.raises(RuntimeError):
        pypicloud_tools.get_settings(True, False, True)
Пример #2
0
def test_get_settings__no_s3_config(config_file, capfd):
    """If no s3 config is found, ensure get_settings raises an error."""

    pypicloud_tools.sys.argv = ["list", "--config", config_file]
    with pytest.raises(SystemExit):
        pypicloud_tools.get_settings(listing=True)

    out, err = capfd.readouterr()
    assert "ERROR: Could not determine S3 settings." in err
    assert DEFAULT_CONFIG in out  # stdout should be a help message...
Пример #3
0
def test_get_settings__config_fillins(config_file):
    """Ensure the config file fills in any missing arguments."""

    with open(config_file, "w") as openconf:
        openconf.write("\n".join([
            "[pypicloud]",
            "repository:http://test-server/pypi",
            "username:test-username",
            "password:test-password",
            "bucket:bucket-name",
            "access:access-key",
            "secret:secret-key",
        ]))

    pypicloud_tools.sys.argv = [
        "list",
        "--config",
        config_file,
        "some_file",
        "some_other_file",
    ]
    expected_s3 = pypicloud_tools.S3Config(
        "bucket-name", "access-key", "secret-key", None,
    )
    expected_pypi = pypicloud_tools.PyPIConfig(
        "http://test-server/pypi", "test-username", "test-password"
    )

    settings = pypicloud_tools.get_settings(listing=True)

    assert settings.s3 == expected_s3
    assert settings.pypi == expected_pypi
    assert settings.items == ["some_file", "some_other_file"]
Пример #4
0
def test_get_settings__s3_overrides(direction, acl, config_file):
    """If s3 options are given on the command line, they take precedence."""

    with open(config_file, "w") as openconf:
        openconf.write("\n".join([
            "[pypicloud]",
            "repository:http://test-server/pypi",
            "username:test-username",
            "password:test-password",
            "bucket:bucket-name",
            "access:access-key",
            "secret:secret-key",
        ]))

    pypicloud_tools.sys.argv = [direction]

    if acl:
        pypicloud_tools.sys.argv.extend(["--acl", acl])

    pypicloud_tools.sys.argv.extend([
        "--bucket",
        "fake-bucket",
        "--access",
        "fake-access",
        "--secret",
        "fake-secret",
        "--config",
        config_file,
        "some_file",
        "some_other_file",
    ])

    settings = pypicloud_tools.get_settings(**{direction: True})
    expected_s3 = pypicloud_tools.S3Config(
        "fake-bucket", "fake-access", "fake-secret", acl,
    )
    expected_pypi = pypicloud_tools.PyPIConfig(
        "http://test-server/pypi", "test-username", "test-password"
    )

    assert settings.s3 == expected_s3
    assert settings.pypi == expected_pypi
    assert settings.items == ["some_file", "some_other_file"]
Пример #5
0
def test_get_settings__needs_remainders(direction):
    """When not listing, the user must provide a package or filename."""

    pypicloud_tools.sys.argv = [direction]
    with pytest.raises(SystemExit):
        pypicloud_tools.get_settings(download=True)