示例#1
0
def test_patch_get_bad_date(mocker, args):
    mocker.patch("sps.request.fetch")
    args.date_to = "A B C"
    with pytest.raises(SystemExit):
        patch.get(args)

    args.date_to = ""
    args.date_from = "A B C"
    with pytest.raises(SystemExit):
        patch.get(args)
示例#2
0
def test_patch_get_date(mocker, args):
    mocker.patch("sps.request.fetch")
    args.date_from = "2020-06-01"
    args.date_to = "2020-12-31"
    patch.get(args)
    request.fetch.assert_called_with(format_url(args))
示例#3
0
def test_patch_get_severity(mocker, args):
    mocker.patch("sps.request.fetch")
    args.severity = "moderate"
    patch.get(args)
    request.fetch.assert_called_with(format_url(args))
示例#4
0
def test_patch_get_all_products(mocker, args):
    mocker.patch("sps.request.fetch")
    args.product = None
    patch.get(args)
    request.fetch.assert_called_with(format_url(args))
示例#5
0
def test_patch_get_pattern(mocker, args):
    mocker.patch("sps.request.fetch")
    args.pattern = "Legacy Module"
    patch.get(args)
    request.fetch.assert_called_with(format_url(args))
示例#6
0
def test_patch_get(mocker, args):
    mocker.patch("sps.request.fetch")
    patch.get(args)
    request.fetch.assert_called_with(format_url(args))
示例#7
0
def test_patch_good_response_from_scc(mocker, args, data):
    mocker.patch("sps.request.fetch")
    request.fetch.return_value = data
    assert patch.get(args) == data
示例#8
0
def test_patch_get_bad_response_from_scc(mocker, args):
    mocker.patch("sps.request.fetch")
    request.fetch.return_value = {}
    with pytest.raises(SystemExit):
        patch.get(args)
示例#9
0
文件: cli.py 项目: SweBarre/sps
def main():
    """The main program logic"""

    parser = create_parser()
    args = parser.parse_args()

    if args.command in ["product", "package", "patchproduct", "patch"]:
        table = PrettyTable()
        if args.command == "product":
            products_data = products.get(args.pattern, args.cache_file,
                                         args.no_cache, args.update_cache)
            table.field_names = ["id", "Name", "Edition", "Identifier", "Arch"]
            for product in products_data:
                table.add_row([
                    product["id"],
                    product["name"],
                    product["edition"],
                    product["identifier"],
                    product["architecture"],
                ])

        if args.command == "package":
            package_data = packages.get(args.product, args.pattern,
                                        args.cache_file)
            table.field_names = [
                "Name", "Version", "Release", "Arch", "Module"
            ]
            for package in package_data:
                module_line = ""
                for product in package["products"]:
                    module_line = "{},{}".format(module_line, product["name"])
                if args.exact_match and package["name"] == args.pattern:
                    table.add_row([
                        package["name"],
                        package["version"],
                        package["release"],
                        package["arch"],
                        module_line[1:],
                    ])
                elif not args.exact_match:
                    table.add_row([
                        package["name"],
                        package["version"],
                        package["release"],
                        package["arch"],
                        module_line[1:],
                    ])
        if args.command == "patchproduct":
            products_data = patchproducts.get(args.pattern, args.cache_file,
                                              args.no_cache, args.update_cache)
            table.field_names = ["Name", "Version", "Arch"]
            for product in products_data:
                table.add_row([
                    product["name"],
                    product["version"],
                    product["architecture"],
                ])
        if args.command == "patch":
            patches = patch.get(args)
            if args.detail:
                for p in patches["hits"]:
                    print(patch.format_detail(p))

                if patches["meta"]["total_hits"] > PATCH_WARN_NUMBER:
                    print_warn(
                        f"Your query has {patches['meta']['total_hits']} hits, you might want to refine your search criteria"
                    )
                print(
                    f"Page {patches['meta']['current_page']}/{patches['meta']['total_pages']}\t Hits: {patches['meta']['total_hits']}"
                )
                sys.exit(0)
            else:
                table.hrules = ALL
                table.field_names = [
                    "Severity",
                    "Name",
                    "Product",
                    "Arch",
                    "id",
                    "Released",
                ]
                for p in patches["hits"]:
                    table.add_row([
                        p["severity"],
                        p["title"],
                        "\n".join(p["product_friendly_names"]),
                        "\n".join(p["product_architectures"]),
                        p["ibs_id"],
                        p["issued_at"][:p["issued_at"].find("T")],
                    ])
                if patches["meta"]["total_hits"] > PATCH_WARN_NUMBER:
                    print("\n")
                    print_warn(
                        f"Your query has {patches['meta']['total_hits']} hits, you might want to refine your search criteria"
                    )
                print(
                    f"\nPage {patches['meta']['current_page']}/{patches['meta']['total_pages']}\t Hits: {patches['meta']['total_hits']}"
                )

        for name in table.field_names:
            table.align[name] = "l"
        table.border = not args.no_borders
        table.header = not args.no_header
        table.sortby = args.sort_table
        print(table)

    if args.command == "completion":
        print(completion.get(args.cache_file, args.shell))

    cacheages = cache.age(args.cache_file, args.cache_age)
    for key, value in cacheages.items():
        print_warn(f"The {key} cache is old, last updated {value}")