Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
islean committed May 30, 2024
1 parent addfb47 commit 56dcdaf
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
4 changes: 2 additions & 2 deletions tests/store/crud/test_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def test_get_analyses_by_status_started_at_and_comment(
existing_analysis: Analysis = analysis_store.get_query(table=Analysis).first()

# GIVEN a comment
analysis_store.update_analysis_comment(
analysis_store.update_latest_analysis_comment(
case_id=existing_analysis.case_id, comment="a new comment"
)

Expand All @@ -35,7 +35,7 @@ def test_get_analyses_by_status_started_at_and_comment_with_comment(analysis_sto
existing_analysis: Analysis = analysis_store.get_query(table=Analysis).first()

# GIVEN a comment
analysis_store.update_analysis_comment(
analysis_store.update_latest_analysis_comment(
case_id=existing_analysis.case_id, comment="a new comment"
)

Expand Down
6 changes: 3 additions & 3 deletions tests/store/crud/test_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ def test_update_analysis_comment(analysis_store: MockStore, case_id: str):
comment: str = "test comment"

# WHEN adding a comment
analysis_store.update_analysis_comment(case_id=analysis.case_id, comment=comment)
analysis_store.update_latest_analysis_comment(case_id=analysis.case_id, comment=comment)

# THEN a comment should have been added
assert analysis.comment == comment
Expand All @@ -350,8 +350,8 @@ def test_update_analysis_comment_when_existing(analysis_store: MockStore, case_i
second_comment: str = "Second"

# WHEN adding a comment
analysis_store.update_analysis_comment(case_id=analysis.case_id, comment=first_comment)
analysis_store.update_analysis_comment(case_id=analysis.case_id, comment=second_comment)
analysis_store.update_latest_analysis_comment(case_id=analysis.case_id, comment=first_comment)
analysis_store.update_latest_analysis_comment(case_id=analysis.case_id, comment=second_comment)

# THEN comments should have been added
assert analysis.comment == f"{first_comment} {second_comment}"
Expand Down
2 changes: 1 addition & 1 deletion trailblazer/server/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ def add_comment():
try:
case_id: str = put_request.get("case_id")
comment: str = put_request.get("comment")
store.update_analysis_comment(case_id=case_id, comment=comment)
store.update_latest_analysis_comment(case_id=case_id, comment=comment)
return jsonify("Success! Adding comment request sent"), HTTPStatus.CREATED
except Exception as error:
return jsonify(f"Exception: {error}"), HTTPStatus.CONFLICT
8 changes: 6 additions & 2 deletions trailblazer/store/crud/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def cancel_ongoing_analysis(
f"Analysis cancelled manually by user:"
f" {(self.get_user(email=email).name if self.get_user(email=email) else (email or 'Unknown'))}!"
)
analysis.comment = analysis.comment + new_comment if analysis.comment else new_comment
self.update_analysis_comment(analysis=analysis, comment=new_comment)
session: Session = get_session()
session.commit()

Expand Down Expand Up @@ -227,8 +227,12 @@ def update_analysis_uploaded_at(self, case_id: str, uploaded_at: datetime) -> No
session: Session = get_session()
session.commit()

def update_analysis_comment(self, case_id: str, comment: str) -> None:
def update_latest_analysis_comment(self, case_id: str, comment: str) -> None:
analysis: Analysis | None = self.get_latest_analysis_for_case(case_id)
self.update_analysis_comment(analysis=analysis, comment=comment)

@staticmethod
def update_analysis_comment(analysis: Analysis, comment: str):
analysis.comment: str = (
" ".join([analysis.comment, comment]) if analysis.comment else comment
)
Expand Down

0 comments on commit 56dcdaf

Please sign in to comment.