From 30f305c1b87b4b6c4f308b15d5ae9248dc367e14 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Thu, 22 Sep 2022 06:33:47 +0300 Subject: Provide database cursor as argument for TheSpecies and Chromosomes Provide the database cursor as an argument to the methods of the two classes: * wqflask.base.species.TheSpecies * wqflask.base.species.Chromosomes Also update dependent code to initialise and pass the cursor where these classes are used. --- wqflask/tests/unit/base/test_species.py | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) (limited to 'wqflask/tests/unit') diff --git a/wqflask/tests/unit/base/test_species.py b/wqflask/tests/unit/base/test_species.py index d7ba30a3..f12bde6d 100644 --- a/wqflask/tests/unit/base/test_species.py +++ b/wqflask/tests/unit/base/test_species.py @@ -30,17 +30,14 @@ class MockDataset: (None, "Random Dataset", None, 1))) def test_species(mocker, species_name, dataset, expected_name, chromosome_param): - mock_conn = mocker.patch("base.species.database_connection") - mock_conn.return_value.__enter__.return_value = mocker.MagicMock() _c = mocker.patch("base.species.Chromosomes", return_value=chromosome_param) - with mock_conn() as conn: - test_species = TheSpecies(dataset=dataset, - species_name=species_name) - _c.assert_called_with(conn=conn, species=species_name, - dataset=dataset) - assert test_species.name == expected_name - assert test_species.chromosomes == chromosome_param + test_species = TheSpecies(dataset=dataset, + species_name=species_name) + _c.assert_called_with(species=species_name, + dataset=dataset) + assert test_species.name == expected_name + assert test_species.chromosomes == chromosome_param @pytest.mark.parametrize( @@ -74,9 +71,8 @@ def test_create_chromosomes(mocker, species, dataset, expected_call): cursor.fetchall.return_value = (("1", 2, 10,), ("2", 3, 11,), ("4", 5, 15,),) - _c = Chromosomes(conn=mock_conn, - dataset=dataset, species=species) - assert _c.chromosomes == OrderedDict([ + _c = Chromosomes(dataset=dataset, species=species) + assert _c.chromosomes(cursor) == OrderedDict([ ("1", IndChromosome("1", 10)), ("2", IndChromosome("2", 11)), ("4", IndChromosome("4", 15)), -- cgit v1.2.3