Skip to content

Commit

Permalink
fix(tests): adapt all tests to API version 1.5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
deveaud-m committed Nov 5, 2023
1 parent 53387d0 commit 1f03171
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 52 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/fossologytests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,8 @@ jobs:
run: nmap fossology -p 80
- name: Run tests
run: |
export API_LATEST=true
poetry run coverage run --source=fossology -m pytest
poetry run coverage report -m
continue-on-error: true
- name: upload codecoverage results only if we are on the repository fossology/fossology-python
if: ${{ github.repository == 'fossology/fossology-python' }}
run: poetry run codecov -t ${{ secrets.CODECOV_TOKEN }}
3 changes: 2 additions & 1 deletion docs-source/sample_workflow.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ Needed imports and Variables
>>> from getpass import getpass
>>> import requests
>>> from fossology import Fossology, fossology_token
>>> from fossology.obj import Group, AccessLevel, TokenScope
>>> from fossology.obj import Group
>>> from fossology.enums import AccessLevel, TokenScope
>>> from fossology.exceptions import FossologyApiError
>>> FOSSOLOGY_SERVER = "http://fossology/repo"
>>> os.environ["FOSSOLOGY_USER"] = "fossy"
Expand Down
43 changes: 17 additions & 26 deletions fossology/uploads.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def upload_file(
:Example for a file upload:
>>> from fossology import Fossology
>>> from fossology.obj import AccessLevel
>>> from fossology.enums import AccessLevel
>>> foss = Fossology(FOSS_URL, FOSS_TOKEN, username) # doctest: +SKIP
>>> my_upload = foss.upload_file(
... foss.rootFolder,
Expand Down Expand Up @@ -254,18 +254,19 @@ def upload_file(
f"{self.api}/uploads", files=files, headers=headers
)
elif vcs or url or server:
data = dict
if vcs:
headers["uploadType"] = "vcs"
data = json.dumps(vcs)
data = {"location": vcs}
elif url:
headers["uploadType"] = "url"
data = json.dumps(url)
data = {"location": url}
elif server:
headers["uploadType"] = "server"
data = json.dumps(server)
data = {"location": server}
headers["Content-Type"] = "application/json"
response = self.session.post(
f"{self.api}/uploads", data=data, headers=headers
f"{self.api}/uploads", data=json.dumps(data), headers=headers
)
else:
logger.info(
Expand Down Expand Up @@ -306,15 +307,6 @@ def upload_file(
description = f"Upload {description} is not authorized"
raise AuthorizationError(description, response)

elif server and response.status_code == 500:
description = (
f"Upload {description} could not be performed; "
f"did you add a prefix for '{server['path']}' in Fossology config "
f"variable 'Admin->Customize->Whitelist for serverupload'? "
f"Has fossy user read access to {server['path']}?"
)
raise FossologyApiError(description, response)

else:
description = f"Upload {description} could not be performed"
raise FossologyApiError(description, response)
Expand Down Expand Up @@ -923,20 +915,19 @@ def schedule_bulk_scan(
>>> bulk_scan_spec = {
... "bulkActions": [
... {
... "licenseShortName": string (example: 'MIT'),
... "licenseText": string (example: 'License text'),
... "acknowledgement": string (example: 'Acknowledgment text'),
... "comment": string (example: 'Comment text'),
... "licenseAction": LicenseAction (ADD/REMOVE),
... "licenseShortName": 'MIT',
... "licenseText": 'License text',
... "acknowledgement": 'Acknowledgment text',
... "comment": 'Comment text',
... "licenseAction": 'ADD', # or 'REMOVE'
... }
... ],
... "refText": string (example: 'Reference Text'),
... "bulkScope": BulkScope (folder/upload),
... "forceDecision": boolean (example: 'false'),
... "ignoreIrre": boolean (example: 'false'),
... "delimiters": string (example: 'DEFAULT'),
... "scanOnlyFindings": boolean (example: 'true'),
... }
... "refText": 'Reference Text',
... "bulkScope": 'folder', # or upload
... "forceDecision": 'false',
... "ignoreIrre": 'false',
... "delimiters": 'DEFAULT',
... "scanOnlyFindings": 'true',
... }
:param upload: the upload for the bulk scan
Expand Down
2 changes: 1 addition & 1 deletion tests/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
def test_get_info(foss: Fossology):
assert foss.info.name == "FOSSology API"
assert foss.info.license.name == "GPL-2.0-only"
assert foss.info.fossology.version
assert foss.info.version


@responses.activate
Expand Down
8 changes: 0 additions & 8 deletions tests/test_license.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
from fossology.exceptions import FossologyApiError
from fossology.obj import License, Obligation

shortname = "GPL-2.0+"


@pytest.fixture()
def test_license():
Expand Down Expand Up @@ -48,12 +46,6 @@ def test_detail_license_not_found(foss: fossology.Fossology):
assert "License Unknown not found" in str(excinfo.value)


def test_detail_license(foss: fossology.Fossology):
detail_license = foss.detail_license(shortname, group="fossy")
assert detail_license
assert isinstance(detail_license, License)


@responses.activate
def test_list_licenses_error(foss_server: str, foss: fossology.Fossology):
responses.add(responses.GET, f"{foss_server}/api/v1/license", status=500)
Expand Down
14 changes: 14 additions & 0 deletions tests/test_upload_clearing.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@
from fossology.obj import Upload


@pytest.mark.skip(reason="Not yet released, waiting for API version 1.6.0")
def test_upload_get_clearing_history(foss: Fossology, upload_with_jobs: Upload):
files, _ = foss.search(license="BSD")
history = foss.get_clearing_history(upload_with_jobs, files[0].uploadTreeId)
assert not history


@pytest.mark.skip(reason="Not yet released, waiting for API version 1.6.0")
def test_upload_get_clearing_history_with_unknown_item_raises_api_error(
foss: Fossology, upload_with_jobs: Upload
):
Expand All @@ -24,6 +26,7 @@ def test_upload_get_clearing_history_with_unknown_item_raises_api_error(
assert f"Upload {upload_with_jobs.id} or item 1 not found" in str(excinfo.value)


@pytest.mark.skip(reason="Not yet released, waiting for API version 1.6.0")
@responses.activate
def test_upload_get_clearing_history_500_error(
foss: Fossology, foss_server: str, upload_with_jobs: Upload
Expand All @@ -41,12 +44,14 @@ def test_upload_get_clearing_history_500_error(
)


@pytest.mark.skip(reason="Not yet released, waiting for API version 1.6.0")
def test_upload_get_bulk_history(foss: Fossology, upload_with_jobs: Upload):
files, _ = foss.search(license="BSD")
history = foss.get_bulk_history(upload_with_jobs, files[0].uploadTreeId)
assert not history


@pytest.mark.skip(reason="Not yet released, waiting for API version 1.6.0")
def test_upload_get_bulk_history_with_unknown_item_raises_api_error(
foss: Fossology, upload_with_jobs: Upload
):
Expand All @@ -55,6 +60,7 @@ def test_upload_get_bulk_history_with_unknown_item_raises_api_error(
assert f"Upload {upload_with_jobs.id} or item 1 not found" in str(excinfo.value)


@pytest.mark.skip(reason="Not yet released, waiting for API version 1.6.0")
@responses.activate
def test_upload_get_bulk_history_500_error(
foss: Fossology, foss_server: str, upload_with_jobs: Upload
Expand All @@ -72,6 +78,7 @@ def test_upload_get_bulk_history_500_error(
)


@pytest.mark.skip(reason="Not yet released, waiting for API version 1.6.0")
def test_upload_schedule_bulk_scan(
foss: Fossology, upload_with_jobs: Upload, foss_bulk_scan_spec: dict
):
Expand All @@ -85,6 +92,7 @@ def test_upload_schedule_bulk_scan(
assert history[0].addedLicenses == ["MIT"]


@pytest.mark.skip(reason="Not yet released, waiting for API version 1.6.0")
def test_schedule_bulk_scan_with_unknown_item_raises_api_error(
foss: Fossology, upload_with_jobs: Upload, foss_bulk_scan_spec: dict
):
Expand All @@ -93,6 +101,7 @@ def test_schedule_bulk_scan_with_unknown_item_raises_api_error(
assert f"Upload {upload_with_jobs.id} or item 1 not found" in str(excinfo.value)


@pytest.mark.skip(reason="Not yet released, waiting for API version 1.6.0")
@responses.activate
def test_schedule_bulk_scan_500_error(
foss: Fossology,
Expand All @@ -113,12 +122,14 @@ def test_schedule_bulk_scan_500_error(
)


@pytest.mark.skip(reason="Not yet released, waiting for API version 1.6.0")
def test_upload_get_prev_next(foss: Fossology, upload_with_jobs: Upload):
files, _ = foss.search(license="BSD")
prev_next = foss.get_prev_next(upload_with_jobs, files[0].uploadTreeId)
assert prev_next


@pytest.mark.skip(reason="Not yet released, waiting for API version 1.6.0")
def test_upload_get_prev_next_with_licenses(foss: Fossology, upload_with_jobs: Upload):
files, _ = foss.search(license="BSD")
prev_next = foss.get_prev_next(
Expand All @@ -127,6 +138,7 @@ def test_upload_get_prev_next_with_licenses(foss: Fossology, upload_with_jobs: U
assert prev_next


@pytest.mark.skip(reason="Not yet released, waiting for API version 1.6.0")
def test_upload_get_prev_next_no_clearing(foss: Fossology, upload_with_jobs: Upload):
files, _ = foss.search(license="BSD")
prev_next = foss.get_prev_next(
Expand All @@ -135,6 +147,7 @@ def test_upload_get_prev_next_no_clearing(foss: Fossology, upload_with_jobs: Upl
assert prev_next


@pytest.mark.skip(reason="Not yet released, waiting for API version 1.6.0")
def test_upload_get_prev_next_with_unknown_item_raises_api_error(
foss: Fossology, upload_with_jobs: Upload
):
Expand All @@ -143,6 +156,7 @@ def test_upload_get_prev_next_with_unknown_item_raises_api_error(
assert f"Upload {upload_with_jobs.id} or item 1 not found" in str(excinfo.value)


@pytest.mark.skip(reason="Not yet released, waiting for API version 1.6.0")
@responses.activate
def test_upload_get_prev_next_500_error(
foss: Fossology, foss_server: str, upload_with_jobs: Upload
Expand Down
8 changes: 4 additions & 4 deletions tests/test_upload_licenses_copyrights.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
def test_upload_licenses(foss: Fossology, upload_with_jobs: Upload):
# Default agent "nomos"
licenses = foss.upload_licenses(upload_with_jobs)
assert len(licenses) == 47
assert len(licenses) == 56


def test_upload_licenses_with_containers(foss: Fossology, upload_with_jobs: Upload):
Expand All @@ -23,17 +23,17 @@ def test_upload_licenses_with_containers(foss: Fossology, upload_with_jobs: Uplo

def test_upload_licenses_agent_ojo(foss: Fossology, upload_with_jobs: Upload):
licenses = foss.upload_licenses(upload_with_jobs, agent="ojo")
assert len(licenses) == 0
assert len(licenses) == 9


def test_upload_licenses_agent_monk(foss: Fossology, upload_with_jobs: Upload):
licenses = foss.upload_licenses(upload_with_jobs, agent="monk")
assert len(licenses) == 13
assert len(licenses) == 22


def test_upload_licenses_and_copyrights(foss: Fossology, upload_with_jobs: Upload):
licenses = foss.upload_licenses(upload_with_jobs, copyright=True)
assert len(licenses) == 47
assert len(licenses) == 56


def test_upload_licenses_with_unknown_group_raises_authorization_error(
Expand Down
2 changes: 1 addition & 1 deletion tests/test_uploads.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def test_copy_upload(foss: Fossology, upload: Upload):

def test_move_upload_to_non_existing_folder(foss: Fossology, upload: Upload):
non_folder = Folder(secrets.randbelow(1000), "Non folder", "", foss.rootFolder)
with pytest.raises(FossologyApiError):
with pytest.raises(AuthorizationError):
foss.move_upload(upload, non_folder, "move")


Expand Down
11 changes: 2 additions & 9 deletions tests/test_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,9 @@ def test_unknown_user(foss: Fossology):


def test_list_users(foss: Fossology):
# Fixture created_foss_user creates a new user for the test session
users = foss.list_users()
assert len(users) == 1
assert len(users) == 2


@responses.activate
Expand Down Expand Up @@ -161,11 +162,3 @@ def test_delete_user(foss_server: str, foss: Fossology):
with pytest.raises(FossologyApiError) as excinfo:
foss.delete_user(user)
assert f"Error while deleting user {user.name} ({user.id})" in str(excinfo.value)


@responses.activate
def test_noversion(foss_server: str, foss: Fossology):
responses.add(responses.GET, f"{foss_server}/api/v1/version", status=404)
with pytest.raises(FossologyApiError) as excinfo:
foss.get_version()
assert "Error while getting API version" in str(excinfo.value)

0 comments on commit 1f03171

Please sign in to comment.