fix: clear the type checker and linter findings
flake8 reported 49 findings and pyright 10, and two of them were real bugs rather than matters of style. The rest were unused imports and four functions over the complexity limit. - Unlock a DOI folder with the id the DOI response carries, rather than an attribute the model does not have, which raised `AttributeError` on every locked DOI folder. - Size the `ls` Size column from the sub-folder on the row rather than from its parent, which pushed the later columns out of line. - Share the path resolution and the destination checks between `cp` and `mv`, and split the recursive download and the `ls` row printing, bringing all four functions under the complexity limit. - Accept a client built without a connection, which `config` and `version` rely on, and report the reason if one is then asked for. - Declare the config protocol's constructor for the type checker alone, so the protocol keeps its guard against being instantiated. - Remove 41 unused imports, and let flake8 accept black's spacing. - Point pyright at the project's own environment, without which it resolved no dependency and reported 124 findings that were not real. - Cover the two fixes and the shared `cp`/`mv` paths with new tests.
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
import unittest
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
from mdrsclient.models import Doi, Folder, Laboratories, Laboratory
|
||||
from mdrsclient.services import MdrsService
|
||||
|
||||
TIMESTAMP = "2026-01-01T00:00:00+09:00"
|
||||
DOI = "10.60178/cbs.20260429-001"
|
||||
LABORATORY = Laboratory(id=1, name="mylab", pi_name="PI", full_name="My Laboratory")
|
||||
|
||||
|
||||
def make_locked_folder() -> Folder:
|
||||
return Folder(
|
||||
id="f1",
|
||||
pid=None,
|
||||
name="root",
|
||||
access_level=4,
|
||||
lock=True,
|
||||
size=0,
|
||||
laboratory_id=1,
|
||||
description="",
|
||||
created_at=TIMESTAMP,
|
||||
updated_at=TIMESTAMP,
|
||||
restrict_opened_at=None,
|
||||
metadata=[],
|
||||
sub_folders=[],
|
||||
path="/root/",
|
||||
)
|
||||
|
||||
|
||||
class TestFindFolderByDoi(unittest.TestCase):
|
||||
"""The DOI response carries the folder id as a field, not as a nested object."""
|
||||
|
||||
def test_a_locked_doi_folder_is_unlocked_with_its_folder_id(self):
|
||||
laboratories = Laboratories()
|
||||
laboratories.append(LABORATORY)
|
||||
|
||||
with (
|
||||
patch("mdrsclient.services.DoiApi") as doi_api,
|
||||
patch("mdrsclient.services.FoldersApi") as folders_api,
|
||||
patch("mdrsclient.services.LaboratoriesApi") as laboratories_api,
|
||||
):
|
||||
doi_api.return_value.retrieve.return_value = Doi(id="20260429-001", doi=DOI, folder_id="f1")
|
||||
folders_api.return_value.retrieve.return_value = make_locked_folder()
|
||||
laboratories_api.return_value.list.return_value = laboratories
|
||||
|
||||
folder, laboratory = MdrsService(MagicMock()).find_folder_by_doi(DOI, "secret")
|
||||
|
||||
folders_api.return_value.auth.assert_called_once_with("f1", "secret")
|
||||
self.assertEqual(folder.id, "f1")
|
||||
self.assertEqual(laboratory.name, "mylab")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user