예제 #1
0
def test_cli_main_patch_detail(mocker, capsys, data, parser):
    mocker.patch("sps.cache.age")
    cache.age.return_value = {}
    mocker.patch("sps.patch.get")
    patch.get.return_value = data
    mocker.patch("sps.cli.create_parser")
    p = parser()
    p.detail = True
    cli.create_parser.return_value = p
    output = """Detailed patch information
---------------------------------------------------------------------------
Name:		Security update for the Linux Kernel
Id:		SUSE-SLE-HA-12-SP3-2020-1275
Severity:	important
Released:	2020-05-14
Details:
description
References
    bugzilla: 
              1056134
    cve     : 
              CVE-2020-11609
Products: SUSE Linux Enterprise High Availability Extension 12 SP3 
SUSE Linux Enterprise Server for SAP Applications 12 SP3
Architecture: ppc64le
Packages: 
          ocfs2-kmp-default-4.4.180-94.116.1.ppc64le.rpm
Page 1/9	 Hits: 81
"""
    with pytest.raises(SystemExit):
        cli.main()
    captured = capsys.readouterr()
    assert captured.out == output
예제 #2
0
def test_main_aged_cache_no_return(mocker, capsys, data):
    class parser_proxy:
        def parse_args(self):
            return Namespace(
                command="product",
                pattern=None,
                cache_file="fake-file-name",
                update_cache=False,
                no_cache=False,
                no_borders=False,
                no_header=False,
                sort_table="id",
                cache_age=60,
            )

    mocker.patch("sps.cli.PrettyTable", autospec=True)
    mocker.patch("sps.cli.create_parser", autospec=True)
    cli.create_parser.return_value = parser_proxy()
    mocker.patch("sps.products.get", autospec=True)
    products.get.return_value = {}
    mocker.patch("sps.cache.age", autospec=True)
    cache.age.return_value = {}
    cli.main()
    cache.age.assert_called_once_with("fake-file-name", 60)
    cache.age.return_value = {"testing": "date"}
    cli.main()
    captured = capsys.readouterr()
    assert (
        captured.err.strip() ==
        f"{helpers.CWARNING}Warning:{helpers.CRESET} The testing cache is old, last updated date"
    )
예제 #3
0
def test_cli_main_patch(mocker, capsys, data, parser):
    mocker.patch("sps.cache.age")
    cache.age.return_value = {}
    mocker.patch("sps.patch.get")
    patch.get.return_value = data
    mocker.patch("sps.cli.create_parser")
    p = parser()
    cli.create_parser.return_value = p
    output = "\nPage 1/9\t Hits: 81\n+-----------+--------------------------------------+----------------------------------------------------------+---------+------------------------------+------------+\n| Severity  | Name                                 | Product                                                  | Arch    | id                           | Released   |\n+-----------+--------------------------------------+----------------------------------------------------------+---------+------------------------------+------------+\n| important | Security update for the Linux Kernel | SUSE Linux Enterprise High Availability Extension 12 SP3 | ppc64le | SUSE-SLE-HA-12-SP3-2020-1275 | 2020-05-14 |\n|           |                                      | SUSE Linux Enterprise Server for SAP Applications 12 SP3 |         |                              |            |\n+-----------+--------------------------------------+----------------------------------------------------------+---------+------------------------------+------------+\n"

    cli.main()
    captured = capsys.readouterr()
    assert captured.out == output
예제 #4
0
def test_cli_main_patch_no_hits_warning(mocker, capsys, data, parser):
    mocker.patch("sps.cache.age")
    cache.age.return_value = {}
    mocker.patch("sps.patch.get")
    data["meta"]["total_hits"] = 499
    patch.get.return_value = data
    mocker.patch("sps.cli.create_parser")
    p = parser()
    cli.create_parser.return_value = p
    output = ""
    cli.main()
    captured = capsys.readouterr()
    assert captured.err.strip() == output
예제 #5
0
def test_cli_main_patch_to_many_hits_warning(mocker, data, parser):
    mocker.patch("sps.cache.age")
    cache.age.return_value = {}
    mocker.patch("sps.patch.get")
    data["meta"]["total_hits"] = 501
    patch.get.return_value = data
    mocker.patch("sps.cli.create_parser")
    p = parser()
    cli.create_parser.return_value = p
    mocker.patch("sps.cli.print_warn")
    cli.main()
    cli.print_warn.assert_called_with(
        "Your query has 501 hits, you might want to refine your search criteria"
    )
