]> Nutra Git (v1) - nutratech/cli.git/commitdiff
fully cover: sql/__init__.py
authorShane Jaroch <chown_tee@proton.me>
Fri, 12 Apr 2024 22:43:34 +0000 (18:43 -0400)
committerShane Jaroch <chown_tee@proton.me>
Fri, 12 Apr 2024 22:43:34 +0000 (18:43 -0400)
ntclient/persistence/sql/__init__.py
tests/persistence/__init__.py [new file with mode: 0644]
tests/persistence/test_sql.py [new file with mode: 0644]

index 56c8d0dd6101a0d653dff82d997b905924c1ed98..e30cafae29ae4860be52e3d253a0b67c1baca8fd 100644 (file)
@@ -81,10 +81,10 @@ def _prep_query(
 
     # TODO: separate `entry` & `entries` entity for single vs. bulk insert?
     if values:
-        if isinstance(values, list):
-            cur.executemany(query, values)
-        elif isinstance(values, tuple):
+        if isinstance(values, tuple):
             cur.execute(query, values)
+        # elif isinstance(values, list):
+        #     cur.executemany(query, values)
         else:
             raise TypeError("'values' must be a list or tuple!")
 
diff --git a/tests/persistence/__init__.py b/tests/persistence/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/tests/persistence/test_sql.py b/tests/persistence/test_sql.py
new file mode 100644 (file)
index 0000000..7f51aff
--- /dev/null
@@ -0,0 +1,22 @@
+# -*- coding: utf-8 -*-
+"""
+Created on Fri Apr 12 18:22:39 2024
+
+@author: shane
+"""
+import pytest
+
+from ntclient.persistence.sql import _prep_query
+from ntclient.persistence.sql.nt import nt_sqlite_connect
+
+
+def test_prep_query_with_non_iterative_values_throws_type_error() -> None:
+    """Test the _prep_query method if a bare (non-iterative) values is passed in."""
+
+    con = nt_sqlite_connect()
+    query = "SELECT * FROM version WHERE id = ?;"
+    db_name = "nt"
+    values = 1
+
+    with pytest.raises(TypeError):
+        _prep_query(con, query, db_name, values)  # type: ignore