def test_detail_license(foss: fossology.Fossology): if fossology.versiontuple(foss.version) < fossology.versiontuple("1.1.3"): with pytest.raises(FossologyUnsupported) as excinfo: foss.detail_license(short) assert ( "Endpoint /license is not supported by your Fossology API version" in str(excinfo.value)) else: license = foss.detail_license(short) assert license assert type(license) == License
def test_detail_license_error(foss_server: str, foss: fossology.Fossology): if fossology.versiontuple(foss.version) < fossology.versiontuple("1.1.3"): with pytest.raises(FossologyUnsupported) as excinfo: foss.detail_license(short) assert ( "Endpoint /license is not supported by your Fossology API version" in str(excinfo.value)) else: responses.add(responses.GET, f"{foss_server}/api/v1/license", status=500) with pytest.raises(FossologyApiError) as excinfo: foss.detail_license(short) assert f"Unable to get license {short}" in str(excinfo.value)
def test_detail_license_error(foss_server: str, foss: fossology.Fossology): if fossology.versiontuple(foss.version) < fossology.versiontuple("1.3.0"): with pytest.raises(FossologyUnsupported) as excinfo: foss.detail_license(shortname) assert ( "Endpoint /license is not supported by your Fossology API version" in str(excinfo.value)) else: responses.add(responses.GET, f"{foss_server}/api/v1/license/Blah", status=500) with pytest.raises(FossologyApiError) as excinfo: foss.detail_license("Blah") assert "Error while getting license Blah" in str(excinfo.value)
def test_list_licenses_error(foss_server: str, foss: fossology.Fossology): if fossology.versiontuple(foss.version) < fossology.versiontuple("1.3.0"): with pytest.raises(FossologyUnsupported) as excinfo: foss.detail_license(shortname) assert ( "Endpoint /license is not supported by your Fossology API version" in str(excinfo.value)) else: responses.add(responses.GET, f"{foss_server}/api/v1/license", status=500) with pytest.raises(FossologyApiError) as excinfo: foss.list_licenses() assert "Unable to retrieve the list of licenses from page 1" in str( excinfo.value)
def test_patch_license_and_get_by_shortname(foss: fossology.Fossology, test_another_license: License): if fossology.versiontuple(foss.version) >= fossology.versiontuple("1.3.0"): foss.add_license(test_another_license) foss.update_license(test_another_license.shortName, fullname="Inner Source license 2.0", risk=1) license_found = foss.detail_license(test_another_license.shortName) assert license_found.shortName == "License-2.0" assert license_found.fullName == "Inner Source license 2.0" assert license_found.risk == 1
def test_add_license_and_get_by_shortname(foss: fossology.Fossology, test_license: License, monkeypatch): if fossology.versiontuple(foss.version) >= fossology.versiontuple("1.3.0"): mocked_logger = MagicMock() monkeypatch.setattr("fossology.license.logger", mocked_logger) foss.add_license(test_license) license_found = foss.detail_license(test_license.shortName) assert license_found.shortName == "License-1.0" expected_license_repr = ( f"License {license_found.fullName} - {license_found.shortName} ") expected_license_repr += ( f"({license_found.id}) with risk level {license_found.risk}") assert str(license_found) == expected_license_repr foss.add_license(test_license, merge_request=True) mocked_logger.info.assert_called_with( f"License {test_license.shortName} already exists")
def test_detail_license_not_found(foss: fossology.Fossology): if fossology.versiontuple(foss.version) >= fossology.versiontuple("1.3.0"): with pytest.raises(FossologyApiError) as excinfo: foss.detail_license("Unknown") assert "License Unknown not found" in str(excinfo.value)