aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gn3/db/sample_data.py9
-rw-r--r--tests/unit/db/test_sample_data.py23
2 files changed, 21 insertions, 11 deletions
diff --git a/gn3/db/sample_data.py b/gn3/db/sample_data.py
index e5c5e48..c697de0 100644
--- a/gn3/db/sample_data.py
+++ b/gn3/db/sample_data.py
@@ -22,7 +22,10 @@ def __extract_actions(original_data: str,
"insert": {"data": [], "csv_header": []},
"update": {"data": [], "csv_header": []},
}
+ strain_name = ""
for _o, _u, _h in zip(original_data, updated_data, csv_header):
+ if _h == "Strain Name":
+ strain_name = _o
if _o == _u: # No change
continue
elif _o and _u == "x": # Deletion
@@ -38,8 +41,10 @@ def __extract_actions(original_data: str,
if not val["data"]:
result[key] = None
else:
- result[key]["data"] = ",".join(result[key]["data"])
- result[key]["csv_header"] = ",".join(result[key]["csv_header"])
+ result[key]["data"] = (f"{strain_name}," +
+ ",".join(result[key]["data"]))
+ result[key]["csv_header"] = ("Strain Name," +
+ ",".join(result[key]["csv_header"]))
return result
diff --git a/tests/unit/db/test_sample_data.py b/tests/unit/db/test_sample_data.py
index 84ab1a1..0fa2604 100644
--- a/tests/unit/db/test_sample_data.py
+++ b/tests/unit/db/test_sample_data.py
@@ -84,17 +84,22 @@ def test_extract_actions():
updated_data="BXD1,x,2,1,F",
csv_header="Strain Name,Value,SE,Count,Sex") ==
{
- "delete": {"data": "18", "csv_header": "Value"},
- "insert": {"data": "2,F", "csv_header": "SE,Sex"},
- "update": {"data": "1", "csv_header": "Count"},
+ "delete": {"data": "BXD1,18",
+ "csv_header": "Strain Name,Value"},
+ "insert": {"data": "BXD1,2,F",
+ "csv_header": "Strain Name,SE,Sex"},
+ "update": {"data": "BXD1,1",
+ "csv_header": "Strain Name,Count"},
})
assert(__extract_actions(original_data="BXD1,18,x,0,x",
updated_data="BXD1,19,2,1,F",
csv_header="Strain Name,Value,SE,Count,Sex") ==
{
"delete": None,
- "insert": {"data": "2,F", "csv_header": "SE,Sex"},
- "update": {"data": "19,1", "csv_header": "Value,Count"},
+ "insert": {"data": "BXD1,2,F",
+ "csv_header": "Strain Name,SE,Sex"},
+ "update": {"data": "BXD1,19,1",
+ "csv_header": "Strain Name,Value,Count"},
})
@@ -119,14 +124,14 @@ def test_update_sample_data(mocker):
gn3.db.sample_data.insert_sample_data.assert_called_once_with(
conn=mock_conn,
trait_name=35,
- data="2,F",
- csv_header="SE,Sex",
+ data="BXD1,2,F",
+ csv_header="Strain Name,SE,Sex",
phenotype_id=10007)
gn3.db.sample_data.delete_sample_data.assert_called_once_with(
conn=mock_conn,
trait_name=35,
- data="18",
- csv_header="Value",
+ data="BXD1,18",
+ csv_header="Strain Name,Value",
phenotype_id=10007)
cursor.execute.assert_has_calls(
[mocker.call("UPDATE NStrain SET count = %s "