diff options
author | BonfaceKilz | 2021-06-03 11:08:58 +0300 |
---|---|---|
committer | BonfaceKilz | 2021-06-03 21:58:31 +0300 |
commit | 5d361fe5102a11afbd56aaab30e4a75a332c3e99 (patch) | |
tree | 81d61039106d9c283984c5b7507b618c074f3af1 | |
parent | 8d29add407d5662995dbc9e94901636b15d32475 (diff) | |
download | genenetwork3-5d361fe5102a11afbd56aaab30e4a75a332c3e99.tar.gz |
Add data structures for the table metadata_audit
-rw-r--r-- | gn3/db/__init__.py | 5 | ||||
-rw-r--r-- | gn3/db/metadata_audit.py | 26 | ||||
-rw-r--r-- | tests/unit/db/test_audit.py | 28 |
3 files changed, 59 insertions, 0 deletions
diff --git a/gn3/db/__init__.py b/gn3/db/__init__.py index d89dbf4..175a640 100644 --- a/gn3/db/__init__.py +++ b/gn3/db/__init__.py @@ -5,21 +5,26 @@ from dataclasses import dataclass, asdict, astuple from typing_extensions import Protocol from MySQLdb import escape_string +from gn3.db.metadata_audit import MetadataAudit from gn3.db.phenotypes import Phenotype from gn3.db.phenotypes import PublishXRef from gn3.db.phenotypes import Publication +from gn3.db.metadata_audit import metadata_audit_mapping from gn3.db.phenotypes import phenotype_mapping from gn3.db.phenotypes import publish_x_ref_mapping from gn3.db.phenotypes import publication_mapping + TABLEMAP = { + "metadata_audit": metadata_audit_mapping, "Phenotype": phenotype_mapping, "PublishXRef": publish_x_ref_mapping, "Publication": publication_mapping, } DATACLASSMAP = { + "MetadataAudit": MetadataAudit, "Phenotype": Phenotype, "PublishXRef": PublishXRef, "Publication": Publication, diff --git a/gn3/db/metadata_audit.py b/gn3/db/metadata_audit.py new file mode 100644 index 0000000..6e22b32 --- /dev/null +++ b/gn3/db/metadata_audit.py @@ -0,0 +1,26 @@ +# pylint: disable=[R0902, R0903] +"""This contains all the necessary functions that access the metadata_audit +table from the db + +""" +from dataclasses import dataclass +from typing import Optional + + +@dataclass(frozen=True) +class MetadataAudit: + """Data Type that represents a Phenotype""" + dataset_id: int + editor: str + json_data: str + time_stamp: Optional[str] = None + + +# Mapping from the MetadataAudit dataclass to the actual column names in the +# database +metadata_audit_mapping = { + "dataset_id": "dataset_id", + "editor": "editor", + "json_data": "json_data", + "time_stamp": "time_stamp", +} diff --git a/tests/unit/db/test_audit.py b/tests/unit/db/test_audit.py new file mode 100644 index 0000000..22787bb --- /dev/null +++ b/tests/unit/db/test_audit.py @@ -0,0 +1,28 @@ +"""Tests for db/phenotypes.py""" +import json +from unittest import TestCase +from unittest import mock + +from gn3.db import insert +from gn3.db.metadata_audit import MetadataAudit + + +class TestMetadatAudit(TestCase): + """Test cases for fetching chromosomes""" + + 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_data') " + 'VALUES (\'35\', \'Bonface\', \'{\\"a\\": \\"b\\"}\')') |