Skip to content

Commit

Permalink
Add the suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
Dhwaniartefact committed Oct 8, 2024
1 parent 61b2791 commit 4cd7dc9
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 33 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ repos:
(README)\.md
)
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.10.1
rev: v1.11.2
hooks:
- id: mypy
additional_dependencies:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,4 @@ module = [
"tests.test_fixity",
]
ignore_errors = false
disallow_untyped_calls = false

58 changes: 27 additions & 31 deletions tests/test_fixity.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import io
import json
import typing
import uuid
from datetime import datetime
from datetime import timezone
from typing import List
from typing import TextIO
from unittest import mock

import pytest
Expand Down Expand Up @@ -56,20 +56,20 @@ def mock_check_fixity() -> List[mock.Mock]:
]


def _assert_stream_content_matches(stream: typing.TextIO, expected: List[str]) -> None:
def _assert_stream_content_matches(stream: TextIO, expected: List[str]) -> None:
stream.seek(0)
assert [line.strip() for line in stream.readlines()] == expected


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

response = fixity.main(["scan", str(aip_id)], stream=stream)
response = fixity.main(["scan", str(aip_id)], stream=stream) # type: ignore

assert response == 0

Expand All @@ -92,16 +92,16 @@ def test_scan(
def test_scan_if_timestamps_argument_is_passed(
_get: mock.Mock,
time: mock.Mock,
environment: pytest.MonkeyPatch,
mock_check_fixity: mock.Mock,
environment: None,
mock_check_fixity: List[mock.Mock],
) -> None:
_get.side_effect = mock_check_fixity
aip_id = uuid.uuid4()
timestamp = 1514775600
time.return_value = timestamp
stream = io.StringIO()

response = fixity.main(["scan", str(aip_id), "--timestamps"], stream=stream)
response = fixity.main(["scan", str(aip_id), "--timestamps"], stream=stream) # type: ignore

assert response == 0

Expand Down Expand Up @@ -137,8 +137,8 @@ def test_scan_if_report_url_exists(
_get: mock.Mock,
utcnow: mock.Mock,
uuid4: mock.Mock,
mock_check_fixity: mock.Mock,
environment: pytest.MonkeyPatch,
mock_check_fixity: List[mock.Mock],
environment: None,
monkeypatch: pytest.MonkeyPatch,
) -> None:
uuid4.return_value = expected_uuid = uuid.uuid4()
Expand All @@ -149,7 +149,7 @@ def test_scan_if_report_url_exists(
aip_id = uuid.uuid4()
stream = io.StringIO()

response = fixity.main(["scan", str(aip_id)], stream=stream)
response = fixity.main(["scan", str(aip_id)], stream=stream) # type: ignore

assert response == 0

Expand Down Expand Up @@ -212,16 +212,16 @@ def test_scan_if_report_url_exists(
def test_scan_handles_exceptions_if_report_url_exists(
_post: mock.Mock,
_get: mock.Mock,
environment: pytest.MonkeyPatch,
environment: None,
monkeypatch: pytest.MonkeyPatch,
mock_check_fixity: mock.Mock,
mock_check_fixity: List[mock.Mock],
) -> None:
_get.side_effect = mock_check_fixity
aip_id = uuid.uuid4()
stream = io.StringIO()
monkeypatch.setenv("REPORT_URL", REPORT_URL)

response = fixity.main(["scan", str(aip_id)], stream=stream)
response = fixity.main(["scan", str(aip_id)], stream=stream) # type: ignore

assert response == 0

Expand Down Expand Up @@ -254,13 +254,11 @@ def test_scan_handles_exceptions_if_report_url_exists(
),
],
)
def test_scan_handles_exceptions(
_get: mock.Mock, environment: pytest.MonkeyPatch
) -> None:
def test_scan_handles_exceptions(_get: mock.Mock, environment: None) -> None:
aip_id = uuid.uuid4()
stream = io.StringIO()

response = fixity.main(["scan", str(aip_id)], stream=stream)
response = fixity.main(["scan", str(aip_id)], stream=stream) # type: ignore

assert response is None

Expand Down Expand Up @@ -292,11 +290,11 @@ def test_scan_handles_exceptions(
],
)
def test_scan_handles_exceptions_if_no_scan_attempted(
_get: mock.Mock, environment: pytest.MonkeyPatch
_get: mock.Mock, environment: None
) -> None:
aip_id = uuid.uuid4()

