def test_filesearch(foss: Fossology, scanned_upload: Upload): if versiontuple(foss.version) > versiontuple("1.0.16"): filelist = [ { "md5": "F921793D03CC6D63EC4B15E9BE8FD3F8" }, { "sha1": scanned_upload.hash.sha1 }, ] search_result = foss.filesearch(filelist=filelist) assert len(search_result) == 2 assert ( f"File with SHA1 {scanned_upload.hash.sha1} doesn't have any concluded license yet" in str(search_result[1])) filelist = [{"sha1": "FAKE"}] result = foss.filesearch(filelist=filelist) assert result == "Unable to get a result with the given filesearch criteria" assert foss.filesearch() == [] else: with pytest.raises(FossologyUnsupported) as excinfo: foss.filesearch(filelist=[], group="test") assert ( "Endpoint /filesearch is not supported by your Fossology API version" in str(excinfo.value))
def test_filesearch_nogroup(foss: Fossology): if versiontuple(foss.version) > versiontuple("1.0.16"): with pytest.raises(AuthorizationError) as excinfo: foss.filesearch(filelist=[], group="test") assert "Searching for group test not authorized" in str(excinfo.value) else: with pytest.raises(FossologyUnsupported) as excinfo: foss.filesearch(filelist=[], group="test") assert ( "Endpoint /filesearch is not supported by your Fossology API version" in str(excinfo.value))
def test_filesearch_error(foss_server: str, foss: Fossology): responses.add(responses.POST, f"{foss_server}/api/v1/filesearch", status=404) if versiontuple(foss.version) > versiontuple("1.0.16"): with pytest.raises(FossologyApiError) as excinfo: foss.filesearch() assert "Unable to get a result with the given filesearch criteria" in str( excinfo.value) else: with pytest.raises(FossologyUnsupported) as excinfo: foss.filesearch(filelist=[], group="test") assert ( "Endpoint /filesearch is not supported by your Fossology API version" in str(excinfo.value))