diff options
author | Munyoki Kilyungi | 2022-09-07 11:47:26 +0300 |
---|---|---|
committer | BonfaceKilz | 2022-09-08 14:26:19 +0300 |
commit | b6fadcc7e8de9d7041f2bb00dcd1ada518a1932c (patch) | |
tree | cc0199f48307568ee2bdab16d7ec0c8774fda50e /wqflask/tests/unit/base | |
parent | f879f82ad0393a770ed50043c70ee1dd4a12daaa (diff) | |
download | genenetwork2-b6fadcc7e8de9d7041f2bb00dcd1ada518a1932c.tar.gz |
Inject database connection to mrna_assay_tissue_data class
* wqflask/base/mrna_assay_tissue_data.py: Imports: Delete
database_connection, escape, and database_connector.
(MrnaAssayTissueData): Inject conn. Re-format queries. Rework 'if
... else' logic. Re-work how results are assigned to
'self.data[symbol]' - remove dot-notation.
(MrnaAssayTissueData.get_symbol_values_pairs): Move box-comments to
doc-string. Rework how results are assigned to 'symbol_values_dict' -
remove dot-notation.
* wqflask/tests/unit/base/test_mrna_assay_tissue_data.py
(test_mrna_assay_tissue_data_initialisation): New test.
* wqflask/wqflask/correlation/correlation_functions.py: Import
database_connection.
(get_trait_symbol_and_tissue_values): Inject conn object.
Diffstat (limited to 'wqflask/tests/unit/base')
-rw-r--r-- | wqflask/tests/unit/base/test_mrna_assay_tissue_data.py | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/wqflask/tests/unit/base/test_mrna_assay_tissue_data.py b/wqflask/tests/unit/base/test_mrna_assay_tissue_data.py new file mode 100644 index 00000000..7a21124a --- /dev/null +++ b/wqflask/tests/unit/base/test_mrna_assay_tissue_data.py @@ -0,0 +1,51 @@ +import pytest +from base.mrna_assay_tissue_data import MrnaAssayTissueData + + +@pytest.mark.parametrize( + ('gene_symbols', 'expected_query', 'sql_fetch_all_results'), + ( + (None, + (("SELECT t.Symbol, t.GeneId, t.DataId, " + "t.Chr, t.Mb, t.description, " + "t.Probe_Target_Description " + "FROM (SELECT Symbol, " + "max(Mean) AS maxmean " + "FROM TissueProbeSetXRef WHERE " + "TissueProbeSetFreezeId=1 AND " + "Symbol != '' AND Symbol IS NOT " + "Null GROUP BY Symbol) " + "AS x INNER JOIN TissueProbeSetXRef " + "AS t ON t.Symbol = x.Symbol " + "AND t.Mean = x.maxmean"),), + (("symbol", "gene_id", + "data_id", "chr", "mb", + "description", + "probe_target_description"),)), + (["k1", "k2", "k3"], + ("SELECT t.Symbol, t.GeneId, t.DataId, " + "t.Chr, t.Mb, t.description, " + "t.Probe_Target_Description FROM (SELECT Symbol, " + "max(Mean) AS maxmean " + "FROM TissueProbeSetXRef WHERE " + "TissueProbeSetFreezeId=1 AND " + "Symbol IN (%s, %s, %s) " + "GROUP BY Symbol) AS x INNER JOIN " + "TissueProbeSetXRef AS " + "t ON t.Symbol = x.Symbol " + "AND t.Mean = x.maxmean", + ("k1", "k2", "k3")), + (("k1", "203", + "112", "xy", "20.11", + "Sample Description", + "Sample Probe Target Description"),)), + ), +) +def test_mrna_assay_tissue_data_initialisation(mocker, gene_symbols, + expected_query, + sql_fetch_all_results): + mock_conn = mocker.MagicMock() + with mock_conn.cursor() as cursor: + cursor.fetchall.return_value = sql_fetch_all_results + MrnaAssayTissueData(conn=mock_conn, gene_symbols=gene_symbols) + cursor.execute.assert_called_with(*expected_query) |