about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2023-08-02 10:27:10 +0300
committerFrederick Muriuki Muriithi2023-08-02 10:27:10 +0300
commit6fb63b348f77d4cce29278cf06191a11a3b6d95d (patch)
tree3f56e9ee4bb6fd4ab8b238f6758a115fd1ffbe17
parentabf648858a1a29d452f0efadf53bf5524dde31db (diff)
downloadgenenetwork3-6fb63b348f77d4cce29278cf06191a11a3b6d95d.tar.gz
Remove ORM-dependent `insert` function
Remove the object-relation-mapping dependent `insert` function to prevent it
being used in the code down the line.
-rw-r--r--gn3/db/__init__.py16
-rw-r--r--tests/unit/db/test_audit.py31
2 files changed, 0 insertions, 47 deletions
diff --git a/gn3/db/__init__.py b/gn3/db/__init__.py
index 5676eb5..95b39d4 100644
--- a/gn3/db/__init__.py
+++ b/gn3/db/__init__.py
@@ -63,22 +63,6 @@ def update(conn: Any,
         conn.commit()
         return cursor.rowcount
 
-def insert(conn: Any,
-           table: str,
-           data: Dataclass) -> Optional[int]:
-    """Run an INSERT into a table"""
-    dict_ = {TABLEMAP[table].get(k): v for k, v in asdict(data).items()
-             if v is not None and k in TABLEMAP[table]}
-    sql = f"INSERT INTO {table} ("
-    sql += ", ".join(f"{k}" for k in dict_.keys())
-    sql += ") VALUES ("
-    sql += ", ".join("%s" for _ in dict_.keys())
-    sql += ")"
-    with conn.cursor() as cursor:
-        cursor.execute(sql, tuple(dict_.values()))
-        conn.commit()
-        return cursor.rowcount
-
 
 def diff_from_dict(old: Dict, new: Dict) -> Dict:
     """Construct a new dict with a specific structure that contains the difference
diff --git a/tests/unit/db/test_audit.py b/tests/unit/db/test_audit.py
deleted file mode 100644
index 884afc6..0000000
--- a/tests/unit/db/test_audit.py
+++ /dev/null
@@ -1,31 +0,0 @@
-"""Tests for db/phenotypes.py"""
-import json
-from unittest import TestCase
-from unittest import mock
-
-import pytest
-
-from gn3.db import insert
-from gn3.db.metadata_audit import MetadataAudit
-
-
-class TestMetadatAudit(TestCase):
-    """Test cases for fetching chromosomes"""
-
-    @pytest.mark.unit_test
-    def test_insert_into_metadata_audit(self):
-        """Test that data is inserted correctly in the audit table
-
-        """
-        db_mock = mock.MagicMock()
-        with db_mock.cursor() as cursor:
-            type(cursor).rowcount = 1
-            self.assertEqual(insert(
-                conn=db_mock, table="metadata_audit",
-                data=MetadataAudit(dataset_id=35,
-                                   editor="Bonface",
-                                   json_data=json.dumps({"a": "b"}))), 1)
-            cursor.execute.assert_called_once_with(
-                "INSERT INTO metadata_audit (dataset_id, "
-                "editor, json_diff_data) VALUES (%s, %s, %s)",
-                (35, 'Bonface', '{"a": "b"}'))