generated from aboutcode-org/skeleton
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor purlcli.py validate, create tests #247
Reference: #247 Signed-off-by: John M. Horan <[email protected]>
- Loading branch information
1 parent
67e05a4
commit ff53939
Showing
2 changed files
with
104 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import os | ||
|
||
from click.testing import CliRunner | ||
from commoncode.testcase import FileBasedTesting | ||
|
||
import purlcli | ||
|
||
|
||
class TestPURLCLI(FileBasedTesting): | ||
test_data_dir = os.path.join(os.path.dirname(__file__), "data") | ||
|
||
def test_validate_purl(self): | ||
test_purls = [ | ||
"pkg:nginx/[email protected]?os=windows", | ||
"pkg:maven/com.fasterxml.jackson.core/[email protected]", | ||
] | ||
|
||
validated_purls = purlcli.validate_purls(test_purls) | ||
|
||
expected_results = [ | ||
{ | ||
"valid": True, | ||
"exists": None, | ||
"message": "The provided PackageURL is valid, but `check_existence` is not supported for this package type.", | ||
"purl": "pkg:nginx/[email protected]?os=windows", | ||
}, | ||
{ | ||
"valid": True, | ||
"exists": True, | ||
"message": "The provided Package URL is valid, and the package exists in the upstream repo.", | ||
"purl": "pkg:maven/com.fasterxml.jackson.core/[email protected]", | ||
}, | ||
] | ||
|
||
self.assertEqual(validated_purls, expected_results) | ||
|
||
def test_validate_purl_empty(self): | ||
test_purls = [] | ||
|
||
validated_purls = purlcli.validate_purls(test_purls) | ||
|
||
expected_results = [] | ||
|
||
self.assertEqual(validated_purls, expected_results) | ||
|
||
def test_validate_purl_invalid(self): | ||
test_purls = [ | ||
"foo", | ||
] | ||
|
||
validated_purls = purlcli.validate_purls(test_purls) | ||
|
||
expected_results = [ | ||
{ | ||
"valid": False, | ||
"exists": None, | ||
"message": "The provided PackageURL is not valid.", | ||
"purl": "foo", | ||
} | ||
] | ||
|
||
self.assertEqual(validated_purls, expected_results) | ||
|
||
def test_validate_purl_strip(self): | ||
test_purls = [ | ||
"pkg:nginx/[email protected]?os=windows", | ||
" pkg:nginx/[email protected]?os=windows", | ||
"pkg:nginx/[email protected]?os=windows ", | ||
] | ||
|
||
validated_purls = purlcli.validate_purls(test_purls) | ||
|
||
expected_results = [ | ||
{ | ||
"valid": True, | ||
"exists": None, | ||
"message": "The provided PackageURL is valid, but `check_existence` is not supported for this package type.", | ||
"purl": "pkg:nginx/[email protected]?os=windows", | ||
}, | ||
{ | ||
"valid": True, | ||
"exists": None, | ||
"message": "The provided PackageURL is valid, but `check_existence` is not supported for this package type.", | ||
"purl": "pkg:nginx/[email protected]?os=windows", | ||
}, | ||
{ | ||
"valid": True, | ||
"exists": None, | ||
"message": "The provided PackageURL is valid, but `check_existence` is not supported for this package type.", | ||
"purl": "pkg:nginx/[email protected]?os=windows", | ||
}, | ||
] | ||
|
||
self.assertEqual(validated_purls, expected_results) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters