Skip to content

Commit

Permalink
Extend the test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Dhwaniartefact committed Oct 18, 2024
1 parent 1387341 commit 8518312
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions tests/test_fixity.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from fixity import reporting
from fixity.models import Report
from fixity.models import Session
from fixity.storage_service import StorageServiceError

SESSION = Session()
STORAGE_SERVICE_URL = "http://localhost:8000/"
Expand Down Expand Up @@ -634,3 +635,58 @@ def test_scanall_if_sort_argument_is_passed(
params={"username": STORAGE_SERVICE_USER, "api_key": STORAGE_SERVICE_KEY},
),
]


@mock.patch("requests.get")
def test_main_handles_exception_if_environment_key_is_missing(
_get: mock.Mock, mock_check_fixity: List[mock.Mock]
) -> None:
_get.side_effect = mock_check_fixity
aip_id = uuid.uuid4()
stream = io.StringIO()

fixity.main(["scan", str(aip_id)], stream=stream)

assert fixity.ArgumentError("Missing environment variable: STORAGE_SERVICE_URL")


@mock.patch("requests.get")
def test_scanall_handles_exception_if_storage_serrvice_is_not_connected(
_get: mock.Mock, monkeypatch: pytest.MonkeyPatch
) -> None:
monkeypatch.setenv("STORAGE_SERVICE_URL", STORAGE_SERVICE_URL)
monkeypatch.setenv("STORAGE_SERVICE_USER", "")
monkeypatch.setenv("STORAGE_SERVICE_KEY", "")
aip_id1 = str(uuid.uuid4())
aip_id2 = str(uuid.uuid4())
_get.side_effect = [
mock.Mock(
**{
"status_code": 401,
"json.return_value": {
"meta": {"next": None},
"objects": [
{
"package_type": "AIP",
"status": "UPLOADED",
"uuid": f"{aip_id1}",
},
{
"package_type": "AIP",
"status": "UPLOADED",
"uuid": f"{aip_id2}",
},
],
},
},
spec=requests.Response,
side_effect=ConnectionError,
)
]
stream = io.StringIO()

fixity.main(["scanall"], stream=stream)

assert StorageServiceError(
f'Storage service at "{STORAGE_SERVICE_URL}" failed authentication while requesting AIPs'
)

0 comments on commit 8518312

Please sign in to comment.