Skip to content

Commit

Permalink
ADD delete project to CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
eboileau committed Aug 5, 2024
1 parent aabba1a commit 5fcf82d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
9 changes: 9 additions & 0 deletions server/src/scimodom/services/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,15 @@ def create_project_metadata_file(self, smid: str) -> TextIO:
metadata_file = Path(self._get_project_metadata_dir(), f"{smid}.json")
return open(metadata_file, "w", opener=write_opener)

def delete_project_metadata_file(self, smid: str) -> None:
"""Remove a metadata file.
:param smid: Sci-ModoM ID (SMID)
:type smid: str
"""
path = Path(self._get_project_metadata_dir(), f"{smid}.json")
path.unlink()

def create_project_request_file(self, request_uuid) -> TextIO:
"""Open a metadata (request) file for writing.
Expand Down
1 change: 1 addition & 0 deletions server/src/scimodom/services/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ def delete_project(self, project: Project) -> None:
if len(contact.projects) == 1:
self._session.delete(contact)
self._session.delete(project)
self._file_service.delete_project_metadata_file(project.id)
self._session.commit()
except Exception:
self._session.rollback()
Expand Down
6 changes: 6 additions & 0 deletions server/tests/unit/services/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class MockFileService:
def __init__(self):
self.files_by_name: dict[str, MockStringIO | MockBytesIO] = {}
self.deleted_requests: list[str] = []
self.deleted_projects: list[str] = []

def create_project_metadata_file(self, smid: str) -> TextIO:
metadata_file = Path(
Expand All @@ -51,6 +52,10 @@ def delete_project_request_file(self, request_uuid) -> None:
name = self._get_project_request_file_path(request_uuid).as_posix()
self.deleted_requests.append(name)

def delete_project_metadata_file(self, smid) -> None:
name = Path(self._get_project_metadata_dir(), f"{smid}.json").as_posix()
self.deleted_projects.append(name)

def _get_project_metadata_dir(self) -> Path:
return Path("/data", "metadata")

Expand Down Expand Up @@ -379,3 +384,4 @@ def test_delete_project(Session, project, file_service):
session.scalar(select(func.count()).select_from(UserProjectAssociation))
== 0
)
assert file_service.deleted_projects == ["/data/metadata/12345678.json"]

0 comments on commit 5fcf82d

Please sign in to comment.