Skip to content

Commit

Permalink
tests(v1): test v1 by default, add tests for uploads v2
Browse files Browse the repository at this point in the history
  • Loading branch information
deveaud-m committed Apr 4, 2024
1 parent dc0e0b7 commit 171332d
Show file tree
Hide file tree
Showing 11 changed files with 95 additions and 57 deletions.
12 changes: 6 additions & 6 deletions tests/test_folders.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

@responses.activate
def test_list_folders_error(foss_server: str, foss: Fossology):
responses.add(responses.GET, f"{foss_server}/api/v2/folders", status=404)
responses.add(responses.GET, f"{foss_server}/api/v1/folders", status=404)
with pytest.raises(FossologyApiError) as excinfo:
foss.list_folders()
assert f"Unable to get a list of folders for {foss.user.name}" in str(excinfo.value)
Expand Down Expand Up @@ -69,7 +69,7 @@ def test_create_folder_no_parent(foss: Fossology):
def test_create_folder_returns_200_but_folder_does_not_exists(
foss_server: str, foss: Fossology
):
responses.add(responses.POST, f"{foss_server}/api/v2/folders", status=200)
responses.add(responses.POST, f"{foss_server}/api/v1/folders", status=200)
with pytest.raises(FossologyApiError) as excinfo:
foss.create_folder(foss.rootFolder, "NoFolder")
assert (
Expand All @@ -81,7 +81,7 @@ def test_create_folder_returns_200_but_folder_does_not_exists(
@responses.activate
def test_create_folder_error(foss_server: str, foss: Fossology):
parent = Folder(secrets.randbelow(1000), "NonFolder", "", foss.rootFolder)
responses.add(responses.POST, f"{foss_server}/api/v2/folders", status=404)
responses.add(responses.POST, f"{foss_server}/api/v1/folders", status=404)
with pytest.raises(FossologyApiError) as excinfo:
foss.create_folder(parent, "TestFolderNoParent")
assert "Unable to create folder TestFolderNoParent" in str(excinfo.value)
Expand All @@ -106,7 +106,7 @@ def test_update_folder(foss: Fossology):
def test_update_folder_error(foss_server: str, foss: Fossology):
folder = Folder(secrets.randbelow(1000), "Folder", "", foss.rootFolder)
responses.add(
responses.PATCH, f"{foss_server}/api/v2/folders/{folder.id}", status=404
responses.PATCH, f"{foss_server}/api/v1/folders/{folder.id}", status=404
)
with pytest.raises(FossologyApiError) as excinfo:
foss.update_folder(folder)
Expand Down Expand Up @@ -152,7 +152,7 @@ def test_copy_folder(foss: Fossology):
def test_put_folder_error(foss_server: str, foss: Fossology):
folder = Folder(secrets.randbelow(1000), "Folder", "", foss.rootFolder)
responses.add(
responses.PUT, f"{foss_server}/api/v2/folders/{folder.id}", status=404
responses.PUT, f"{foss_server}/api/v1/folders/{folder.id}", status=404
)
with pytest.raises(FossologyApiError) as excinfo:
foss.move_folder(folder, foss.rootFolder)
Expand All @@ -178,7 +178,7 @@ def test_delete_folder(foss: Fossology):
def test_delete_folder_error(foss_server: str, foss: Fossology):
folder = Folder(secrets.randbelow(1000), "Folder", "", foss.rootFolder)
responses.add(
responses.DELETE, f"{foss_server}/api/v2/folders/{folder.id}", status=404
responses.DELETE, f"{foss_server}/api/v1/folders/{folder.id}", status=404
)
with pytest.raises(FossologyApiError) as excinfo:
foss.delete_folder(folder)
Expand Down
10 changes: 5 additions & 5 deletions tests/test_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ def verify_user_group_membership(
# Test functions
@responses.activate
def test_list_groups_error(foss_server: str, foss: fossology.Fossology):
responses.add(responses.GET, f"{foss_server}/api/v2/groups", status=500)
responses.add(responses.GET, f"{foss_server}/api/v1/groups", status=500)
with pytest.raises(FossologyApiError) as excinfo:
foss.list_groups()
assert f"Unable to get a list of groups for {foss.user.name}" in str(excinfo.value)


@responses.activate
def test_list_group_members_error(foss_server: str, foss: fossology.Fossology):
responses.add(responses.GET, f"{foss_server}/api/v2/groups/42/members", status=500)
responses.add(responses.GET, f"{foss_server}/api/v1/groups/42/members", status=500)
with pytest.raises(FossologyApiError) as excinfo:
foss.list_group_members(42)
assert "Unable to get a list of members for group 42" in str(excinfo.value)
Expand All @@ -52,7 +52,7 @@ def test_delete_group_member_validation_error(
foss_server: str, foss: fossology.Fossology
):
responses.add(
responses.DELETE, f"{foss_server}/api/v2/groups/42/user/42", status=400
responses.DELETE, f"{foss_server}/api/v1/groups/42/user/42", status=400
)
with pytest.raises(FossologyApiError) as excinfo:
foss.delete_group_member(42, 42)
Expand All @@ -64,7 +64,7 @@ def test_delete_group_member_validation_error(
@responses.activate
def test_delete_group_member_error(foss_server: str, foss: fossology.Fossology):
responses.add(
responses.DELETE, f"{foss_server}/api/v2/groups/42/user/42", status=500
responses.DELETE, f"{foss_server}/api/v1/groups/42/user/42", status=500
)
with pytest.raises(FossologyApiError) as excinfo:
foss.delete_group_member(42, 42)
Expand All @@ -77,7 +77,7 @@ def test_delete_group_member_error(foss_server: str, foss: fossology.Fossology):
def test_delete_group_error(foss_server: str, foss: fossology.Fossology):
group_id = secrets.randbelow(10)
responses.add(
responses.DELETE, f"{foss_server}/api/v2/groups/{group_id}", status=500
responses.DELETE, f"{foss_server}/api/v1/groups/{group_id}", status=500
)
with pytest.raises(FossologyApiError) as excinfo:
foss.delete_group(group_id)
Expand Down
12 changes: 6 additions & 6 deletions tests/test_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def test_item_info_500_error(
):
responses.add(
responses.GET,
f"{foss_server}/api/v2/uploads/{upload_with_jobs.id}/item/1/info",
f"{foss_server}/api/v1/uploads/{upload_with_jobs.id}/item/1/info",
status=500,
)
with pytest.raises(FossologyApiError) as excinfo:
Expand Down Expand Up @@ -69,7 +69,7 @@ def test_item_copyrights_500_error(
):
responses.add(
responses.GET,
f"{foss_server}/api/v2/uploads/{upload_with_jobs.id}/item/1/totalcopyrights",
f"{foss_server}/api/v1/uploads/{upload_with_jobs.id}/item/1/totalcopyrights",
status=500,
)
with pytest.raises(FossologyApiError) as excinfo:
Expand Down Expand Up @@ -100,7 +100,7 @@ def test_upload_get_clearing_history_500_error(
):
responses.add(
responses.GET,
f"{foss_server}/api/v2/uploads/{upload_with_jobs.id}/item/1/clearing-history",
f"{foss_server}/api/v1/uploads/{upload_with_jobs.id}/item/1/clearing-history",
status=500,
)
with pytest.raises(FossologyApiError) as excinfo:
Expand Down Expand Up @@ -131,7 +131,7 @@ def test_upload_get_bulk_history_500_error(
):
responses.add(
responses.GET,
f"{foss_server}/api/v2/uploads/{upload_with_jobs.id}/item/1/clearing-history",
f"{foss_server}/api/v1/uploads/{upload_with_jobs.id}/item/1/clearing-history",
status=500,
)
with pytest.raises(FossologyApiError) as excinfo:
Expand Down Expand Up @@ -172,7 +172,7 @@ def test_schedule_bulk_scan_500_error(
):
responses.add(
responses.POST,
f"{foss_server}/api/v2/uploads/{upload_with_jobs.id}/item/1/bulk-scan",
f"{foss_server}/api/v1/uploads/{upload_with_jobs.id}/item/1/bulk-scan",
status=500,
)
with pytest.raises(FossologyApiError) as excinfo:
Expand Down Expand Up @@ -219,7 +219,7 @@ def test_upload_get_prev_next_500_error(
):
responses.add(
responses.GET,
f"{foss_server}/api/v2/uploads/{upload_with_jobs.id}/item/1/prev-next",
f"{foss_server}/api/v1/uploads/{upload_with_jobs.id}/item/1/prev-next",
status=500,
)
with pytest.raises(FossologyApiError) as excinfo:
Expand Down
10 changes: 5 additions & 5 deletions tests/test_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def test_detail_job_wait_completed(

@responses.activate
def test_schedule_job_error(foss_server: str, foss: Fossology, upload: Upload):
responses.add(responses.POST, f"{foss_server}/api/v2/jobs", status=404)
responses.add(responses.POST, f"{foss_server}/api/v1/jobs", status=404)
with pytest.raises(FossologyApiError) as excinfo:
foss.schedule_jobs(foss.rootFolder, upload, {})
assert f"Scheduling jobs for upload {upload.uploadname} failed" in str(
Expand All @@ -71,15 +71,15 @@ def test_schedule_job_error(foss_server: str, foss: Fossology, upload: Upload):

@responses.activate
def test_list_jobs_error(foss_server: str, foss: Fossology):
responses.add(responses.GET, f"{foss_server}/api/v2/jobs", status=404)
responses.add(responses.GET, f"{foss_server}/api/v1/jobs", status=404)
with pytest.raises(FossologyApiError) as excinfo:
foss.list_jobs()
assert "Unable to retrieve the list of jobs from page 1" in str(excinfo.value)


@responses.activate
def test_list_all_jobs_access_denied(foss_server: str, foss: Fossology):
responses.add(responses.GET, f"{foss_server}/api/v2/jobs/all", status=403)
responses.add(responses.GET, f"{foss_server}/api/v1/jobs/all", status=403)
with pytest.raises(FossologyApiError) as excinfo:
foss.list_jobs(all=True)
assert "Access denied to /jobs/all endpoint" in str(excinfo.value)
Expand All @@ -88,8 +88,8 @@ def test_list_all_jobs_access_denied(foss_server: str, foss: Fossology):
@responses.activate
def test_detail_job_error(foss_server: str, foss: Fossology):
job_id = secrets.randbelow(1000)
responses.add(responses.GET, f"{foss_server}/api/v2/jobs/{job_id}", status=404)
responses.add(responses.GET, f"{foss_server}/api/v2/jobs/{job_id}", status=404)
responses.add(responses.GET, f"{foss_server}/api/v1/jobs/{job_id}", status=404)
responses.add(responses.GET, f"{foss_server}/api/v1/jobs/{job_id}", status=404)
with pytest.raises(FossologyApiError) as excinfo:
foss.detail_job(job_id, wait=True)
assert f"Error while getting details for job {job_id}" in str(excinfo.value)
Expand Down
10 changes: 5 additions & 5 deletions tests/test_license.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def test_another_license():

@responses.activate
def test_detail_license_error(foss_server: str, foss: fossology.Fossology):
responses.add(responses.GET, f"{foss_server}/api/v2/license/Blah", status=500)
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)
Expand All @@ -48,7 +48,7 @@ def test_detail_license_not_found(foss: fossology.Fossology):

@responses.activate
def test_list_licenses_error(foss_server: str, foss: fossology.Fossology):
responses.add(responses.GET, f"{foss_server}/api/v2/license", status=500)
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)
Expand Down Expand Up @@ -76,7 +76,7 @@ def test_get_all_candidate_licenses(foss: fossology.Fossology):
def test_add_license_error(
foss_server: str, foss: fossology.Fossology, test_license: License
):
responses.add(responses.POST, f"{foss_server}/api/v2/license", status=500)
responses.add(responses.POST, f"{foss_server}/api/v1/license", status=500)
with pytest.raises(FossologyApiError) as excinfo:
foss.add_license(test_license)
assert f"Error while adding new license {test_license.shortName}" in str(
Expand All @@ -93,7 +93,7 @@ def test_add_license_already_exists(
):
mocked_logger = MagicMock()
monkeypatch.setattr("fossology.license.logger", mocked_logger)
responses.add(responses.POST, f"{foss_server}/api/v2/license", status=409)
responses.add(responses.POST, f"{foss_server}/api/v1/license", status=409)
foss.add_license(test_license)
mocked_logger.info.assert_called_once()

Expand Down Expand Up @@ -125,7 +125,7 @@ def test_patch_license_error(
foss_server: str, foss: fossology.Fossology, test_license: License
):
responses.add(
responses.PATCH, f"{foss_server}/api/v2/license/License-1.0", status=500
responses.PATCH, f"{foss_server}/api/v1/license/License-1.0", status=500
)
with pytest.raises(FossologyApiError) as excinfo:
foss.update_license(test_license.shortName)
Expand Down
12 changes: 6 additions & 6 deletions tests/test_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ def test_generate_report(foss: Fossology, upload: Upload):
def test_report_error(foss_server: str, foss: Fossology, upload: Upload):
responses.add(
responses.GET,
f"{foss_server}/api/v2/report",
f"{foss_server}/api/v1/report",
status=503,
headers={"Retry-After": "1"},
)
responses.add(responses.GET, f"{foss_server}/api/v2/report", status=404)
responses.add(responses.GET, f"{foss_server}/api/v1/report", status=404)
with pytest.raises(FossologyApiError) as excinfo:
foss.generate_report(upload)
assert f"Report generation for upload {upload.uploadname} failed" in str(
Expand All @@ -68,7 +68,7 @@ def test_download_report_error(foss_server: str, foss: Fossology):
report_id = secrets.randbelow(1000)
responses.add(
responses.GET,
f"{foss_server}/api/v2/report/{report_id}",
f"{foss_server}/api/v1/report/{report_id}",
status=500,
)
with pytest.raises(FossologyApiError) as excinfo:
Expand All @@ -81,7 +81,7 @@ def test_download_report_filename_without_quotes(foss_server: str, foss: Fossolo
report_id = "1"
responses.add(
responses.GET,
f"{foss_server}/api/v2/report/{report_id}",
f"{foss_server}/api/v1/report/{report_id}",
status=200,
headers={"Content-Disposition": "attachment; filename=Report_FileName.docx"},
)
Expand All @@ -94,7 +94,7 @@ def test_download_report_filename_with_quotes(foss_server: str, foss: Fossology)
report_id = "1"
responses.add(
responses.GET,
f"{foss_server}/api/v2/report/{report_id}",
f"{foss_server}/api/v1/report/{report_id}",
status=200,
headers={"Content-Disposition": 'attachment; filename="Report_FileName.docx"'},
)
Expand All @@ -107,7 +107,7 @@ def test_download_report_filename_with_single_quotes(foss_server: str, foss: Fos
report_id = "1"
responses.add(
responses.GET,
f"{foss_server}/api/v2/report/{report_id}",
f"{foss_server}/api/v1/report/{report_id}",
status=200,
headers={"Content-Disposition": "attachment; filename='Report_FileName.docx'"},
)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def test_search_upload_does_not_exist(foss: Fossology):

@responses.activate
def test_search_error(foss_server: str, foss: Fossology):
responses.add(responses.GET, f"{foss_server}/api/v2/search", status=404)
responses.add(responses.GET, f"{foss_server}/api/v1/search", status=404)
with pytest.raises(FossologyApiError) as excinfo:
foss.search()
assert "Unable to get a result with the given search criteria" in str(excinfo.value)
Expand Down Expand Up @@ -108,7 +108,7 @@ def test_filesearch_nogroup(foss: Fossology):

@responses.activate
def test_filesearch_error(foss_server: str, foss: Fossology):
responses.add(responses.POST, f"{foss_server}/api/v2/filesearch", status=404)
responses.add(responses.POST, f"{foss_server}/api/v1/filesearch", status=404)
with pytest.raises(FossologyApiError) as excinfo:
foss.filesearch()
assert "Unable to get a result with the given filesearch criteria" in str(
Expand Down
14 changes: 7 additions & 7 deletions tests/test_upload_licenses_copyrights.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def test_upload_licenses_with_unknown_group_raises_authorization_error(
def test_upload_licenses_412_error(foss: Fossology, foss_server: str, upload: Upload):
responses.add(
responses.GET,
f"{foss_server}/api/v2/uploads/{upload.id}/licenses",
f"{foss_server}/api/v1/uploads/{upload.id}/licenses",
status=412,
)
with pytest.raises(FossologyApiError) as excinfo:
Expand All @@ -66,7 +66,7 @@ def test_upload_licenses_412_error(foss: Fossology, foss_server: str, upload: Up
def test_upload_licenses_503_error(foss: Fossology, foss_server: str, upload: Upload):
responses.add(
responses.GET,
f"{foss_server}/api/v2/uploads/{upload.id}/licenses",
f"{foss_server}/api/v1/uploads/{upload.id}/licenses",
status=503,
)
with pytest.raises(RetryError):
Expand All @@ -77,7 +77,7 @@ def test_upload_licenses_503_error(foss: Fossology, foss_server: str, upload: Up
def test_upload_licenses_500_error(foss: Fossology, foss_server: str, upload: Upload):
responses.add(
responses.GET,
f"{foss_server}/api/v2/uploads/{upload.id}/licenses",
f"{foss_server}/api/v1/uploads/{upload.id}/licenses",
status=500,
)
with pytest.raises(FossologyApiError) as excinfo:
Expand All @@ -97,7 +97,7 @@ def test_upload_copyrights(foss: Fossology, upload_with_jobs: Upload):
def test_upload_copyrights_403_error(foss: Fossology, foss_server: str, upload: Upload):
responses.add(
responses.GET,
f"{foss_server}/api/v2/uploads/{upload.id}/copyrights",
f"{foss_server}/api/v1/uploads/{upload.id}/copyrights",
status=403,
)
with pytest.raises(AuthorizationError) as excinfo:
Expand All @@ -112,7 +112,7 @@ def test_upload_copyrights_403_error(foss: Fossology, foss_server: str, upload:
def test_upload_copyrights_412_error(foss: Fossology, foss_server: str, upload: Upload):
responses.add(
responses.GET,
f"{foss_server}/api/v2/uploads/{upload.id}/copyrights",
f"{foss_server}/api/v1/uploads/{upload.id}/copyrights",
status=412,
)
with pytest.raises(FossologyApiError) as excinfo:
Expand All @@ -127,7 +127,7 @@ def test_upload_copyrights_412_error(foss: Fossology, foss_server: str, upload:
def test_upload_copyrights_503_error(foss: Fossology, foss_server: str, upload: Upload):
responses.add(
responses.GET,
f"{foss_server}/api/v2/uploads/{upload.id}/copyrights",
f"{foss_server}/api/v1/uploads/{upload.id}/copyrights",
status=503,
)
with pytest.raises(RetryError):
Expand All @@ -138,7 +138,7 @@ def test_upload_copyrights_503_error(foss: Fossology, foss_server: str, upload:
def test_upload_copyrights_500_error(foss: Fossology, foss_server: str, upload: Upload):
responses.add(
responses.GET,
f"{foss_server}/api/v2/uploads/{upload.id}/copyrights",
f"{foss_server}/api/v1/uploads/{upload.id}/copyrights",
status=500,
)
with pytest.raises(FossologyApiError) as excinfo:
Expand Down
Loading

0 comments on commit 171332d

Please sign in to comment.