From b18de873dbead76276ee5077bc8a2afe78f61606 Mon Sep 17 00:00:00 2001 From: BonfaceKilz Date: Wed, 6 Apr 2022 16:36:52 +0300 Subject: Use case attribute id inside brackets if present during insertions * gn3/db/sample_data.py (delete_sample_data): If an id is present in the column header, use it. * tests/unit/db/test_sample_data.py (test_delete_sample_data): Update tests to capture the above. --- tests/unit/db/test_sample_data.py | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) (limited to 'tests/unit') diff --git a/tests/unit/db/test_sample_data.py b/tests/unit/db/test_sample_data.py index e7d7fb0..f631239 100644 --- a/tests/unit/db/test_sample_data.py +++ b/tests/unit/db/test_sample_data.py @@ -90,13 +90,6 @@ def test_delete_sample_data(mocker): mock_conn = mocker.MagicMock() strain_id, data_id, inbredset_id = 1, 17373, 20 with mock_conn.cursor() as cursor: - cursor.fetchone.side_effect = ( - 0, - [ - 19, - ], - 0, - ) mocker.patch( "gn3.db.sample_data.get_sample_data_ids", return_value=(strain_id, data_id, inbredset_id), @@ -104,21 +97,21 @@ def test_delete_sample_data(mocker): delete_sample_data( conn=mock_conn, trait_name=35, - data="BXD1,18,3,0,M", - csv_header="Strain Name,Value,SE,Count,Sex", + data="BXD1,18,3,0,Red,M", + csv_header="Strain Name,Value,SE,Count,Color,Sex (17)", phenotype_id=10007, ) calls = [ mocker.call( - "DELETE FROM PublishData WHERE " "StrainId = %s AND Id = %s", + "DELETE FROM PublishData WHERE StrainId = %s AND Id = %s", (strain_id, data_id), ), mocker.call( - "DELETE FROM PublishSE WHERE " "StrainId = %s AND DataId = %s", + "DELETE FROM PublishSE WHERE StrainId = %s AND DataId = %s", (strain_id, data_id), ), mocker.call( - "DELETE FROM NStrain WHERE " "StrainId = %s AND DataId = %s", + "DELETE FROM NStrain WHERE StrainId = %s AND DataId = %s", (strain_id, data_id), ), mocker.call( @@ -127,7 +120,13 @@ def test_delete_sample_data(mocker): "(SELECT CaseAttributeId FROM " "CaseAttribute WHERE Name = %s) " "AND InbredSetId = %s", - (strain_id, "Sex", inbredset_id), + (strain_id, "Color", inbredset_id), + ), + mocker.call( + "DELETE FROM CaseAttributeXRefNew WHERE " + "StrainId = %s AND CaseAttributeId = %s " + "AND InbredSetId = %s", + (strain_id, "17", inbredset_id), ), ] cursor.execute.assert_has_calls(calls, any_order=False) -- cgit v1.2.3