예제 #6
0
def test_main_product_output(mocker, capsys):
    class parser_proxy:
        def parse_args(self):
            return Namespace(
                command="product",
                pattern=None,
                cache_file="fake-file-name",
                update_cache=False,
                no_cache=False,
                no_borders=False,
                no_header=False,
                sort_table="id",
                cache_age=60,
            )

    data = {
        "data": [
            {
                "id": 1935,
                "name": "SUSE Linux Enterprise Desktop",
                "identifier": "SLED/15.2/x86_64",
                "type": "base",
                "free": False,
                "edition": "15 SP2",
                "architecture": "x86_64",
            },
        ]
    }

    mocker.patch("sps.cache.age", autospec=True)
    cache.age.return_value = {}
    mocker.patch("sps.products.get", autospec=True)
    products.get.return_value = data["data"]
    mocker.patch("sps.cli.create_parser", autospec=True)
    cli.create_parser.return_value = parser_proxy()

    output = """+------+-------------------------------+---------+------------------+--------+
| id   | Name                          | Edition | Identifier       | Arch   |
+------+-------------------------------+---------+------------------+--------+
| 1935 | SUSE Linux Enterprise Desktop | 15 SP2  | SLED/15.2/x86_64 | x86_64 |
+------+-------------------------------+---------+------------------+--------+
"""

    cli.main()
    captured = capsys.readouterr()
    assert captured.out == output
예제 #7
0
def test_main_completion(mocker):
    class parser_proxy:
        def parse_args(self):
            return Namespace(
                command="completion",
                cache_file="fake-file-name",
                shell="bash",
                cache_age=60,
            )

    mocker.patch("sps.cache.age", autospec=True)
    cache.age.return_values = {}
    mocker.patch("sps.cli.create_parser", autospec=True)
    cli.create_parser.return_value = parser_proxy()
    mocker.patch("sps.completion.get", autospec=True)
    completion.get.return_value = "\n"
    cli.main()
    completion.get.assert_called_with("fake-file-name", "bash")
예제 #8
0
def test_main_patchproduct_output(parser, data, mocker, capsys):
    mocker.patch("sps.cache.age")
    cache.age.return_value = {}
    mocker.patch("sps.patchproducts.get")
    patchproducts.get.return_value = data
    mocker.patch("sps.cli.create_parser")
    p = parser()
    cli.create_parser.return_value = p
    output = """+---------------------------------------------------+---------+---------+
| Name                                              | Version | Arch    |
+---------------------------------------------------+---------+---------+
| Development Tools Module                          | 15      | s390x   |
| Legacy Module                                     | 15 SP2  | aarch64 |
| SUSE Linux Enterprise Real Time Extension         | 12 SP1  | x86_64  |
| SUSE Linux Enterprise Server for SAP Applications | 15 SP2  | x86_64  |
+---------------------------------------------------+---------+---------+
"""
    cli.main()
    captured = capsys.readouterr()
    assert captured.out == output
예제 #9
0
def test_main_package_output(mocker, capsys):
    class parser_proxy:
        def parse_args(self):
            return Namespace(
                command="package",
                pattern="gvim",
                cache_file="fake-file-name",
                update_cache=False,
                product="1935",
                exact_match=False,
                no_borders=False,
                no_header=False,
                sort_table="Name",
                cache_age=60,
            )

    data = {
        "data": [
            {
                "id":
                19399264,
                "name":
                "gvim",
                "arch":
                "x86_64",
                "version":
                "8.0.1568",
                "release":
                "5.3.1",
                "products": [{
                    "id": 1967,
                    "name": "Desktop Applications Module",
                    "identifier":
                    "sle-module-desktop-applications/15.2/x86_64",
                    "type": "module",
                    "free": True,
                    "edition": "15 SP2",
                    "architecture": "x86_64",
                }],
            },
            {
                "id":
                19731289,
                "name":
                "gvim-debuginfo",
                "arch":
                "x86_64",
                "version":
                "8.0.1568",
                "release":
                "5.3.1",
                "products": [{
                    "id": 1967,
                    "name": "Desktop Applications Module",
                    "identifier":
                    "sle-module-desktop-applications/15.2/x86_64",
                    "type": "module",
                    "free": True,
                    "edition": "15 SP2",
                    "architecture": "x86_64",
                }],
            },
        ]
    }

    mocker.patch("sps.cache.age", autospec=True)
    cache.age.return_value = {}
    mocker.patch("sps.packages.get", autospec=True)
    packages.get.return_value = data["data"]
    mocker.patch("sps.cli.create_parser", autospec=True)
    cli.create_parser.return_value = parser_proxy()

    output = """+----------------+----------+---------+--------+-----------------------------+
| Name           | Version  | Release | Arch   | Module                      |
+----------------+----------+---------+--------+-----------------------------+
| gvim           | 8.0.1568 | 5.3.1   | x86_64 | Desktop Applications Module |
| gvim-debuginfo | 8.0.1568 | 5.3.1   | x86_64 | Desktop Applications Module |
+----------------+----------+---------+--------+-----------------------------+
"""

    cli.main()
    captured = capsys.readouterr()
    assert captured.out == output