From b964cac2778087f99ee6dd05520a36ebbc1984fa Mon Sep 17 00:00:00 2001 From: "John M. Horan" Date: Fri, 7 Jun 2024 19:03:50 -0700 Subject: [PATCH] Remove logging and messaging #365 Reference: https://github.com/nexB/purldb/issues/365 Signed-off-by: John M. Horan --- purldb-toolkit/src/purldb_toolkit/purlcli.py | 430 +++--------------- .../purlcli/expected_metadata_output.json | 10 +- .../data/purlcli/expected_urls_output.json | 47 +- .../purlcli/expected_urls_output_head.json | 79 +--- .../expected_urls_output_head_mock.json | 4 +- .../purlcli/expected_validate_output.json | 7 +- .../purlcli/expected_versions_output.json | 69 +-- purldb-toolkit/tests/test_purlcli.py | 384 ++-------------- purldb-toolkit/tests/test_purlcli_live.py | 338 ++------------ 9 files changed, 152 insertions(+), 1216 deletions(-) diff --git a/purldb-toolkit/src/purldb_toolkit/purlcli.py b/purldb-toolkit/src/purldb_toolkit/purlcli.py index 28d99e7d..29f1597b 100644 --- a/purldb-toolkit/src/purldb_toolkit/purlcli.py +++ b/purldb-toolkit/src/purldb_toolkit/purlcli.py @@ -8,23 +8,15 @@ # import json -import logging -import os import re from importlib.metadata import version -from pathlib import Path import click import requests from fetchcode.package import info -from fetchcode.package_versions import SUPPORTED_ECOSYSTEMS from fetchcode.package_versions import versions -from packageurl import PackageURL from packageurl.contrib import purl2url -LOG_FILE_LOCATION = os.path.join(os.path.expanduser("~"), "purlcli.log") -logger = logging.getLogger(__name__) - @click.group() def purlcli(): @@ -56,8 +48,7 @@ def purlcli(): ) def get_metadata(purls, output, file): """ - Given one or more PURLs, for each PURL, return a mapping of metadata - fetched from the fetchcode package.py info() function. + Fetch package metadata for a PURL. """ check_for_duplicate_input_sources(purls, file) if file: @@ -76,39 +67,22 @@ def get_metadata_details(purls, output, file, command_name): metadata_details = {} metadata_details["headers"] = [] metadata_details["packages"] = [] - metadata_warnings = {} - deduplicated_purls, duplicate_purls = deduplicate_purls(purls) - clear_log_file() + deduplicated_purls = deduplicate_purls(purls) for purl in deduplicated_purls: purl = purl.strip() if not purl: continue - metadata_purl_status = check_metadata_purl(purl) - if command_name == "metadata" and metadata_purl_status in [ - "validation_error", - "not_valid", - "valid_but_not_supported", - "not_in_upstream_repo", - ]: - metadata_warnings[purl] = metadata_purl_status - continue - if command_name == "metadata" and metadata_purl_status in [ - "valid_but_not_fully_supported", - "check_existence_not_supported", - ]: - metadata_warnings[purl] = metadata_purl_status metadata_collection = collect_metadata(purl) metadata_details["packages"].extend(metadata_collection) metadata_details["headers"] = construct_headers( deduplicated_purls=deduplicated_purls, - duplicate_purls=duplicate_purls, output=output, file=file, command_name=command_name, - purl_warnings=metadata_warnings, ) + return metadata_details @@ -124,45 +98,8 @@ def collect_metadata(purl): release_detail = release.to_dict() release_detail.move_to_end("purl", last=False) collected_metadata.append(release_detail) - return collected_metadata - -def check_metadata_purl(purl): - """ - Return a variable identifying the warning if (1) the input PURL is invalid, - (2) its type is not supported by `metadata` or (3) its existence was not - validated (e.g., "does not exist in the upstream repo"). This will be - reported by construct_headers() in the `warnings` field of the `header` - section of the JSON object returned by the `metadata` command. - """ - check_validation = validate_purl(purl) - if check_validation is None: - return "validation_error" - elif check_validation["valid"] == False: - return "not_valid" - - # This is manually constructed from a visual inspection of fetchcode/package.py. - metadata_supported_ecosystems = [ - "bitbucket", - "cargo", - "generic", - "github", - "gnu", - "npm", - "openssl", - "pypi", - "rubygems", - # NOTE: cocoapods support added subject to fetchcode/package.py PR approval and new release. - "cocoapods", - ] - metadata_purl = PackageURL.from_string(purl) - - if metadata_purl.type not in metadata_supported_ecosystems: - return "valid_but_not_supported" - elif check_validation["exists"] == False: - return "not_in_upstream_repo" - elif check_validation["exists"] == None: - return "check_existence_not_supported" + return collected_metadata def deduplicate_purls(purls): @@ -172,34 +109,21 @@ def deduplicate_purls(purls): """ reviewed = set() deduplicated_purls = [] - duplicate_purls = [] for purl in purls: purl = purl.strip() if purl not in reviewed: reviewed.add(purl) deduplicated_purls.append(purl) - else: - duplicate_purls.append(purl) - return deduplicated_purls, duplicate_purls - -def read_log_file(log_file_path): - log_file = log_file_path - if log_file.is_file(): - with open(log_file_path, "r") as log_file: - return log_file.readlines() - else: - return [] + return deduplicated_purls def construct_headers( deduplicated_purls=None, - duplicate_purls=None, output=None, file=None, command_name=None, head=None, - purl_warnings=None, ): """ Return a list comprising the `headers` content of the dictionary output. @@ -232,42 +156,10 @@ def construct_headers( options["--output"] = output.name headers_content["options"] = options - if command_name in ["metadata", "urls", "validate", "versions"]: - if duplicate_purls: - for duplicate in duplicate_purls: - logger.warning(f"Duplicate input PURL removed: {duplicate}") - - for purl in deduplicated_purls: - if not purl: - continue - warning_text = { - "error_fetching_purl": f"'error fetching {purl}'", - "validation_error": f"'{purl}' encountered a validation error", - "not_valid": f"'{purl}' not valid", - "valid_but_not_supported": f"'{purl}' not supported with `{command_name}` command", - "valid_but_not_fully_supported": f"'{purl}' not fully supported with `urls` command", - "not_in_upstream_repo": f"'{purl}' does not exist in the upstream repo", - "check_existence_not_supported": f"'check_existence' is not supported for '{purl}'", - } - if command_name in ["metadata", "urls", "validate", "versions"]: - purl_warning = purl_warnings.get(purl, None) - if purl_warning: - warning = warning_text[purl_warning] - logger.warning(warning) - continue - - log_file = Path(LOG_FILE_LOCATION) - log_file_contents = read_log_file(log_file) - if log_file_contents: - for line in log_file_contents: - if line.startswith("ERROR"): - errors.append(line[8:-1]) - elif line.startswith("WARNING"): - warnings.append(line[10:-1]) - headers_content["errors"] = errors headers_content["warnings"] = warnings headers.append(headers_content) + return headers @@ -300,8 +192,11 @@ def construct_headers( ) def get_urls(purls, output, file, head): """ - Given one or more PURLs, for each PURL, return a list of all known URLs - fetched from the packageurl-python purl2url.py code. + Return known URLs for a PURL. + + This includes the "download_url" which is the standard download URL, the "repo_download_url" + which is the download URL provided by the package repository, the "repo_url" which is the URL of + this package on the package repository. """ check_for_duplicate_input_sources(purls, file) if file: @@ -320,9 +215,7 @@ def get_urls_details(purls, output, file, head, command_name): urls_details = {} urls_details["headers"] = [] urls_details["packages"] = [] - urls_warnings = {} - deduplicated_purls, duplicate_purls = deduplicate_purls(purls) - clear_log_file() + deduplicated_purls = deduplicate_purls(purls) for purl in deduplicated_purls: url_detail = {} @@ -330,22 +223,6 @@ def get_urls_details(purls, output, file, head, command_name): purl = purl.strip() if not purl: continue - urls_purl_status = check_urls_purl(purl) - if command_name == "urls" and urls_purl_status in [ - "validation_error", - "not_valid", - "valid_but_not_supported", - "not_in_upstream_repo", - ]: - urls_warnings[purl] = urls_purl_status - continue - if command_name == "urls" and urls_purl_status in [ - "valid_but_not_fully_supported", - "check_existence_not_supported", - ]: - urls_warnings[purl] = urls_purl_status - - url_purl = PackageURL.from_string(purl) url_detail["download_url"] = purl2url.get_download_url(purl) if head: @@ -393,23 +270,18 @@ def get_urls_details(purls, output, file, head, command_name): urls_details["headers"] = construct_headers( deduplicated_purls=deduplicated_purls, - duplicate_purls=duplicate_purls, output=output, file=file, head=head, command_name=command_name, - purl_warnings=urls_warnings, ) + return urls_details def make_head_request(url_detail): """ - Make a head request and get request and return a dictionary containing - status code data for the incoming PURL URL. This returns both get and - head request status code data so the user can evaluate -- requests.get() - and requests.head() sometimes return different status codes and sometimes - return inaccurate codes, e.g., a 404 when the URL actually exists. + Return both get and head request status code data for each URL. """ if url_detail is None: return {"get_request": "N/A", "head_request": "N/A"} @@ -417,76 +289,13 @@ def make_head_request(url_detail): get_request_status_code = get_response.status_code head_response = requests.head(url_detail) head_request_status_code = head_response.status_code + return { "get_request": get_request_status_code, "head_request": head_request_status_code, } -def check_urls_purl(purl): - """ - If applicable, return a variable indicating that the input PURL is invalid, - or its type is not supported (or not fully supported) by `urls`, or it - does not exist in the upstream repo. - """ - check_validation = validate_purl(purl) - if check_validation is None: - return "validation_error" - results = check_validation - if results["valid"] == False: - return "not_valid" - - # Both of these lists are manually constructed from a visual inspection of - # packageurl-python/src/packageurl/contrib/purl2url.py. - # This list applies to the purl2url.py `repo_url` section: - urls_supported_ecosystems_repo_url = [ - "bitbucket", - "cargo", - # NOTE: Temp for cocoapods dev work in purl2url. Keep in the list uncommented -- I still need to respond to Tushar's comments but the real code work is done, now supported for repo_url. - "cocoapods", - "gem", - "github", - "gitlab", - "golang", - "hackage", - "npm", - "nuget", - "pypi", - "rubygems", - ] - # This list applies to the purl2url.py `download_url` section: - urls_supported_ecosystems_download_url = [ - "bitbucket", - "cargo", - "gem", - "github", - "gitlab", - "hackage", - "npm", - "nuget", - "rubygems", - ] - urls_purl = PackageURL.from_string(purl) - - if ( - urls_purl.type not in urls_supported_ecosystems_repo_url - and urls_purl.type not in urls_supported_ecosystems_download_url - ): - return "valid_but_not_supported" - if results["exists"] == False: - return "not_in_upstream_repo" - if ( - urls_purl.type in urls_supported_ecosystems_repo_url - and urls_purl.type not in urls_supported_ecosystems_download_url - ) or ( - urls_purl.type not in urls_supported_ecosystems_repo_url - and urls_purl.type in urls_supported_ecosystems_download_url - ): - return "valid_but_not_fully_supported" - if results["exists"] == None: - return "check_existence_not_supported" - - @purlcli.command(name="validate") @click.option( "--purl", @@ -510,7 +319,9 @@ def check_urls_purl(purl): ) def validate(purls, output, file): """ - Check the syntax and upstream repo status of one or more PURLs. + Validate PURL syntax and existence. + + Check that the syntax of a PURL is correct. Check that the PURL exists using the PurlDB. """ check_for_duplicate_input_sources(purls, file) if file: @@ -528,105 +339,41 @@ def get_validate_details(purls, output, file, command_name): """ validate_details = {} validate_details["headers"] = [] - validate_warnings = {} - deduplicated_purls, duplicate_purls = deduplicate_purls(purls) validate_details["packages"] = [] - clear_log_file() + deduplicated_purls = deduplicate_purls(purls) for purl in deduplicated_purls: purl = purl.strip() if not purl: continue - validated_purl_status = check_validate_purl(purl) - if command_name == "validate" and validated_purl_status in [ - "validation_error", - "not_valid", - "valid_but_not_supported", - "not_in_upstream_repo", - "check_existence_not_supported", - ]: - validate_warnings[purl] = validated_purl_status - if validated_purl_status: - # Move the `purl` key to the top. - original_validate_purl = validate_purl(purl) - reordered_validate_purl = { - "purl": original_validate_purl.pop("purl"), - **original_validate_purl, - } - validate_details["packages"].append(reordered_validate_purl) + + original_validate_purl = validate_purl(purl) + reordered_validate_purl = { + "purl": original_validate_purl.pop("purl"), + **original_validate_purl, + } + validate_details["packages"].append(reordered_validate_purl) validate_details["headers"] = construct_headers( deduplicated_purls=deduplicated_purls, - duplicate_purls=duplicate_purls, output=output, file=file, command_name=command_name, - purl_warnings=validate_warnings, ) - return validate_details - -def check_validate_purl(purl): - """ - As applicable, return a variable indicating that the input PURL is - valid/invalid or does not exist in the upstream repo. - """ - check_validation = validate_purl(purl) - if check_validation is None: - return "validation_error" - elif check_validation["valid"] == False: - return "not_valid" - elif check_validation["exists"] == False: - return "not_in_upstream_repo" - elif check_validation["exists"] == True: - return check_validation - elif check_validation["exists"] == None: - return "check_existence_not_supported" + return validate_details def validate_purl(purl): """ Return a JSON object containing data from the PurlDB `validate` endpoint regarding the validity of the input PURL. - - Based on packagedb.package_managers VERSION_API_CLASSES_BY_PACKAGE_TYPE - and packagedb/api.py class PurlValidateViewSet(viewsets.ViewSet) - -- and supported by testing the command -- it appears that the `validate` - command `check_existence` parameter supports the following PURL types: - - "cargo", - "composer", - "deb", - "gem", - "golang", - "hex", - "maven", - "npm", - "nuget", - "pypi", """ - logging.basicConfig( - level=logging.WARN, - format="%(levelname)s - %(message)s", - filename=LOG_FILE_LOCATION, - filemode="w", - ) - api_query = "https://public.purldb.io/api/validate/" request_body = {"purl": purl, "check_existence": True} + response = requests.get(api_query, params=request_body).json() - try: - response = requests.get(api_query, params=request_body).json() - except json.decoder.JSONDecodeError as e: - logger.error(f"validate_purl(): json.decoder.JSONDecodeError for '{purl}': {e}") - except Exception as e: - logger.error(f"'validate' endpoint error for '{purl}': {e}") - else: - if response is None: - logger.error( - f"'{purl}' -- response.status_code for None = {response.status_code}" - ) - return response + return response @purlcli.command(name="versions") @@ -652,7 +399,7 @@ def validate_purl(purl): ) def get_versions(purls, output, file): """ - Given one or more PURLs, return a list of all known versions for each PURL. + List all known versions for a PURL. """ check_for_duplicate_input_sources(purls, file) if file: @@ -671,116 +418,55 @@ def get_versions_details(purls, output, file, command_name): versions_details = {} versions_details["headers"] = [] versions_details["packages"] = [] - versions_warnings = {} - deduplicated_purls, duplicate_purls = deduplicate_purls(purls) - clear_log_file() - for purl in deduplicated_purls: - purl = purl.strip() - if not purl: + raw_purls = [] + for input_purl in purls: + raw_purl = re.split("[@,]+", input_purl)[0] + raw_purls.append(raw_purl) + + deduplicated_purls = deduplicate_purls(raw_purls) + for deduplicated_purl in deduplicated_purls: + deduplicated_purl = deduplicated_purl.strip() + if not deduplicated_purl: continue purl_data = {} - purl_data["purl"] = purl - versions_purl_status = check_versions_purl(purl) - if command_name == "versions" and versions_purl_status in [ - "validation_error", - "not_valid", - "valid_but_not_supported", - "not_in_upstream_repo", - ]: - versions_warnings[purl] = versions_purl_status - continue - if command_name == "versions" and versions_purl_status in [ - "valid_but_not_fully_supported", - "check_existence_not_supported", - ]: - versions_warnings[purl] = versions_purl_status - version_collection = collect_versions(purl) + purl_data["purl"] = deduplicated_purl + + version_collection = collect_versions(deduplicated_purl) versions_details["packages"].extend(version_collection) versions_details["headers"] = construct_headers( - deduplicated_purls=deduplicated_purls, - duplicate_purls=duplicate_purls, + deduplicated_purls=purls, output=output, file=file, command_name=command_name, - purl_warnings=versions_warnings, ) + return versions_details def collect_versions(purl): """ - Return a list of version objects collected from fetchcode/package_versions.py. - - We use `versions()` from fetchcode/package_versions.py, which keeps the - version (if any) of the input PURL in its output, so - "pkg:pypi/fetchcode@0.3.0" is returned as "pkg:pypi/fetchcode@0.3.0@0.1.0", - "pkg:pypi/fetchcode@0.3.0@0.2.0" etc. Thus, we remove any string starting - with `@` first. + Return a list of version objects for each input PURL. """ collected_versions = [] for package_version in list(versions(purl)): purl_version_data = {} purl_version = package_version.value - raw_purl = re.split("[@,]+", purl)[0] - nested_purl = raw_purl + "@" + f"{purl_version}" - pkg_ver_release_date = package_version.release_date - pkg_ver_release_date_no_time = pkg_ver_release_date.date() - - purl_version_data["purl"] = nested_purl + purl_version_data["purl"] = purl purl_version_data["version"] = f"{purl_version}" - purl_version_data["release_date"] = f"{pkg_ver_release_date_no_time}" - collected_versions.append(purl_version_data) - return collected_versions + pkg_ver_release_date_no_time = None + if package_version.release_date: + pkg_ver_release_date = package_version.release_date + pkg_ver_release_date_no_time = str(pkg_ver_release_date.date()) + purl_version_data["release_date"] = f"{pkg_ver_release_date_no_time}" -def check_versions_purl(purl): - """ - Return a variable identifying the message for printing to the console by - get_versions_details() if (1) the input PURL is invalid, (2) its type is not - supported by `versions` or (3) its existence was not validated (e.g., - "does not exist in the upstream repo"). This message will also be reported - by construct_headers() in the `warnings` field of the `header` section of - the JSON object returned by the `versions` command. - - Note for dev purposes: SUPPORTED_ECOSYSTEMS (imported from - fetchcode.package_versions) comprises the following types: - [ - "cargo", - "composer", - "conan", - "deb", - "gem", - "github", - "golang", - "hex", - "maven", - "npm", - "nuget", - "pypi", - ] - """ - check_validation = validate_purl(purl) - if check_validation is None: - return "validation_error" - elif check_validation["valid"] == False: - return "not_valid" - - supported = SUPPORTED_ECOSYSTEMS - versions_purl = PackageURL.from_string(purl) - if versions_purl.type not in supported: - return "valid_but_not_supported" - elif check_validation["exists"] == False: - return "not_in_upstream_repo" - elif check_validation["exists"] == None: - return "check_existence_not_supported" - # This handles the conflict between the `validate`` endpoint (treats - # both "pkg:deb/debian/2ping" and "pkg:deb/2ping" as valid) and - # fetchcode.package_versions versions() (returns None for "pkg:deb/2ping"). - elif versions(purl) is None: - return "valid_but_not_supported" + purl_version_data["release_date"] = pkg_ver_release_date_no_time + collected_versions.append(purl_version_data) + + return collected_versions def check_for_duplicate_input_sources(purls, file): @@ -790,11 +476,5 @@ def check_for_duplicate_input_sources(purls, file): raise click.UsageError("Use either purls or file.") -def clear_log_file(): - log_file = Path(LOG_FILE_LOCATION) - with open(log_file, "w"): - pass - - if __name__ == "__main__": purlcli() diff --git a/purldb-toolkit/tests/data/purlcli/expected_metadata_output.json b/purldb-toolkit/tests/data/purlcli/expected_metadata_output.json index 32df4492..794022cb 100644 --- a/purldb-toolkit/tests/data/purlcli/expected_metadata_output.json +++ b/purldb-toolkit/tests/data/purlcli/expected_metadata_output.json @@ -12,21 +12,13 @@ "pkg:pypi/fetchcode@0.3.0os=windows", "pkg:pypi/fetchcode@5.0.0", "pkg:cargo/banquo", - "pkg:nginx/nginx", - "pkg:gem/rails", "pkg:rubygems/rails" ], "--file": null, "--output": "" }, "errors": [], - "warnings": [ - "'pkg:pypi/fetchcode@0.3.0os=windows' does not exist in the upstream repo", - "'pkg:pypi/fetchcode@5.0.0' does not exist in the upstream repo", - "'pkg:nginx/nginx' not supported with `metadata` command", - "'pkg:gem/rails' not supported with `metadata` command", - "'check_existence' is not supported for 'pkg:rubygems/rails'" - ] + "warnings": [] } ], "packages": [ diff --git a/purldb-toolkit/tests/data/purlcli/expected_urls_output.json b/purldb-toolkit/tests/data/purlcli/expected_urls_output.json index c2bf50d7..4a940958 100644 --- a/purldb-toolkit/tests/data/purlcli/expected_urls_output.json +++ b/purldb-toolkit/tests/data/purlcli/expected_urls_output.json @@ -8,47 +8,20 @@ "--purl": [ "pkg:pypi/fetchcode", "pkg:pypi/fetchcode@0.3.0", - "pkg:pypi/fetchcode@5.0.0", "pkg:pypi/dejacode", "pkg:pypi/dejacode@5.0.0", "pkg:pypi/dejacode@5.0.0?os=windows", - "pkg:pypi/dejacode@5.0.0os=windows", - "pkg:pypi/dejacode@5.0.0?how_is_the_weather=rainy", - "pkg:pypi/dejacode@5.0.0#how/are/you", - "pkg:pypi/dejacode@10.0.0", "pkg:cargo/banquo", "pkg:cargo/socksprox", - "pkg:nginx/nginx", - "pkg:nginx/nginx@0.8.9?os=windows", "pkg:gem/bundler-sass", "pkg:rubygems/bundler-sass", - "pkg:pypi/matchcode", - "abcdefg", - "pkg/abc", "pkg:nuget/auth0-aspnet@1.1.0" ], "--file": null, "--output": "" }, "errors": [], - "warnings": [ - "'pkg:pypi/fetchcode' not fully supported with `urls` command", - "'pkg:pypi/fetchcode@0.3.0' not fully supported with `urls` command", - "'pkg:pypi/fetchcode@5.0.0' does not exist in the upstream repo", - "'pkg:pypi/dejacode' not fully supported with `urls` command", - "'pkg:pypi/dejacode@5.0.0' not fully supported with `urls` command", - "'pkg:pypi/dejacode@5.0.0?os=windows' not fully supported with `urls` command", - "'pkg:pypi/dejacode@5.0.0os=windows' does not exist in the upstream repo", - "'pkg:pypi/dejacode@5.0.0?how_is_the_weather=rainy' not fully supported with `urls` command", - "'pkg:pypi/dejacode@5.0.0#how/are/you' not fully supported with `urls` command", - "'pkg:pypi/dejacode@10.0.0' does not exist in the upstream repo", - "'pkg:nginx/nginx' not supported with `urls` command", - "'pkg:nginx/nginx@0.8.9?os=windows' not supported with `urls` command", - "'check_existence' is not supported for 'pkg:rubygems/bundler-sass'", - "'pkg:pypi/matchcode' does not exist in the upstream repo", - "'abcdefg' not valid", - "'pkg/abc' not valid" - ] + "warnings": [] } ], "packages": [ @@ -97,24 +70,6 @@ "repository_download_url": null, "repository_homepage_url": "https://pypi.org/project/dejacode/5.0.0/" }, - { - "purl": "pkg:pypi/dejacode@5.0.0?how_is_the_weather=rainy", - "download_url": null, - "inferred_urls": [ - "https://pypi.org/project/dejacode/5.0.0/" - ], - "repository_download_url": null, - "repository_homepage_url": "https://pypi.org/project/dejacode/5.0.0/" - }, - { - "purl": "pkg:pypi/dejacode@5.0.0#how/are/you", - "download_url": null, - "inferred_urls": [ - "https://pypi.org/project/dejacode/5.0.0/" - ], - "repository_download_url": null, - "repository_homepage_url": "https://pypi.org/project/dejacode/5.0.0/" - }, { "purl": "pkg:cargo/banquo", "download_url": null, diff --git a/purldb-toolkit/tests/data/purlcli/expected_urls_output_head.json b/purldb-toolkit/tests/data/purlcli/expected_urls_output_head.json index 2e8de8c1..0237229f 100644 --- a/purldb-toolkit/tests/data/purlcli/expected_urls_output_head.json +++ b/purldb-toolkit/tests/data/purlcli/expected_urls_output_head.json @@ -8,23 +8,13 @@ "--purl": [ "pkg:pypi/fetchcode", "pkg:pypi/fetchcode@0.3.0", - "pkg:pypi/fetchcode@5.0.0", "pkg:pypi/dejacode", "pkg:pypi/dejacode@5.0.0", "pkg:pypi/dejacode@5.0.0?os=windows", - "pkg:pypi/dejacode@5.0.0os=windows", - "pkg:pypi/dejacode@5.0.0?how_is_the_weather=rainy", - "pkg:pypi/dejacode@5.0.0#how/are/you", - "pkg:pypi/dejacode@10.0.0", "pkg:cargo/banquo", "pkg:cargo/socksprox", - "pkg:nginx/nginx", - "pkg:nginx/nginx@0.8.9?os=windows", "pkg:gem/bundler-sass", "pkg:rubygems/bundler-sass", - "pkg:pypi/matchcode", - "abcdefg", - "pkg/abc", "pkg:nuget/auth0-aspnet@1.1.0" ], "--file": null, @@ -32,24 +22,7 @@ "--output": "" }, "errors": [], - "warnings": [ - "'pkg:pypi/fetchcode' not fully supported with `urls` command", - "'pkg:pypi/fetchcode@0.3.0' not fully supported with `urls` command", - "'pkg:pypi/fetchcode@5.0.0' does not exist in the upstream repo", - "'pkg:pypi/dejacode' not fully supported with `urls` command", - "'pkg:pypi/dejacode@5.0.0' not fully supported with `urls` command", - "'pkg:pypi/dejacode@5.0.0?os=windows' not fully supported with `urls` command", - "'pkg:pypi/dejacode@5.0.0os=windows' does not exist in the upstream repo", - "'pkg:pypi/dejacode@5.0.0?how_is_the_weather=rainy' not fully supported with `urls` command", - "'pkg:pypi/dejacode@5.0.0#how/are/you' not fully supported with `urls` command", - "'pkg:pypi/dejacode@10.0.0' does not exist in the upstream repo", - "'pkg:nginx/nginx' not supported with `urls` command", - "'pkg:nginx/nginx@0.8.9?os=windows' not supported with `urls` command", - "'check_existence' is not supported for 'pkg:rubygems/bundler-sass'", - "'pkg:pypi/matchcode' does not exist in the upstream repo", - "'abcdefg' not valid", - "'pkg/abc' not valid" - ] + "warnings": [] } ], "packages": [ @@ -178,56 +151,6 @@ "head_request_status_code": 200 } }, - { - "purl": "pkg:pypi/dejacode@5.0.0?how_is_the_weather=rainy", - "download_url": { - "url": null, - "get_request_status_code": "N/A", - "head_request_status_code": "N/A" - }, - "inferred_urls": [ - { - "url": "https://pypi.org/project/dejacode/5.0.0/", - "get_request_status_code": 200, - "head_request_status_code": 200 - } - ], - "repository_download_url": { - "url": null, - "get_request_status_code": "N/A", - "head_request_status_code": "N/A" - }, - "repository_homepage_url": { - "url": "https://pypi.org/project/dejacode/5.0.0/", - "get_request_status_code": 200, - "head_request_status_code": 200 - } - }, - { - "purl": "pkg:pypi/dejacode@5.0.0#how/are/you", - "download_url": { - "url": null, - "get_request_status_code": "N/A", - "head_request_status_code": "N/A" - }, - "inferred_urls": [ - { - "url": "https://pypi.org/project/dejacode/5.0.0/", - "get_request_status_code": 200, - "head_request_status_code": 200 - } - ], - "repository_download_url": { - "url": null, - "get_request_status_code": "N/A", - "head_request_status_code": "N/A" - }, - "repository_homepage_url": { - "url": "https://pypi.org/project/dejacode/5.0.0/", - "get_request_status_code": 200, - "head_request_status_code": 200 - } - }, { "purl": "pkg:cargo/banquo", "download_url": { diff --git a/purldb-toolkit/tests/data/purlcli/expected_urls_output_head_mock.json b/purldb-toolkit/tests/data/purlcli/expected_urls_output_head_mock.json index 7de378fd..2c157d29 100644 --- a/purldb-toolkit/tests/data/purlcli/expected_urls_output_head_mock.json +++ b/purldb-toolkit/tests/data/purlcli/expected_urls_output_head_mock.json @@ -13,9 +13,7 @@ "--output": "" }, "errors": [], - "warnings": [ - "'pkg:pypi/fetchcode' not fully supported with `urls` command" - ] + "warnings": [] } ], "packages": [ diff --git a/purldb-toolkit/tests/data/purlcli/expected_validate_output.json b/purldb-toolkit/tests/data/purlcli/expected_validate_output.json index d1f74eba..de84f52d 100644 --- a/purldb-toolkit/tests/data/purlcli/expected_validate_output.json +++ b/purldb-toolkit/tests/data/purlcli/expected_validate_output.json @@ -20,12 +20,7 @@ "--output": "" }, "errors": [], - "warnings": [ - "'pkg:pypi/fetchcode@0.3.0os=windows' does not exist in the upstream repo", - "'pkg:pypi/fetchcode@5.0.0' does not exist in the upstream repo", - "'check_existence' is not supported for 'pkg:nginx/nginx'", - "'check_existence' is not supported for 'pkg:rubygems/rails'" - ] + "warnings": [] } ], "packages": [ diff --git a/purldb-toolkit/tests/data/purlcli/expected_versions_output.json b/purldb-toolkit/tests/data/purlcli/expected_versions_output.json index e9c6abf8..428979d9 100644 --- a/purldb-toolkit/tests/data/purlcli/expected_versions_output.json +++ b/purldb-toolkit/tests/data/purlcli/expected_versions_output.json @@ -12,128 +12,93 @@ "pkg:pypi/fetchcode@0.3.0os=windows", "pkg:pypi/fetchcode@5.0.0", "pkg:cargo/banquo", - "pkg:nginx/nginx", "pkg:hex/coherence@0.1.0" ], "--file": null, "--output": "" }, "errors": [], - "warnings": [ - "'pkg:pypi/fetchcode@0.3.0os=windows' does not exist in the upstream repo", - "'pkg:pypi/fetchcode@5.0.0' does not exist in the upstream repo", - "'pkg:nginx/nginx' not supported with `versions` command" - ] + "warnings": [] } ], "packages": [ { - "purl": "pkg:pypi/fetchcode@0.1.0", + "purl": "pkg:pypi/fetchcode", "version": "0.1.0", "release_date": "2021-08-25" }, { - "purl": "pkg:pypi/fetchcode@0.2.0", + "purl": "pkg:pypi/fetchcode", "version": "0.2.0", "release_date": "2022-09-14" }, { - "purl": "pkg:pypi/fetchcode@0.3.0", + "purl": "pkg:pypi/fetchcode", "version": "0.3.0", "release_date": "2023-12-18" }, { - "purl": "pkg:pypi/fetchcode@0.1.0", - "version": "0.1.0", - "release_date": "2021-08-25" - }, - { - "purl": "pkg:pypi/fetchcode@0.2.0", - "version": "0.2.0", - "release_date": "2022-09-14" - }, - { - "purl": "pkg:pypi/fetchcode@0.3.0", - "version": "0.3.0", - "release_date": "2023-12-18" - }, - { - "purl": "pkg:pypi/fetchcode@0.1.0", - "version": "0.1.0", - "release_date": "2021-08-25" - }, - { - "purl": "pkg:pypi/fetchcode@0.2.0", - "version": "0.2.0", - "release_date": "2022-09-14" - }, - { - "purl": "pkg:pypi/fetchcode@0.3.0", - "version": "0.3.0", - "release_date": "2023-12-18" - }, - { - "purl": "pkg:cargo/banquo@0.1.0", + "purl": "pkg:cargo/banquo", "version": "0.1.0", "release_date": "2024-02-07" }, { - "purl": "pkg:hex/coherence@0.8.0", + "purl": "pkg:hex/coherence", "version": "0.8.0", "release_date": "2023-09-22" }, { - "purl": "pkg:hex/coherence@0.5.2", + "purl": "pkg:hex/coherence", "version": "0.5.2", "release_date": "2018-09-03" }, { - "purl": "pkg:hex/coherence@0.5.1", + "purl": "pkg:hex/coherence", "version": "0.5.1", "release_date": "2018-08-28" }, { - "purl": "pkg:hex/coherence@0.5.0", + "purl": "pkg:hex/coherence", "version": "0.5.0", "release_date": "2017-08-02" }, { - "purl": "pkg:hex/coherence@0.4.0", + "purl": "pkg:hex/coherence", "version": "0.4.0", "release_date": "2017-07-03" }, { - "purl": "pkg:hex/coherence@0.3.1", + "purl": "pkg:hex/coherence", "version": "0.3.1", "release_date": "2016-11-27" }, { - "purl": "pkg:hex/coherence@0.3.0", + "purl": "pkg:hex/coherence", "version": "0.3.0", "release_date": "2016-08-28" }, { - "purl": "pkg:hex/coherence@0.2.0", + "purl": "pkg:hex/coherence", "version": "0.2.0", "release_date": "2016-07-30" }, { - "purl": "pkg:hex/coherence@0.1.3", + "purl": "pkg:hex/coherence", "version": "0.1.3", "release_date": "2016-07-19" }, { - "purl": "pkg:hex/coherence@0.1.2", + "purl": "pkg:hex/coherence", "version": "0.1.2", "release_date": "2016-07-12" }, { - "purl": "pkg:hex/coherence@0.1.1", + "purl": "pkg:hex/coherence", "version": "0.1.1", "release_date": "2016-07-11" }, { - "purl": "pkg:hex/coherence@0.1.0", + "purl": "pkg:hex/coherence", "version": "0.1.0", "release_date": "2016-07-11" } diff --git a/purldb-toolkit/tests/test_purlcli.py b/purldb-toolkit/tests/test_purlcli.py index 43def355..f4035125 100644 --- a/purldb-toolkit/tests/test_purlcli.py +++ b/purldb-toolkit/tests/test_purlcli.py @@ -55,9 +55,7 @@ def test_metadata_cli_no_input_sources(self): assert result.exit_code == 2 @mock.patch("purldb_toolkit.purlcli.collect_metadata") - @mock.patch("purldb_toolkit.purlcli.check_metadata_purl") - def test_metadata_details(self, mock_check_metadata_purl, mock_collect_metadata): - + def test_metadata_details(self, mock_collect_metadata): mock_collect_metadata.return_value = [ OrderedDict( [ @@ -222,8 +220,6 @@ def test_metadata_details(self, mock_check_metadata_purl, mock_collect_metadata) ), ] - mock_check_metadata_purl.return_value = None - expected_data = { "headers": [ { @@ -421,88 +417,6 @@ def test_metadata_details(self, mock_check_metadata_purl, mock_collect_metadata) assert purl_metadata_data == expected_data - @mock.patch("purldb_toolkit.purlcli.validate_purl") - def test_check_metadata_purl(self, mock_validate_purl): - mock_validate_purl.return_value = { - "valid": True, - "exists": None, - "message": "The provided PackageURL is valid, but `check_existence` is not supported for this package type.", - "purl": "pkg:rubygems/bundler-sass", - } - input_purl = "pkg:rubygems/bundler-sass" - expected = "check_existence_not_supported" - purl_metadata = purlcli.check_metadata_purl(input_purl) - - assert purl_metadata == expected - - @mock.patch("purldb_toolkit.purlcli.validate_purl") - def test_check_metadata_purl_multiple(self, mock_validate_purl): - mock_validate_purl.side_effect = [ - { - "valid": True, - "exists": True, - "message": "The provided Package URL is valid, and the package exists in the upstream repo.", - "purl": "pkg:pypi/fetchcode", - }, - { - "valid": True, - "exists": True, - "message": "The provided Package URL is valid, and the package exists in the upstream repo.", - "purl": "pkg:gem/bundler-sass", - }, - { - "valid": True, - "exists": None, - "message": "The provided PackageURL is valid, but `check_existence` is not supported for this package type.", - "purl": "pkg:rubygems/bundler-sass", - }, - { - "valid": True, - "exists": None, - "message": "The provided PackageURL is valid, but `check_existence` is not supported for this package type.", - "purl": "pkg:nginx/nginx", - }, - { - "valid": True, - "exists": False, - "message": "The provided PackageURL is valid, but does not exist in the upstream repo.", - "purl": "pkg:pypi/zzzzz", - }, - { - "valid": False, - "exists": None, - "message": "The provided PackageURL is not valid.", - "purl": "pkg:pypi/?fetchcode", - }, - { - "valid": False, - "exists": None, - "message": "The provided PackageURL is not valid.", - "purl": "zzzzz", - }, - { - "valid": True, - "exists": True, - "message": "The provided Package URL is valid, and the package exists in the upstream repo.", - "purl": "pkg:maven/axis/axis@1.0", - }, - ] - - input_purls_and_expected_states = [ - ["pkg:pypi/fetchcode", None], - ["pkg:gem/bundler-sass", "valid_but_not_supported"], - ["pkg:rubygems/bundler-sass", "check_existence_not_supported"], - ["pkg:nginx/nginx", "valid_but_not_supported"], - ["pkg:pypi/zzzzz", "not_in_upstream_repo"], - ["pkg:pypi/?fetchcode", "not_valid"], - ["zzzzz", "not_valid"], - ["pkg:maven/axis/axis@1.0", "valid_but_not_supported"], - ] - - for input_purl, expected_state in input_purls_and_expected_states: - purl_metadata = purlcli.check_metadata_purl(input_purl) - assert purl_metadata == expected_state - def test_deduplicate_purls(self): input_purls = [ "pkg:pypi/fetchcode@0.1.0", @@ -515,14 +429,7 @@ def test_deduplicate_purls(self): ] actual_output = purlcli.deduplicate_purls(input_purls) expected_output = ( - ["pkg:pypi/fetchcode@0.1.0", "pkg:pypi/fetchcode@0.2.0"], - [ - "pkg:pypi/fetchcode@0.1.0", - "pkg:pypi/fetchcode@0.1.0", - "pkg:pypi/fetchcode@0.1.0", - "pkg:pypi/fetchcode@0.1.0", - "pkg:pypi/fetchcode@0.2.0", - ], + ["pkg:pypi/fetchcode@0.1.0", "pkg:pypi/fetchcode@0.2.0"] ) assert actual_output == expected_output @@ -558,37 +465,19 @@ def test_deduplicate_purls(self): }, "tool_name": "purlcli", "tool_version": "0.1.0", - "warnings": [ - "Duplicate input PURL removed: pkg:pypi/fetchcode@0.1.0", - "Duplicate input PURL removed: pkg:pypi/fetchcode@0.1.0", - "Duplicate input PURL removed: pkg:pypi/fetchcode@0.1.0", - "Duplicate input PURL removed: pkg:pypi/fetchcode@0.1.0", - "Duplicate input PURL removed: pkg:pypi/fetchcode@0.2.0", - ], + "warnings": [], } ], ), ], ) - @mock.patch("purldb_toolkit.purlcli.read_log_file") - def test_deduplicate_purls_construct_headers( - self, mock_read_log_file, test_input, expected - ): - mock_read_log_file.return_value = [ - "WARNING - Duplicate input PURL removed: pkg:pypi/fetchcode@0.1.0\n", - "WARNING - Duplicate input PURL removed: pkg:pypi/fetchcode@0.1.0\n", - "WARNING - Duplicate input PURL removed: pkg:pypi/fetchcode@0.1.0\n", - "WARNING - Duplicate input PURL removed: pkg:pypi/fetchcode@0.1.0\n", - "WARNING - Duplicate input PURL removed: pkg:pypi/fetchcode@0.2.0\n", - ] - + def test_deduplicate_purls_construct_headers(self, test_input, expected): metadata_headers = purlcli.construct_headers( test_input, output="", file="", command_name="metadata", head=None, - purl_warnings={}, ) cli_test_utils.streamline_headers(expected) @@ -622,27 +511,19 @@ def test_deduplicate_purls_construct_headers( }, "tool_name": "purlcli", "tool_version": "0.1.0", - "warnings": [ - "'pkg:gem/bundler-sass' not supported with `metadata` command" - ], + "warnings": [], } ], ), ], ) - @mock.patch("purldb_toolkit.purlcli.read_log_file") - def test_construct_headers(self, mock_read_log_file, test_input, expected): - mock_read_log_file.return_value = [ - "WARNING - 'pkg:gem/bundler-sass' not supported with `metadata` command\n", - ] - + def test_construct_headers(self, test_input, expected): metadata_headers = purlcli.construct_headers( test_input, output="", file="", command_name="metadata", head=None, - purl_warnings={"pkg:gem/bundler-sass": "valid_but_not_supported"}, ) cli_test_utils.streamline_headers(expected) @@ -652,9 +533,8 @@ def test_construct_headers(self, mock_read_log_file, test_input, expected): class TestPURLCLI_urls(object): - @mock.patch("purldb_toolkit.purlcli.read_log_file") @mock.patch("purldb_toolkit.purlcli.make_head_request") - def test_urls_cli_head(self, mock_make_head_request, mock_read_log_file): + def test_urls_cli_head(self, mock_make_head_request): """ Test the `urls` command with actual and expected JSON output files. """ @@ -671,10 +551,6 @@ def test_urls_cli_head(self, mock_make_head_request, mock_read_log_file): {"head_request": 200}, ] - mock_read_log_file.return_value = [ - "WARNING - 'pkg:pypi/fetchcode' not fully supported with `urls` command\n", - ] - expected_result_file = test_env.get_test_loc( "purlcli/expected_urls_output_head_mock.json" ) @@ -763,15 +639,7 @@ def test_urls_cli_no_input_sources(self): assert "Use either purls or file." in result.output assert result.exit_code == 2 - @mock.patch("purldb_toolkit.purlcli.read_log_file") - @mock.patch("purldb_toolkit.purlcli.check_urls_purl") - def test_urls_details(self, mock_check_urls_purl, mock_read_log_file): - mock_check_urls_purl.return_value = "valid_but_not_fully_supported" - - mock_read_log_file.return_value = [ - "WARNING = 'pkg:pypi/fetchcode' not fully supported with `urls` command\n", - ] - + def test_urls_details(self): expected_data = { "headers": [ { @@ -784,9 +652,7 @@ def test_urls_details(self, mock_check_urls_purl, mock_read_log_file): "--output": "", }, "errors": [], - "warnings": [ - "'pkg:pypi/fetchcode' not fully supported with `urls` command" - ], + "warnings": [], } ], "packages": [ @@ -816,21 +682,6 @@ def test_urls_details(self, mock_check_urls_purl, mock_read_log_file): assert purl_urls == expected_data - @mock.patch("purldb_toolkit.purlcli.validate_purl") - def test_check_urls_purl(self, mock_validate_purl): - mock_validate_purl.return_value = { - "valid": True, - "exists": True, - "message": "The provided Package URL is valid, and the package exists in the upstream repo.", - "purl": "pkg:pypi/fetchcode", - } - - input_purl = "pkg:pypi/fetchcode" - expected = "valid_but_not_fully_supported" - purl_urls = purlcli.check_urls_purl(input_purl) - - assert purl_urls == expected - @mock.patch("requests.get") @mock.patch("requests.head") def test_validate_purl_mock_requests_get_and_head( @@ -873,72 +724,48 @@ def mock_requests_get_return_func(): class TestPURLCLI_versions(object): - @mock.patch("purldb_toolkit.purlcli.read_log_file") - @mock.patch("purldb_toolkit.purlcli.collect_versions") - @mock.patch("purldb_toolkit.purlcli.check_versions_purl") - def test_versions_details_multiple( - self, mock_check_versions_purl, mock_collect_versions, mock_read_log_file - ): - - mock_check_versions_purl.side_effect = [ - None, - None, - "valid_but_not_supported", - "valid_but_not_supported", - None, - "not_valid", - ] + @mock.patch("purldb_toolkit.purlcli.collect_versions") + def test_versions_details_multiple(self, mock_collect_versions): mock_collect_versions.side_effect = [ [ { - "purl": "pkg:pypi/fetchcode@0.1.0", + "purl": "pkg:pypi/fetchcode", "version": "0.1.0", "release_date": "2021-08-25", }, { - "purl": "pkg:pypi/fetchcode@0.2.0", + "purl": "pkg:pypi/fetchcode", "version": "0.2.0", "release_date": "2022-09-14", }, { - "purl": "pkg:pypi/fetchcode@0.3.0", + "purl": "pkg:pypi/fetchcode", "version": "0.3.0", "release_date": "2023-12-18", }, ], [ { - "purl": "pkg:gem/bundler-sass@0.1.2", + "purl": "pkg:gem/bundler-sass", "version": "0.1.2", "release_date": "2013-12-11", } ], [ { - "purl": "pkg:cargo/socksprox@0.1.1", + "purl": "pkg:cargo/socksprox", "release_date": "2024-02-07", "version": "0.1.1", }, { - "purl": "pkg:cargo/socksprox@0.1.0", + "purl": "pkg:cargo/socksprox", "release_date": "2024-02-07", "version": "0.1.0", }, ], ] - mock_read_log_file.side_effect = [ - [], - [], - [ - "WARNING - 'pkg:rubygems/bundler-sass' not supported with `versions` command\n", - ], - ["WARNING - 'pkg:nginx/nginx' not supported with `versions` command\n"], - [], - ["WARNING - 'pkg:pypi/?fetchcode' not valid\n"], - ] - input_purls_and_expected_purl_data = [ [ ["pkg:pypi/fetchcode"], @@ -959,17 +786,17 @@ def test_versions_details_multiple( ], "packages": [ { - "purl": "pkg:pypi/fetchcode@0.1.0", + "purl": "pkg:pypi/fetchcode", "version": "0.1.0", "release_date": "2021-08-25", }, { - "purl": "pkg:pypi/fetchcode@0.2.0", + "purl": "pkg:pypi/fetchcode", "version": "0.2.0", "release_date": "2022-09-14", }, { - "purl": "pkg:pypi/fetchcode@0.3.0", + "purl": "pkg:pypi/fetchcode", "version": "0.3.0", "release_date": "2023-12-18", }, @@ -995,57 +822,13 @@ def test_versions_details_multiple( ], "packages": [ { - "purl": "pkg:gem/bundler-sass@0.1.2", + "purl": "pkg:gem/bundler-sass", "version": "0.1.2", "release_date": "2013-12-11", } ], }, ], - [ - ["pkg:rubygems/bundler-sass"], - { - "headers": [ - { - "tool_name": "purlcli", - "tool_version": "0.2.0", - "options": { - "command": "versions", - "--purl": ["pkg:rubygems/bundler-sass"], - "--file": None, - "--output": "", - }, - "errors": [], - "warnings": [ - "'pkg:rubygems/bundler-sass' not supported with `versions` command" - ], - } - ], - "packages": [], - }, - ], - [ - ["pkg:nginx/nginx"], - { - "headers": [ - { - "tool_name": "purlcli", - "tool_version": "0.2.0", - "options": { - "command": "versions", - "--purl": ["pkg:nginx/nginx"], - "--file": None, - "--output": "", - }, - "errors": [], - "warnings": [ - "'pkg:nginx/nginx' not supported with `versions` command" - ], - } - ], - "packages": [], - }, - ], [ ["pkg:cargo/socksprox"], { @@ -1065,38 +848,18 @@ def test_versions_details_multiple( ], "packages": [ { - "purl": "pkg:cargo/socksprox@0.1.1", + "purl": "pkg:cargo/socksprox", "version": "0.1.1", "release_date": "2024-02-07", }, { - "purl": "pkg:cargo/socksprox@0.1.0", + "purl": "pkg:cargo/socksprox", "version": "0.1.0", "release_date": "2024-02-07", }, ], }, ], - [ - ["pkg:pypi/?fetchcode"], - { - "headers": [ - { - "tool_name": "purlcli", - "tool_version": "0.2.0", - "options": { - "command": "versions", - "--purl": ["pkg:pypi/?fetchcode"], - "--file": None, - "--output": "", - }, - "errors": [], - "warnings": ["'pkg:pypi/?fetchcode' not valid"], - } - ], - "packages": [], - }, - ], ] output = "" @@ -1114,33 +877,25 @@ def test_versions_details_multiple( assert purl_versions_data == expected_data @mock.patch("purldb_toolkit.purlcli.collect_versions") - @mock.patch("purldb_toolkit.purlcli.check_versions_purl") - def test_versions_details( - self, - mock_check_versions_purl, - mock_collect_versions, - ): - + def test_versions_details(self, mock_collect_versions): mock_collect_versions.return_value = [ { - "purl": "pkg:pypi/fetchcode@0.1.0", + "purl": "pkg:pypi/fetchcode", "version": "0.1.0", "release_date": "2021-08-25", }, { - "purl": "pkg:pypi/fetchcode@0.2.0", + "purl": "pkg:pypi/fetchcode", "version": "0.2.0", "release_date": "2022-09-14", }, { - "purl": "pkg:pypi/fetchcode@0.3.0", + "purl": "pkg:pypi/fetchcode", "version": "0.3.0", "release_date": "2023-12-18", }, ] - mock_check_versions_purl.return_value = None - expected_data = { "headers": [ { @@ -1158,17 +913,17 @@ def test_versions_details( ], "packages": [ { - "purl": "pkg:pypi/fetchcode@0.1.0", + "purl": "pkg:pypi/fetchcode", "version": "0.1.0", "release_date": "2021-08-25", }, { - "purl": "pkg:pypi/fetchcode@0.2.0", + "purl": "pkg:pypi/fetchcode", "version": "0.2.0", "release_date": "2022-09-14", }, { - "purl": "pkg:pypi/fetchcode@0.3.0", + "purl": "pkg:pypi/fetchcode", "version": "0.3.0", "release_date": "2023-12-18", }, @@ -1189,85 +944,6 @@ def test_versions_details( ) assert purl_versions_data == expected_data - @mock.patch("purldb_toolkit.purlcli.validate_purl") - def test_check_versions_purl_multiple(self, mock_validate_purl): - mock_validate_purl.side_effect = [ - { - "valid": True, - "exists": True, - "message": "The provided Package URL is valid, and the package exists in the upstream repo.", - "purl": "pkg:pypi/fetchcode", - }, - { - "valid": True, - "exists": True, - "message": "The provided Package URL is valid, and the package exists in the upstream repo.", - "purl": "pkg:gem/bundler-sass", - }, - { - "valid": True, - "exists": None, - "message": "The provided PackageURL is valid, but `check_existence` is not supported for this package type.", - "purl": "pkg:rubygems/bundler-sass", - }, - { - "valid": True, - "exists": None, - "message": "The provided PackageURL is valid, but `check_existence` is not supported for this package type.", - "purl": "pkg:nginx/nginx", - }, - { - "valid": True, - "exists": False, - "message": "The provided PackageURL is valid, but does not exist in the upstream repo.", - "purl": "pkg:pypi/zzzzz", - }, - { - "valid": False, - "exists": None, - "message": "The provided PackageURL is not valid.", - "purl": "pkg:pypi/?fetchcode", - }, - { - "valid": False, - "exists": None, - "message": "The provided PackageURL is not valid.", - "purl": "zzzzz", - }, - { - "valid": True, - "exists": True, - "message": "The provided Package URL is valid, and the package exists in the upstream repo.", - "purl": "pkg:maven/axis/axis@1.0", - }, - ] - input_purls_and_expected_states = [ - ["pkg:pypi/fetchcode", None], - ["pkg:gem/bundler-sass", None], - ["pkg:rubygems/bundler-sass", "valid_but_not_supported"], - ["pkg:nginx/nginx", "valid_but_not_supported"], - ["pkg:pypi/zzzzz", "not_in_upstream_repo"], - ["pkg:pypi/?fetchcode", "not_valid"], - ["zzzzz", "not_valid"], - ["pkg:maven/axis/axis@1.0", None], - ] - for input_purl, expected_state in input_purls_and_expected_states: - purl_versions = purlcli.check_versions_purl(input_purl) - assert purl_versions == expected_state - - @mock.patch("purldb_toolkit.purlcli.validate_purl") - def test_check_versions_purl(self, mock_validate_purl): - mock_validate_purl.return_value = { - "valid": True, - "exists": None, - "message": "The provided PackageURL is valid, but `check_existence` is not supported for this package type.", - "purl": "pkg:rubygems/bundler-sass", - } - input_purl = "pkg:rubygems/bundler-sass" - purl_versions = purlcli.check_versions_purl(input_purl) - expected = "valid_but_not_supported" - assert purl_versions == expected - def streamline_metadata_packages(packages): """ diff --git a/purldb-toolkit/tests/test_purlcli_live.py b/purldb-toolkit/tests/test_purlcli_live.py index 372b7bab..53765375 100644 --- a/purldb-toolkit/tests/test_purlcli_live.py +++ b/purldb-toolkit/tests/test_purlcli_live.py @@ -25,8 +25,7 @@ class TestPURLCLI_metadata(object): - @mock.patch("purldb_toolkit.purlcli.read_log_file") - def test_metadata_cli(self, mock_read_log_file): + def test_metadata_cli(self): """ Test the `metadata` command with actual and expected JSON output files. @@ -34,14 +33,6 @@ def test_metadata_cli(self, mock_read_log_file): because the `--output` values (paths) differ due to the use of temporary files, and therefore we test a list of relevant key-value pairs. """ - mock_read_log_file.return_value = [ - "WARNING - 'pkg:pypi/fetchcode@0.3.0os=windows' does not exist in the upstream repo\n", - "WARNING - 'pkg:pypi/fetchcode@5.0.0' does not exist in the upstream repo\n", - "WARNING - 'pkg:nginx/nginx' not supported with `metadata` command\n", - "WARNING - 'pkg:gem/rails' not supported with `metadata` command\n", - "WARNING - 'check_existence' is not supported for 'pkg:rubygems/rails'\n", - ] - expected_result_file = test_env.get_test_loc( "purlcli/expected_metadata_output.json" ) @@ -60,10 +51,6 @@ def test_metadata_cli(self, mock_read_log_file): "--purl", "pkg:cargo/banquo", "--purl", - "pkg:nginx/nginx", - "--purl", - "pkg:gem/rails", - "--purl", "pkg:rubygems/rails", "--output", actual_result_file, @@ -175,12 +162,16 @@ def test_metadata_details(self): ("version", None), ("qualifiers", OrderedDict()), ("subpath", None), + ("repository_homepage_url", None), + ("repository_download_url", None), + ("api_data_url", None), ("primary_language", None), ("description", None), ("release_date", None), ("parties", []), ("keywords", []), ("homepage_url", "https://github.com/nexB/fetchcode"), + ("download_url", None), ("api_url", "https://pypi.org/pypi/fetchcode/json"), ("size", None), ("sha1", None), @@ -188,6 +179,7 @@ def test_metadata_details(self): ("sha256", None), ("sha512", None), ("bug_tracking_url", None), + ("code_view_url", None), ("vcs_url", None), ("copyright", None), ("license_expression", None), @@ -197,9 +189,6 @@ def test_metadata_details(self): ("dependencies", []), ("contains_source_code", None), ("source_packages", []), - ("repository_homepage_url", None), - ("repository_download_url", None), - ("api_data_url", None), ] ), OrderedDict( @@ -211,12 +200,19 @@ def test_metadata_details(self): ("version", "0.1.0"), ("qualifiers", OrderedDict()), ("subpath", None), + ("repository_homepage_url", None), + ("repository_download_url", None), + ("api_data_url", None), ("primary_language", None), ("description", None), ("release_date", None), ("parties", []), ("keywords", []), ("homepage_url", "https://github.com/nexB/fetchcode"), + ( + "download_url", + "https://files.pythonhosted.org/packages/19/a0/c90e5ba4d71ea1a1a89784f6d839ffb0dbf32d270cba04d5602188cb3713/fetchcode-0.1.0-py3-none-any.whl", + ), ("api_url", "https://pypi.org/pypi/fetchcode/json"), ("size", None), ("sha1", None), @@ -224,6 +220,7 @@ def test_metadata_details(self): ("sha256", None), ("sha512", None), ("bug_tracking_url", None), + ("code_view_url", None), ("vcs_url", None), ("copyright", None), ("license_expression", None), @@ -233,9 +230,6 @@ def test_metadata_details(self): ("dependencies", []), ("contains_source_code", None), ("source_packages", []), - ("repository_homepage_url", None), - ("repository_download_url", None), - ("api_data_url", None), ] ), OrderedDict( @@ -247,12 +241,19 @@ def test_metadata_details(self): ("version", "0.2.0"), ("qualifiers", OrderedDict()), ("subpath", None), + ("repository_homepage_url", None), + ("repository_download_url", None), + ("api_data_url", None), ("primary_language", None), ("description", None), ("release_date", None), ("parties", []), ("keywords", []), ("homepage_url", "https://github.com/nexB/fetchcode"), + ( + "download_url", + "https://files.pythonhosted.org/packages/d7/e9/96e9302e84e326b3c10a40c1723f21f4db96b557a17c6871e7a4c6336906/fetchcode-0.2.0-py3-none-any.whl", + ), ("api_url", "https://pypi.org/pypi/fetchcode/json"), ("size", None), ("sha1", None), @@ -260,6 +261,7 @@ def test_metadata_details(self): ("sha256", None), ("sha512", None), ("bug_tracking_url", None), + ("code_view_url", None), ("vcs_url", None), ("copyright", None), ("license_expression", None), @@ -269,9 +271,6 @@ def test_metadata_details(self): ("dependencies", []), ("contains_source_code", None), ("source_packages", []), - ("repository_homepage_url", None), - ("repository_download_url", None), - ("api_data_url", None), ] ), OrderedDict( @@ -283,12 +282,19 @@ def test_metadata_details(self): ("version", "0.3.0"), ("qualifiers", OrderedDict()), ("subpath", None), + ("repository_homepage_url", None), + ("repository_download_url", None), + ("api_data_url", None), ("primary_language", None), ("description", None), ("release_date", None), ("parties", []), ("keywords", []), ("homepage_url", "https://github.com/nexB/fetchcode"), + ( + "download_url", + "https://files.pythonhosted.org/packages/8d/fb/e45da0abf63504c3f88ad02537dc9dc64ea5206b09ce29cfb8191420d678/fetchcode-0.3.0-py3-none-any.whl", + ), ("api_url", "https://pypi.org/pypi/fetchcode/json"), ("size", None), ("sha1", None), @@ -296,6 +302,7 @@ def test_metadata_details(self): ("sha256", None), ("sha512", None), ("bug_tracking_url", None), + ("code_view_url", None), ("vcs_url", None), ("copyright", None), ("license_expression", None), @@ -305,9 +312,6 @@ def test_metadata_details(self): ("dependencies", []), ("contains_source_code", None), ("source_packages", []), - ("repository_homepage_url", None), - ("repository_download_url", None), - ("api_data_url", None), ] ), ], @@ -334,43 +338,6 @@ def test_metadata_details(self): assert purl_metadata_data["headers"] == expected_data["headers"] compare_packages(expected_data, purl_metadata_data) - @pytest.mark.parametrize( - "test_input,expected", - [ - ( - ["pkg:pypi/fetchcode"], - None, - ), - ( - ["pkg:gem/bundler-sass"], - "valid_but_not_supported", - ), - ( - ["pkg:rubygems/bundler-sass"], - "check_existence_not_supported", - ), - ( - ["pkg:nginx/nginx"], - "valid_but_not_supported", - ), - ( - ["pkg:pypi/zzzzz"], - "not_in_upstream_repo", - ), - ( - ["pkg:pypi/?fetchcode"], - "not_valid", - ), - ( - ["zzzzz"], - "not_valid", - ), - ], - ) - def test_check_metadata_purl(self, test_input, expected): - purl_metadata = purlcli.check_metadata_purl(test_input[0]) - assert purl_metadata == expected - @pytest.mark.parametrize( "test_input,expected", [ @@ -397,27 +364,19 @@ def test_check_metadata_purl(self, test_input, expected): }, "tool_name": "purlcli", "tool_version": "0.2.0", - "warnings": [ - "'pkg:gem/bundler-sass' not supported with `metadata` command" - ], + "warnings": [], } ], ), ], ) - @mock.patch("purldb_toolkit.purlcli.read_log_file") - def test_construct_headers(self, mock_read_log_file, test_input, expected): - mock_read_log_file.return_value = [ - "WARNING - 'pkg:gem/bundler-sass' not supported with `metadata` command\n", - ] - + def test_construct_headers(self, test_input, expected): metadata_headers = purlcli.construct_headers( test_input, output="", file="", command_name="metadata", head=None, - purl_warnings={"pkg:gem/bundler-sass": "valid_but_not_supported"}, ) cli_test_utils.streamline_headers(expected) cli_test_utils.streamline_headers(metadata_headers) @@ -426,30 +385,10 @@ def test_construct_headers(self, mock_read_log_file, test_input, expected): class TestPURLCLI_urls(object): - @mock.patch("purldb_toolkit.purlcli.read_log_file") - def test_urls_cli(self, mock_read_log_file): + def test_urls_cli(self): """ Test the `urls` command with actual and expected JSON output files. """ - mock_read_log_file.return_value = [ - "WARNING - 'pkg:pypi/fetchcode' not fully supported with `urls` command\n", - "WARNING - 'pkg:pypi/fetchcode@0.3.0' not fully supported with `urls` command\n", - "WARNING - 'pkg:pypi/fetchcode@5.0.0' does not exist in the upstream repo\n", - "WARNING - 'pkg:pypi/dejacode' not fully supported with `urls` command\n", - "WARNING - 'pkg:pypi/dejacode@5.0.0' not fully supported with `urls` command\n", - "WARNING - 'pkg:pypi/dejacode@5.0.0?os=windows' not fully supported with `urls` command\n", - "WARNING - 'pkg:pypi/dejacode@5.0.0os=windows' does not exist in the upstream repo\n", - "WARNING - 'pkg:pypi/dejacode@5.0.0?how_is_the_weather=rainy' not fully supported with `urls` command\n", - "WARNING - 'pkg:pypi/dejacode@5.0.0#how/are/you' not fully supported with `urls` command\n", - "WARNING - 'pkg:pypi/dejacode@10.0.0' does not exist in the upstream repo\n", - "WARNING - 'pkg:nginx/nginx' not supported with `urls` command\n", - "WARNING - 'pkg:nginx/nginx@0.8.9?os=windows' not supported with `urls` command\n", - "WARNING - 'check_existence' is not supported for 'pkg:rubygems/bundler-sass'\n", - "WARNING - 'pkg:pypi/matchcode' does not exist in the upstream repo\n", - "WARNING - 'abcdefg' not valid\n", - "WARNING - 'pkg/abc' not valid\n", - ] - expected_result_file = test_env.get_test_loc( "purlcli/expected_urls_output.json" ) @@ -460,40 +399,20 @@ def test_urls_cli(self, mock_read_log_file): "--purl", "pkg:pypi/fetchcode@0.3.0", "--purl", - "pkg:pypi/fetchcode@5.0.0", - "--purl", "pkg:pypi/dejacode", "--purl", "pkg:pypi/dejacode@5.0.0", "--purl", "pkg:pypi/dejacode@5.0.0?os=windows", "--purl", - "pkg:pypi/dejacode@5.0.0os=windows", - "--purl", - "pkg:pypi/dejacode@5.0.0?how_is_the_weather=rainy", - "--purl", - "pkg:pypi/dejacode@5.0.0#how/are/you", - "--purl", - "pkg:pypi/dejacode@10.0.0", - "--purl", "pkg:cargo/banquo", "--purl", "pkg:cargo/socksprox", "--purl", - "pkg:nginx/nginx", - "--purl", - "pkg:nginx/nginx@0.8.9?os=windows", - "--purl", "pkg:gem/bundler-sass", "--purl", "pkg:rubygems/bundler-sass", "--purl", - "pkg:pypi/matchcode", - "--purl", - "abcdefg", - "--purl", - "pkg/abc", - "--purl", "pkg:nuget/auth0-aspnet@1.1.0", "--output", actual_result_file, @@ -541,30 +460,10 @@ def test_urls_cli(self, mock_read_log_file): for output, expected in result_objects: assert output == expected - @mock.patch("purldb_toolkit.purlcli.read_log_file") - def test_urls_cli_head(self, mock_read_log_file): + def test_urls_cli_head(self): """ Test the `urls` command with actual and expected JSON output files. """ - mock_read_log_file.return_value = [ - "WARNING - 'pkg:pypi/fetchcode' not fully supported with `urls` command\n", - "WARNING - 'pkg:pypi/fetchcode@0.3.0' not fully supported with `urls` command\n", - "WARNING - 'pkg:pypi/fetchcode@5.0.0' does not exist in the upstream repo\n", - "WARNING - 'pkg:pypi/dejacode' not fully supported with `urls` command\n", - "WARNING - 'pkg:pypi/dejacode@5.0.0' not fully supported with `urls` command\n", - "WARNING - 'pkg:pypi/dejacode@5.0.0?os=windows' not fully supported with `urls` command\n", - "WARNING - 'pkg:pypi/dejacode@5.0.0os=windows' does not exist in the upstream repo\n", - "WARNING - 'pkg:pypi/dejacode@5.0.0?how_is_the_weather=rainy' not fully supported with `urls` command\n", - "WARNING - 'pkg:pypi/dejacode@5.0.0#how/are/you' not fully supported with `urls` command\n", - "WARNING - 'pkg:pypi/dejacode@10.0.0' does not exist in the upstream repo\n", - "WARNING - 'pkg:nginx/nginx' not supported with `urls` command\n", - "WARNING - 'pkg:nginx/nginx@0.8.9?os=windows' not supported with `urls` command\n", - "WARNING - 'check_existence' is not supported for 'pkg:rubygems/bundler-sass'\n", - "WARNING - 'pkg:pypi/matchcode' does not exist in the upstream repo\n", - "WARNING - 'abcdefg' not valid\n", - "WARNING - 'pkg/abc' not valid\n", - ] - expected_result_file = test_env.get_test_loc( "purlcli/expected_urls_output_head.json" ) @@ -575,40 +474,20 @@ def test_urls_cli_head(self, mock_read_log_file): "--purl", "pkg:pypi/fetchcode@0.3.0", "--purl", - "pkg:pypi/fetchcode@5.0.0", - "--purl", "pkg:pypi/dejacode", "--purl", "pkg:pypi/dejacode@5.0.0", "--purl", "pkg:pypi/dejacode@5.0.0?os=windows", "--purl", - "pkg:pypi/dejacode@5.0.0os=windows", - "--purl", - "pkg:pypi/dejacode@5.0.0?how_is_the_weather=rainy", - "--purl", - "pkg:pypi/dejacode@5.0.0#how/are/you", - "--purl", - "pkg:pypi/dejacode@10.0.0", - "--purl", "pkg:cargo/banquo", "--purl", "pkg:cargo/socksprox", "--purl", - "pkg:nginx/nginx", - "--purl", - "pkg:nginx/nginx@0.8.9?os=windows", - "--purl", "pkg:gem/bundler-sass", "--purl", "pkg:rubygems/bundler-sass", "--purl", - "pkg:pypi/matchcode", - "--purl", - "abcdefg", - "--purl", - "pkg/abc", - "--purl", "pkg:nuget/auth0-aspnet@1.1.0", "--head", "--output", @@ -691,13 +570,7 @@ def test_urls_cli_no_input_sources(self): assert "Use either purls or file." in result.output assert result.exit_code == 2 - @mock.patch("purldb_toolkit.purlcli.read_log_file") - def test_urls_details(self, mock_read_log_file): - mock_read_log_file.return_value = [ - "WARNING - 'pkg:pypi/fetchcode@0.3.0' not fully supported with `urls` command\n", - "WARNING - 'check_existence' is not supported for 'pkg:github/istio/istio@1.20.2'\n", - ] - + def test_urls_details(self): input_purls = [ "pkg:pypi/fetchcode@0.3.0", "pkg:gem/bundler@2.3.23", @@ -732,10 +605,7 @@ def test_urls_details(self, mock_read_log_file): "--output": "", }, "errors": [], - "warnings": [ - "'pkg:pypi/fetchcode@0.3.0' not fully supported with `urls` command", - "'check_existence' is not supported for 'pkg:github/istio/istio@1.20.2'", - ], + "warnings": [], } ], "packages": [ @@ -773,43 +643,6 @@ def test_urls_details(self, mock_read_log_file): assert purl_urls_data == expected_data - @pytest.mark.parametrize( - "test_input,expected", - [ - ( - ["pkg:pypi/fetchcode"], - "valid_but_not_fully_supported", - ), - ( - ["pkg:gem/bundler-sass"], - None, - ), - ( - ["pkg:rubygems/bundler-sass"], - "check_existence_not_supported", - ), - ( - ["pkg:nginx/nginx"], - "valid_but_not_supported", - ), - ( - ["pkg:pypi/zzzzz"], - "not_in_upstream_repo", - ), - ( - ["pkg:pypi/?fetchcode"], - "not_valid", - ), - ( - ["zzzzz"], - "not_valid", - ), - ], - ) - def test_check_urls_purl(self, test_input, expected): - purl_urls = purlcli.check_urls_purl(test_input[0]) - assert purl_urls == expected - @pytest.mark.parametrize( "test_input,expected", [ @@ -842,18 +675,10 @@ def test_make_head_request(self, test_input, expected): class TestPURLCLI_validate(object): - @mock.patch("purldb_toolkit.purlcli.read_log_file") - def test_validate_cli(self, mock_read_log_file): + def test_validate_cli(self): """ Test the `validate` command with actual and expected JSON output files. """ - mock_read_log_file.return_value = [ - "WARNING - 'pkg:pypi/fetchcode@0.3.0os=windows' does not exist in the upstream repo\n", - "WARNING - 'pkg:pypi/fetchcode@5.0.0' does not exist in the upstream repo\n", - "WARNING - 'check_existence' is not supported for 'pkg:nginx/nginx'\n", - "WARNING - 'check_existence' is not supported for 'pkg:rubygems/rails'\n", - ] - expected_result_file = test_env.get_test_loc( "purlcli/expected_validate_output.json" ) @@ -1073,17 +898,10 @@ def test_validate_purl_strip(self, test_input, expected): class TestPURLCLI_versions(object): - @mock.patch("purldb_toolkit.purlcli.read_log_file") - def test_versions_cli(self, mock_read_log_file): + def test_versions_cli(self): """ Test the `versions` command with actual and expected JSON output files. """ - mock_read_log_file.return_value = [ - "WARNING - 'pkg:pypi/fetchcode@0.3.0os=windows' does not exist in the upstream repo\n", - "WARNING - 'pkg:pypi/fetchcode@5.0.0' does not exist in the upstream repo\n", - "WARNING - 'pkg:nginx/nginx' not supported with `versions` command\n", - ] - expected_result_file = test_env.get_test_loc( "purlcli/expected_versions_output.json" ) @@ -1102,8 +920,6 @@ def test_versions_cli(self, mock_read_log_file): "--purl", "pkg:cargo/banquo", "--purl", - "pkg:nginx/nginx", - "--purl", "pkg:hex/coherence@0.1.0", "--output", actual_result_file, @@ -1159,11 +975,7 @@ def test_versions_cli(self, mock_read_log_file): [ "pkg:pypi/fetchcode", "pkg:gem/bundler-sass", - "pkg:rubygems/bundler-sass", - "pkg:nginx/nginx", "pkg:pypi/zzzzz", - "pkg:pypi/?fetchcode", - "zzzzz", ], { "headers": [ @@ -1175,48 +987,38 @@ def test_versions_cli(self, mock_read_log_file): "--purl": [ "pkg:pypi/fetchcode", "pkg:gem/bundler-sass", - "pkg:rubygems/bundler-sass", - "pkg:nginx/nginx", "pkg:pypi/zzzzz", - "pkg:pypi/?fetchcode", - "zzzzz", ], "--file": None, "--output": "", }, "errors": [], - "warnings": [ - "'pkg:rubygems/bundler-sass' not supported with `versions` command", - "'pkg:nginx/nginx' not supported with `versions` command", - "'pkg:pypi/zzzzz' does not exist in the upstream repo", - "'pkg:pypi/?fetchcode' not valid", - "'zzzzz' not valid", - ], + "warnings": [], } ], "packages": [ { - "purl": "pkg:pypi/fetchcode@0.1.0", + "purl": "pkg:pypi/fetchcode", "version": "0.1.0", "release_date": "2021-08-25", }, { - "purl": "pkg:pypi/fetchcode@0.2.0", + "purl": "pkg:pypi/fetchcode", "version": "0.2.0", "release_date": "2022-09-14", }, { - "purl": "pkg:pypi/fetchcode@0.3.0", + "purl": "pkg:pypi/fetchcode", "version": "0.3.0", "release_date": "2023-12-18", }, { - "purl": "pkg:pypi/fetchcode@0.4.0", + "purl": "pkg:pypi/fetchcode", "release_date": "2024-03-12", "version": "0.4.0", }, { - "purl": "pkg:gem/bundler-sass@0.1.2", + "purl": "pkg:gem/bundler-sass", "version": "0.1.2", "release_date": "2013-12-11", }, @@ -1225,16 +1027,7 @@ def test_versions_cli(self, mock_read_log_file): ), ], ) - @mock.patch("purldb_toolkit.purlcli.read_log_file") - def test_versions_details(self, mock_read_log_file, test_input, expected): - mock_read_log_file.return_value = [ - "WARNING - 'pkg:rubygems/bundler-sass' not supported with `versions` command\n", - "WARNING - 'pkg:nginx/nginx' not supported with `versions` command\n", - "WARNING - 'pkg:pypi/zzzzz' does not exist in the upstream repo\n", - "WARNING - 'pkg:pypi/?fetchcode' not valid\n", - "WARNING - 'zzzzz' not valid\n", - ] - + def test_versions_details(self, test_input, expected): output = "" file = "" command_name = "versions" @@ -1253,47 +1046,6 @@ def test_versions_details(self, mock_read_log_file, test_input, expected): compare_packages(expected, purl_versions) - @pytest.mark.parametrize( - "test_input,expected", - [ - ( - ["pkg:pypi/fetchcode"], - None, - ), - ( - ["pkg:gem/bundler-sass"], - None, - ), - ( - ["pkg:rubygems/bundler-sass"], - "valid_but_not_supported", - ), - ( - ["pkg:nginx/nginx"], - "valid_but_not_supported", - ), - ( - ["pkg:pypi/zzzzz"], - "not_in_upstream_repo", - ), - ( - ["pkg:pypi/?fetchcode"], - "not_valid", - ), - ( - ["zzzzz"], - "not_valid", - ), - ( - ["pkg:maven/axis/axis@1.0"], - None, - ), - ], - ) - def test_check_versions_purl(self, test_input, expected): - purl_versions = purlcli.check_versions_purl(test_input[0]) - assert purl_versions == expected - def streamline_metadata_packages(packages): """