about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--gn3/api/case_attributes.py31
-rw-r--r--gn3/db/case_attributes.py5
-rw-r--r--tests/unit/db/test_case_attributes.py4
3 files changed, 23 insertions, 17 deletions
diff --git a/gn3/api/case_attributes.py b/gn3/api/case_attributes.py
index 837d0d1..536d74d 100644
--- a/gn3/api/case_attributes.py
+++ b/gn3/api/case_attributes.py
@@ -6,13 +6,6 @@ from urllib.parse import urljoin
 
 import requests
 from MySQLdb.cursors import DictCursor
-from gn3.db.case_attributes import (
-    CaseAttributeEdit,
-    EditStatus,
-    view_change,
-    queue_edit,
-    apply_change,
-    get_changes)
 from authlib.integrations.flask_oauth2.errors import _HTTPException
 from flask import (
     jsonify,
@@ -20,6 +13,13 @@ from flask import (
     Response,
     Blueprint,
     current_app)
+from gn3.db.case_attributes import (
+    CaseAttributeEdit,
+    EditStatus,
+    view_change,
+    queue_edit,
+    apply_change,
+    get_changes)
 
 
 from gn3.db_utils import Connection, database_connection
@@ -246,7 +246,8 @@ def edit_case_attributes(inbredset_id: int, auth_token=None) -> Response:
 
 
 @caseattr.route("/<int:inbredset_id>/diff/list", methods=["GET"])
-def list_diffs(inbredset_id: int) -> Response:
+@require_token
+def list_diffs(inbredset_id: int, auth_token=None) -> Response:
     """List any changes that have not been approved/rejected."""
     try:
         required_access(auth_token,
@@ -267,9 +268,9 @@ def list_diffs(inbredset_id: int) -> Response:
         }), 401
 
 
-@caseattr.route("/approve/<int:change_id>", methods=["POST"])
+@caseattr.route("/<int:inbredset_id>/approve/<int:change_id>", methods=["POST"])
 @require_token
-def approve_case_attributes_diff(filename: str, auth_token=None) -> Response:
+def approve_case_attributes_diff(inbredset_id: int, change_id: int, auth_token=None) -> Response:
     """Approve the changes to the case attributes in the diff."""
     try:
         required_access(auth_token,
@@ -278,6 +279,7 @@ def approve_case_attributes_diff(filename: str, auth_token=None) -> Response:
         with database_connection(current_app.config["SQL_URI"]) as conn, \
                 conn.cursor() as cursor:
             match apply_change(cursor, change_type=EditStatus.rejected,
+                               change_id=change_id,
                                directory=current_app.config["LMDB_DATA_PATH"]):
                 case True:
                     return jsonify({
@@ -296,9 +298,9 @@ def approve_case_attributes_diff(filename: str, auth_token=None) -> Response:
         }), 401
 
 
-@caseattr.route("/reject/<int:change_id>", methods=["POST"])
+@caseattr.route("/<int:inbredset_id>/reject/<int:change_id>", methods=["POST"])
 @require_token
-def reject_case_attributes_diff(filename: str, auth_token=None) -> Response:
+def reject_case_attributes_diff(inbredset_id: int, change_id: int, auth_token=None) -> Response:
     """Reject the changes to the case attributes in the diff."""
     try:
         required_access(auth_token,
@@ -308,6 +310,7 @@ def reject_case_attributes_diff(filename: str, auth_token=None) -> Response:
         with database_connection(current_app.config["SQL_URI"]) as conn, \
                 conn.cursor() as cursor:
             match apply_change(cursor, change_type=EditStatus.rejected,
+                               change_id=change_id,
                                directory=current_app.config["LMDB_DATA_PATH"]):
                 case True:
                     return jsonify({
@@ -326,9 +329,9 @@ def reject_case_attributes_diff(filename: str, auth_token=None) -> Response:
         }), 401
 
 
-@caseattr.route("/<int:change_id>/diff/view", methods=["GET"])
+@caseattr.route("/<int:inbredset_id>/diff/<int:change_id>/view", methods=["GET"])
 @require_token
-def view_diff(inbredset_id: int, diff_id: int, auth_token=None) -> Response:
+def view_diff(inbredset_id: int, change_id: int, auth_token=None) -> Response:
     """View a diff."""
     try:
         required_access(
diff --git a/gn3/db/case_attributes.py b/gn3/db/case_attributes.py
index c164b06..b16bbdd 100644
--- a/gn3/db/case_attributes.py
+++ b/gn3/db/case_attributes.py
@@ -252,9 +252,10 @@ def get_changes(cursor, inbredset_id: int, directory: Path) -> dict:
     }
 
 
-# pylint: disable[too-many-locals]
+# pylint: disable=[too-many-locals]
 def apply_change(cursor, change_type: EditStatus, change_id: int, directory: Path) -> bool:
-    """Applies or rejects a case attribute change and updates its status in the audit table and LMDB.
+    """Applies or rejects a case attribute change and updates its
+    status in the audit table and LMDB.
 
     Processes a change identified by `change_id` based on the
     specified `change_type` (approved or rejected). For approved
diff --git a/tests/unit/db/test_case_attributes.py b/tests/unit/db/test_case_attributes.py
index f5f2058..d9da253 100644
--- a/tests/unit/db/test_case_attributes.py
+++ b/tests/unit/db/test_case_attributes.py
@@ -1,11 +1,11 @@
 """Test cases for gn3.db.case_attributes.py"""
 
-import pytest
 import pickle
 import tempfile
 import os
 import json
 from pathlib import Path
+import pytest
 from pytest_mock import MockFixture
 from gn3.db.case_attributes import queue_edit
 from gn3.db.case_attributes import (
@@ -18,6 +18,7 @@ from gn3.db.case_attributes import (
 
 @pytest.mark.unit_test
 def test_queue_edit(mocker: MockFixture) -> None:
+    """Test queueing an edit."""
     mock_conn = mocker.MagicMock()
     with mock_conn.cursor() as cursor:
         type(cursor).lastrowid = 28
@@ -90,6 +91,7 @@ def test_view_change_no_data(mocker: MockFixture) -> None:
     "Test no result when view_change is called"
     change_id = 28
     mock_cursor, mock_conn = mocker.MagicMock(), mocker.MagicMock()
+    mock_conn.cursor.return_value = mock_cursor
     mock_cursor.fetchone.return_value = (None, None)
     assert view_change(mock_cursor, change_id) == {}
     mock_cursor.execute.assert_called_once_with(