about summary refs log tree commit diff
path: root/gn3/db/case_attributes.py
diff options
context:
space:
mode:
authorMunyoki Kilyungi2025-06-26 12:15:11 +0300
committerBonfaceKilz2025-07-07 07:58:31 +0300
commit0bf50a6944f3eda46de909ce06b1e43e24dfbedc (patch)
tree23b00c17ea082972b5eef67f3061654405e5ebdd /gn3/db/case_attributes.py
parentefe42cd86d7b333db6913341e9ee08b8be1d2838 (diff)
downloadgenenetwork3-0bf50a6944f3eda46de909ce06b1e43e24dfbedc.tar.gz
Add test cases for "update_case_attributes."
Signed-off-by: Munyoki Kilyungi <me@bonfacemunyoki.com>
Diffstat (limited to 'gn3/db/case_attributes.py')
-rw-r--r--gn3/db/case_attributes.py22
1 files changed, 13 insertions, 9 deletions
diff --git a/gn3/db/case_attributes.py b/gn3/db/case_attributes.py
index afebb7f..e14d99b 100644
--- a/gn3/db/case_attributes.py
+++ b/gn3/db/case_attributes.py
@@ -82,14 +82,17 @@ def queue_edit(cursor, directory: Path, edit: CaseAttributeEdit) -> Optional[int
 
 
 def update_case_attribute(cursor, directory: Path,
-                          change_id: int, edit: CaseAttributeEdit) -> int:
+                          change_id: int, edit: CaseAttributeEdit) -> bool:
     directory = f"{directory}/case-attributes/{edit.inbredset_id}"
     if not os.path.exists(directory):
         os.makedirs(directory)
     env = lmdb.open(directory, map_size=8_000_000)  # 1 MB
-    modifications = {}
-    if edit.changes.get("Modifications").get("Current"):
-        modifications = edit.get("Modifications").get("Current")
+    modifications = dict()
+    if edit.changes.get("Modifications") and \
+       edit.changes.get("Modifications").get("Current"):
+        modifications = edit.changes.get("Modifications").get("Current")
+    if not modifications:
+        return False
     for strain, changes in modifications.items():
         for case_attribute, value in changes.items():
             value = str(value).strip()
@@ -101,7 +104,7 @@ def update_case_attribute(cursor, directory: Path,
             cursor.execute("SELECT CaseAttributeId, Name AS CaseAttributeName "
                            "FROM CaseAttribute WHERE InbredSetId = %s "
                            "AND Name = %s",
-                           (inbredset_id, edit.inbredset_id,))
+                           (edit.inbredset_id, case_attribute,))
             case_attr_id, _ = cursor.fetchone()
             cursor.execute(
                 "INSERT INTO CaseAttributeXRefNew"
@@ -110,16 +113,17 @@ def update_case_attribute(cursor, directory: Path,
                 "ON DUPLICATE KEY UPDATE Value=VALUES(value)",
                 (edit.inbredset_id, strain_id, case_attr_id, value,))
             cursor.execute(
-                "UPDATE caseattributes_audit SET ",
+                "UPDATE caseattributes_audit SET "
                 "status = %s WHERE id = %s",
                 (str(edit.status), change_id,))
             with env.begin(write=True) as txn:
                 review_ids, approved_ids = set(), set()
                 if reviews := txn.get(b"review"):
                     review_ids = pickle.loads(reviews)
-                    review_ids.remove(change_id)
-                if approvals := txn.get(b"review"):
+                if approvals := txn.get(b"approved"):
                     approved_ids = pickle.loads(approvals)
-                    approved_ids.add(change_id)
+                review_ids.remove(change_id)
+                approved_ids.add(change_id)
                 txn.put(b"review", pickle.dumps(review_ids))
                 txn.put(b"approved", pickle.dumps(approved_ids))
+                return True