response = fixity.main(["scan", str(aip_id)])
response = fixity.main(["scan", str(aip_id)]) # type: ignore

assert response is None

Expand All @@ -312,12 +310,12 @@ def test_scan_handles_exceptions_if_no_scan_attempted(
],
ids=["Success", "Fail", "Did not run"],
)
def test_scan_message(status: mock.Mock, error_message: mock.Mock) -> None:
def test_scan_message(status: bool, error_message: str) -> None:
aip_id = uuid.uuid4()

response = fixity.scan_message(
aip_uuid=aip_id, status=status, message=error_message
)
) # type: ignore

assert (
response == f"Fixity scan {error_message} for AIP: {aip_id} ({error_message})"
Expand All @@ -328,7 +326,7 @@ def test_scan_message(status: mock.Mock, error_message: mock.Mock) -> None:
"requests.get",
)
def test_scanall(
_get: mock.Mock, environment: pytest.MonkeyPatch, mock_check_fixity: mock.Mock
_get: mock.Mock, environment: None, mock_check_fixity: List[mock.Mock]
) -> None:
aip1_uuid = str(uuid.uuid4())
aip2_uuid = str(uuid.uuid4())
Expand Down Expand Up @@ -359,7 +357,7 @@ def test_scanall(
]
stream = io.StringIO()

response = fixity.main(["scanall"], stream=stream)
response = fixity.main(["scanall"], stream=stream) # type: ignore

assert response == 0

Expand All @@ -374,9 +372,7 @@ def test_scanall(


@mock.patch("requests.get")
def test_scanall_handles_exceptions(
_get: mock.Mock, environment: pytest.MonkeyPatch
) -> None:
def test_scanall_handles_exceptions(_get: mock.Mock, environment: None) -> None:
aip_id1 = str(uuid.uuid4())
aip_id2 = str(uuid.uuid4())
_get.side_effect = [
Expand Down Expand Up @@ -422,7 +418,7 @@ def test_scanall_handles_exceptions(
]
stream = io.StringIO()

response = fixity.main(["scanall"], stream=stream)
response = fixity.main(["scanall"], stream=stream) # type: ignore

assert response == 1

Expand All @@ -438,7 +434,7 @@ def test_scanall_handles_exceptions(

@mock.patch("requests.get")
def test_main_handles_exceptions_if_scanall_fails(
_get: mock.Mock, environment: pytest.MonkeyPatch
_get: mock.Mock, environment: None
) -> None:
aip_id1 = str(uuid.uuid4())
aip_id2 = str(uuid.uuid4())
Expand Down Expand Up @@ -485,7 +481,7 @@ def test_main_handles_exceptions_if_scanall_fails(
]
stream = io.StringIO()

result = fixity.main(["scanall"], stream=stream)
result = fixity.main(["scanall"], stream=stream) # type: ignore

assert result == 1

Expand All @@ -501,7 +497,7 @@ def test_main_handles_exceptions_if_scanall_fails(

@mock.patch("requests.get")
def test_scanall_if_sort_argument_is_passed(
_get: mock.Mock, environment: pytest.MonkeyPatch, mock_check_fixity: mock.Mock
_get: mock.Mock, environment: None, mock_check_fixity: List[mock.Mock]
) -> None:
aip1_uuid = str(uuid.uuid4())
aip2_uuid = str(uuid.uuid4())
Expand Down Expand Up @@ -587,7 +583,7 @@ def test_scanall_if_sort_argument_is_passed(

stream = io.StringIO()

response = fixity.main(["scanall", "--sort"], stream=stream)
response = fixity.main(["scanall", "--sort"], stream=stream) # type: ignore

assert response == 1

Expand Down

0 comments on commit 4cd7dc9

Please sign in to comment.