コード例 #1
0
def test_cli_show_package_found(app: Cli) -> None:
    """Test `show` command: package found."""
    command = app.find("show")
    command_tester = CommandTester(command)

    result = command_tester.execute("flask 1.1.1 -v")
    assert result == 0
コード例 #2
0
ファイル: test_about.py プロジェクト: pomes/valiant
def test_cli_about_toml(
    app: Cli,
    valiant_app_name: str,
    valiant_version: str,
    valiant_license: str,
    valiant_url: str,
) -> None:
    """Test the static output from the `about` command - TOML output."""
    import toml

    command = app.find("about")
    command_tester = CommandTester(command)
    result = command_tester.execute(args="--out toml")

    assert result == 0
    output = toml.loads(command_tester.io.fetch_output())

    assert "tool" in output
    assert "valiant" in output["tool"]
    assert "about" in output["tool"]["valiant"]

    info = output["tool"]["valiant"]["about"]
    assert info["name"] == valiant_app_name
    assert info["version"] == valiant_version
    assert info["license"] == valiant_license
    assert info["url"] == valiant_url
コード例 #3
0
def test_cli_audit(app: Cli, datafiles: py.path) -> None:
    """Test the static output from the `audit` command."""
    command = app.find("audit")
    command_tester = CommandTester(command)
    result = command_tester.execute(f"{datafiles / 'requirements-small.txt'}")

    assert result == 0
コード例 #4
0
def test_cli_report_short(app: Cli) -> None:
    """Test the static output from the `report` command."""
    command = app.find("report")
    command_tester = CommandTester(command)
    result = command_tester.execute("-s flask 1.1.1")

    assert result == 0
コード例 #5
0
def test_cli_show_one_param(app: Cli) -> None:
    """Test `show` command: only one param provided."""
    command = app.find("show")
    command_tester = CommandTester(command)

    with pytest.raises(CannotParseArgsException):
        result = command_tester.execute("bottle")
        assert result != 0
コード例 #6
0
def test_cli_show_no_params(app: Cli) -> None:
    """Test `show` command: no params provided."""
    command = app.find("show")
    command_tester = CommandTester(command)

    with pytest.raises(CannotParseArgsException):
        result = command_tester.execute()
        assert result != 0
コード例 #7
0
ファイル: test_about.py プロジェクト: pomes/valiant
def test_cli_about(
    app: Cli, valiant_app_title: str, valiant_version: str, valiant_license: str
) -> None:
    """Test the static output from the `about` command."""
    command = app.find("about")
    command_tester = CommandTester(command)
    result = command_tester.execute()

    assert result == 0
    output = command_tester.io.fetch_output()
    assert output.startswith(f"{valiant_app_title} {valiant_version}")
    assert output.find(valiant_license)
コード例 #8
0
def test_cli_report_json(app: Cli) -> None:
    """Test the output from the `report` command - JSON output."""
    import json

    command = app.find("report")
    command_tester = CommandTester(command)
    result = command_tester.execute("flask 1.1.1 -o json")

    assert result == 0
    output = json.loads(command_tester.io.fetch_output())
    assert output

    assert output["metadata"]["name"].lower() == "flask"
    assert output["metadata"]["version"] == "1.1.1"

    assert len(output["reports"]) == 3
    assert "safety" in output["reports"]
    assert "spdx" in output["reports"]
    assert "basic" in output["reports"]
コード例 #9
0
def test_cli_audit_toml(app: Cli, datafiles: py.path) -> None:
    """Test the output from the `audit` command - JSON output.

    TODO: Flesh out this test.
    """
    import toml

    command = app.find("audit")
    command_tester = CommandTester(command)
    result = command_tester.execute(
        f"{datafiles / 'requirements-small.txt'} -o toml")

    assert result == 0
    output = toml.loads(command_tester.io.fetch_output())
    assert output

    reports = output["tool"]["valiant"]["report"]
    assert len(reports) == 7

    expected_packages = [
        ("click", "7.1.1"),
        ("flask", "1.1.1"),
        ("itsdangerous", "1.1.0"),
        ("jinja2", "2.11.1"),
        ("markupsafe", "1.1.1"),
        ("werkzeug", "1.0.1"),
        ("insecure-package", "0.1.0"),
    ]

    package_reports = [(item["metadata"]["name"].lower(),
                        item["metadata"]["version"]) for item in reports]

    assert len(package_reports) == len(expected_packages)

    for pkg in expected_packages:
        assert pkg in package_reports

    for rep in reports:
        assert len(rep["reports"]) == 3
        assert "safety" in rep["reports"]
        assert "spdx" in rep["reports"]
        assert "basic" in rep["reports"]
コード例 #10
0
def test_cli_report_toml(app: Cli) -> None:
    """Test the output from the `report` command - TOML output."""
    import toml

    command = app.find("report")
    command_tester = CommandTester(command)
    result = command_tester.execute("flask 1.1.1 -o toml")

    assert result == 0
    output = toml.loads(command_tester.io.fetch_output())
    assert output

    metadata = output["tool"]["valiant"]["report"]["metadata"]
    assert metadata["name"].lower() == "flask"
    assert metadata["version"] == "1.1.1"

    reports = output["tool"]["valiant"]["report"]["reports"]
    assert len(reports) == 3
    assert "safety" in reports
    assert "spdx" in reports
    assert "basic" in reports
コード例 #11
0
ファイル: test_about.py プロジェクト: pomes/valiant
def test_cli_about_json(
    app: Cli,
    valiant_app_name: str,
    valiant_version: str,
    valiant_license: str,
    valiant_url: str,
) -> None:
    """Test the static output from the `about` command - JSON output."""
    import json

    command = app.find("about")
    command_tester = CommandTester(command)
    result = command_tester.execute(args="--out json")

    assert result == 0
    output = json.loads(command_tester.io.fetch_output())

    assert len(output) == 4
    assert output["name"] == valiant_app_name
    assert output["version"] == valiant_version
    assert output["license"] == valiant_license
    assert output["url"] == valiant_url