aboutsummaryrefslogtreecommitdiff
path: root/tests/unit/db/test_db.py
diff options
context:
space:
mode:
authorBonfaceKilz2021-06-07 11:16:45 +0300
committerBonfaceKilz2021-06-07 19:58:44 +0300
commit8668dabeb44c72c54f2c91a9b0f6814042df4d85 (patch)
treee95c2bf4d03fbfb1049b1dc297d26b6c5de9f512 /tests/unit/db/test_db.py
parentae77ad6f35999dd416590f2a9d9d6451880a4a70 (diff)
downloadgenenetwork3-8668dabeb44c72c54f2c91a9b0f6814042df4d85.tar.gz
tests: test_db: Add a test-case for fetchall
Diffstat (limited to 'tests/unit/db/test_db.py')
-rw-r--r--tests/unit/db/test_db.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/unit/db/test_db.py b/tests/unit/db/test_db.py
index 2e38d4c..485678f 100644
--- a/tests/unit/db/test_db.py
+++ b/tests/unit/db/test_db.py
@@ -2,10 +2,12 @@
from unittest import TestCase
from unittest import mock
+from gn3.db import fetchall
from gn3.db import fetchone
from gn3.db import update
from gn3.db import diff_from_dict
from gn3.db.phenotypes import Phenotype
+from gn3.db.metadata_audit import MetadataAudit
class TestCrudMethods(TestCase):
@@ -65,6 +67,35 @@ class TestCrudMethods(TestCase):
"SELECT * FROM Phenotype WHERE id = %s AND Owner = %s",
(35, 'Rob'))
+ def test_fetchall_metadataaudit(self):
+ """Test that multiple metadata_audit entries are fetched properly
+
+ """
+ db_mock = mock.MagicMock()
+ with db_mock.cursor() as cursor:
+ test_data = (
+ 35, "Rob", ('{"pages": '
+ '{"old": "5099-5109", '
+ '"new": "5099-5110"}, '
+ '"month": {"old": "July", '
+ '"new": "June"}, '
+ '"year": {"old": "2001", '
+ '"new": "2002"}}'),
+ "2021-06-04 09:01:05"
+ )
+ cursor.fetchall.return_value = (test_data,)
+ metadata = list(fetchall(db_mock,
+ "metadata_audit",
+ where=MetadataAudit(dataset_id=35,
+ editor="Rob")))[0]
+ self.assertEqual(metadata.dataset_id, 35)
+ self.assertEqual(metadata.time_stamp,
+ "2021-06-04 09:01:05")
+ cursor.execute.assert_called_once_with(
+ ("SELECT * FROM metadata_audit WHERE "
+ "dataset_id = %s AND editor = %s"),
+ (35, 'Rob'))
+
def test_diff_from_dict(self):
"""Test that a correct diff is generated"""
self.assertEqual(diff_from_dict({"id": 1, "data": "a"},