From a3c7aa69a9d0bb15b7dcaf0c704cd51ace2aabd4 Mon Sep 17 00:00:00 2001 From: James Woglom Date: Wed, 21 Apr 2021 01:38:53 -0400 Subject: [PATCH] tests: add bolus parsing tests --- Pipfile | 2 +- tconnectsync/parser/nightscout.py | 4 +- tests/parser/test_tconnect.py | 183 +++++++++++++++++++++++++++++- tests/sync/test_bolus.py | 156 ++++--------------------- tests/test_process.py | 5 +- 5 files changed, 208 insertions(+), 142 deletions(-) diff --git a/Pipfile b/Pipfile index 5724e2b..d066da1 100644 --- a/Pipfile +++ b/Pipfile @@ -14,4 +14,4 @@ python-dotenv = "*" [scripts] tconnectsync = "python3 main.py" -test = "python3 -m unittest discover" \ No newline at end of file +test = "python3 -m unittest discover -vv" \ No newline at end of file diff --git a/tconnectsync/parser/nightscout.py b/tconnectsync/parser/nightscout.py index 501fb58..2c30849 100644 --- a/tconnectsync/parser/nightscout.py +++ b/tconnectsync/parser/nightscout.py @@ -25,8 +25,8 @@ class NightscoutEntry: return { "eventType": BOLUS_EVENTTYPE, "created_at": created_at, - "carbs": carbs, - "insulin": bolus, + "carbs": int(carbs), + "insulin": float(bolus), "notes": notes, "enteredBy": ENTERED_BY, } diff --git a/tests/parser/test_tconnect.py b/tests/parser/test_tconnect.py index fc57ecc..224ed09 100644 --- a/tests/parser/test_tconnect.py +++ b/tests/parser/test_tconnect.py @@ -3,7 +3,7 @@ import unittest from tconnectsync.parser.tconnect import TConnectEntry -class TestTConnectEntry(unittest.TestCase): +class TestTConnectEntryBasal(unittest.TestCase): def test_parse_ciq_basal_entry(self): self.assertEqual( TConnectEntry.parse_ciq_basal_entry({ @@ -33,6 +33,187 @@ class TestTConnectEntry(unittest.TestCase): } ) +class TestTConnectEntryBolus(unittest.TestCase): + entryStdCorrection = { + "Type": "Bolus", + "Description": "Standard/Correction", + "BG": "141", + "IOB": "", + "BolusRequestID": "7001.000", + "BolusCompletionID": "7001.000", + "CompletionDateTime": "2021-04-01T12:58:26", + "InsulinDelivered": "13.53", + "FoodDelivered": "12.50", + "CorrectionDelivered": "1.03", + "CompletionStatusID": "3", + "CompletionStatusDesc": "Completed", + "BolusIsComplete": "1", + "BolexCompletionID": "", + "BolexSize": "", + "BolexStartDateTime": "", + "BolexCompletionDateTime": "", + "BolexInsulinDelivered": "", + "BolexIOB": "", + "BolexCompletionStatusID": "", + "BolexCompletionStatusDesc": "", + "ExtendedBolusIsComplete": "", + "EventDateTime": "2021-04-01T12:53:36", + "RequestDateTime": "2021-04-01T12:53:36", + "BolusType": "Carb", + "BolusRequestOptions": "Standard/Correction", + "StandardPercent": "100.00", + "Duration": "0", + "CarbSize": "75", + "UserOverride": "0", + "TargetBG": "110", + "CorrectionFactor": "30.00", + "FoodBolusSize": "12.50", + "CorrectionBolusSize": "1.03", + "ActualTotalBolusRequested": "13.53", + "IsQuickBolus": "0", + "EventHistoryReportEventDesc": "0", + "EventHistoryReportDetails": "Correction & Food Bolus", + "NoteID": "CF 1:30 - Carb Ratio 1:6 - Target BG 110", + "IndexID": "0", + "Note": "1181649" + } + def test_parse_bolus_entry_std_correction(self): + self.assertEqual( + TConnectEntry.parse_bolus_entry(self.entryStdCorrection), + { + "description": "Standard/Correction", + "complete": "1", + "completion": "Completed", + "request_time": "2021-04-01 12:53:36-04:00", + "completion_time": "2021-04-01 12:58:26-04:00", + "insulin": "13.53", + "carbs": "75", + "user_override": "0", + "extended_bolus": "", + "bolex_completion_time": None, + "bolex_start_time": None + }) + + entryStd = { + "Type": "Bolus", + "Description": "Standard", + "BG": "159", + "IOB": "2.13", + "BolusRequestID": "7007.000", + "BolusCompletionID": "7007.000", + "CompletionDateTime": "2021-04-01T23:23:17", + "InsulinDelivered": "1.25", + "FoodDelivered": "0.00", + "CorrectionDelivered": "0.00", + "CompletionStatusID": "3", + "CompletionStatusDesc": "Completed", + "BolusIsComplete": "1", + "BolexCompletionID": "", + "BolexSize": "", + "BolexStartDateTime": "", + "BolexCompletionDateTime": "", + "BolexInsulinDelivered": "", + "BolexIOB": "", + "BolexCompletionStatusID": "", + "BolexCompletionStatusDesc": "", + "ExtendedBolusIsComplete": "", + "EventDateTime": "2021-04-01T23:21:58", + "RequestDateTime": "2021-04-01T23:21:58", + "BolusType": "Carb", + "BolusRequestOptions": "Standard", + "StandardPercent": "100.00", + "Duration": "0", + "CarbSize": "0", + "UserOverride": "1", + "TargetBG": "110", + "CorrectionFactor": "30.00", + "FoodBolusSize": "0.00", + "CorrectionBolusSize": "0.00", + "ActualTotalBolusRequested": "1.25", + "IsQuickBolus": "0", + "EventHistoryReportEventDesc": "0", + "EventHistoryReportDetails": "Food Bolus", + "NoteID": "CF 1:30 - Carb Ratio 1:6 - Target BG 110 | Override: Pump calculated Bolus = 0.0 units", + "IndexID": "0", + "Note": "1182867" + } + def test_parse_bolus_entry_std(self): + self.assertEqual( + TConnectEntry.parse_bolus_entry(self.entryStd), + { + "description": "Standard", + "complete": "1", + "completion": "Completed", + "request_time": "2021-04-01 23:21:58-04:00", + "completion_time": "2021-04-01 23:23:17-04:00", + "insulin": "1.25", + "carbs": "0", + "user_override": "1", + "extended_bolus": "", + "bolex_completion_time": None, + "bolex_start_time": None + }) + + entryStdAutomatic = { + "Type": "Bolus", + "Description": "Automatic Bolus/Correction", + "BG": "", + "IOB": "3.24", + "BolusRequestID": "7010.000", + "BolusCompletionID": "7010.000", + "CompletionDateTime": "2021-04-02T01:00:47", + "InsulinDelivered": "1.70", + "FoodDelivered": "0.00", + "CorrectionDelivered": "1.70", + "CompletionStatusID": "3", + "CompletionStatusDesc": "Completed", + "BolusIsComplete": "1", + "BolexCompletionID": "", + "BolexSize": "", + "BolexStartDateTime": "", + "BolexCompletionDateTime": "", + "BolexInsulinDelivered": "", + "BolexIOB": "", + "BolexCompletionStatusID": "", + "BolexCompletionStatusDesc": "", + "ExtendedBolusIsComplete": "", + "EventDateTime": "2021-04-02T00:59:13", + "RequestDateTime": "2021-04-02T00:59:13", + "BolusType": "Automatic Correction", + "BolusRequestOptions": "Automatic Bolus/Correction", + "StandardPercent": "100.00", + "Duration": "0", + "CarbSize": "0", + "UserOverride": "0", + "TargetBG": "160", + "CorrectionFactor": "30.00", + "FoodBolusSize": "0.00", + "CorrectionBolusSize": "1.70", + "ActualTotalBolusRequested": "1.70", + "IsQuickBolus": "0", + "EventHistoryReportEventDesc": "0", + "EventHistoryReportDetails": "Correction Bolus", + "NoteID": "CF 1:30 - Carb Ratio 1:0 - Target BG 160", + "IndexID": "0", + "Note": "1183132" + } + def test_parse_bolus_entry_std_automatic(self): + self.assertEqual( + TConnectEntry.parse_bolus_entry(self.entryStdAutomatic), + { + "description": "Automatic Bolus/Correction", + "complete": "1", + "completion": "Completed", + "request_time": "2021-04-02 00:59:13-04:00", + "completion_time": "2021-04-02 01:00:47-04:00", + "insulin": "1.70", + "carbs": "0", + "user_override": "0", + "extended_bolus": "", + "bolex_completion_time": None, + "bolex_start_time": None + }) + if __name__ == '__main__': diff --git a/tests/sync/test_bolus.py b/tests/sync/test_bolus.py index edf6161..1cb108a 100644 --- a/tests/sync/test_bolus.py +++ b/tests/sync/test_bolus.py @@ -1,152 +1,34 @@ #!/usr/bin/env python3 import unittest + +from tconnectsync.sync.bolus import process_bolus_events from tconnectsync.parser.tconnect import TConnectEntry +from ..parser.test_tconnect import TestTConnectEntryBolus + class TestBolusSync(unittest.TestCase): - base = { - "readingData": [], - "iobData": [], - "basalData": [], - "bolusData": [] - } @staticmethod def get_example_csv_bolus_events(): - data = TestBolusSync.base.copy() - data["bolusData"] = [ - { - "Type": "Bolus", - "Description": "Standard/Correction", - "BG": "141", - "IOB": "", - "BolusRequestID": "7001.000", - "BolusCompletionID": "7001.000", - "CompletionDateTime": "2021-04-01T12:58:26", - "InsulinDelivered": "13.53", - "FoodDelivered": "12.50", - "CorrectionDelivered": "1.03", - "CompletionStatusID": "3", - "CompletionStatusDesc": "Completed", - "BolusIsComplete": "1", - "BolexCompletionID": "", - "BolexSize": "", - "BolexStartDateTime": "", - "BolexCompletionDateTime": "", - "BolexInsulinDelivered": "", - "BolexIOB": "", - "BolexCompletionStatusID": "", - "BolexCompletionStatusDesc": "", - "ExtendedBolusIsComplete": "", - "EventDateTime": "2021-04-01T12:53:36", - "RequestDateTime": "2021-04-01T12:53:36", - "BolusType": "Carb", - "BolusRequestOptions": "Standard/Correction", - "StandardPercent": "100.00", - "Duration": "0", - "CarbSize": "75", - "UserOverride": "0", - "TargetBG": "110", - "CorrectionFactor": "30.00", - "FoodBolusSize": "12.50", - "CorrectionBolusSize": "1.03", - "ActualTotalBolusRequested": "13.53", - "IsQuickBolus": "0", - "EventHistoryReportEventDesc": "0", - "EventHistoryReportDetails": "Correction & Food Bolus", - "NoteID": "CF 1:30 - Carb Ratio 1:6 - Target BG 110", - "IndexID": "0", - "Note": "1181649" - }, { - "Type": "Bolus", - "Description": "Standard", - "BG": "159", - "IOB": "2.13", - "BolusRequestID": "7007.000", - "BolusCompletionID": "7007.000", - "CompletionDateTime": "2021-04-01T23:23:17", - "InsulinDelivered": "1.25", - "FoodDelivered": "0.00", - "CorrectionDelivered": "0.00", - "CompletionStatusID": "3", - "CompletionStatusDesc": "Completed", - "BolusIsComplete": "1", - "BolexCompletionID": "", - "BolexSize": "", - "BolexStartDateTime": "", - "BolexCompletionDateTime": "", - "BolexInsulinDelivered": "", - "BolexIOB": "", - "BolexCompletionStatusID": "", - "BolexCompletionStatusDesc": "", - "ExtendedBolusIsComplete": "", - "EventDateTime": "2021-04-01T23:21:58", - "RequestDateTime": "2021-04-01T23:21:58", - "BolusType": "Carb", - "BolusRequestOptions": "Standard", - "StandardPercent": "100.00", - "Duration": "0", - "CarbSize": "0", - "UserOverride": "1", - "TargetBG": "110", - "CorrectionFactor": "30.00", - "FoodBolusSize": "0.00", - "CorrectionBolusSize": "0.00", - "ActualTotalBolusRequested": "1.25", - "IsQuickBolus": "0", - "EventHistoryReportEventDesc": "0", - "EventHistoryReportDetails": "Food Bolus", - "NoteID": "CF 1:30 - Carb Ratio 1:6 - Target BG 110 | Override: Pump calculated Bolus = 0.0 units", - "IndexID": "0", - "Note": "1182867" - }, { - "Type": "Bolus", - "Description": "Automatic Bolus/Correction", - "BG": "", - "IOB": "3.24", - "BolusRequestID": "7010.000", - "BolusCompletionID": "7010.000", - "CompletionDateTime": "2021-04-02T01:00:47", - "InsulinDelivered": "1.70", - "FoodDelivered": "0.00", - "CorrectionDelivered": "1.70", - "CompletionStatusID": "3", - "CompletionStatusDesc": "Completed", - "BolusIsComplete": "1", - "BolexCompletionID": "", - "BolexSize": "", - "BolexStartDateTime": "", - "BolexCompletionDateTime": "", - "BolexInsulinDelivered": "", - "BolexIOB": "", - "BolexCompletionStatusID": "", - "BolexCompletionStatusDesc": "", - "ExtendedBolusIsComplete": "", - "EventDateTime": "2021-04-02T00:59:13", - "RequestDateTime": "2021-04-02T00:59:13", - "BolusType": "Automatic Correction", - "BolusRequestOptions": "Automatic Bolus/Correction", - "StandardPercent": "100.00", - "Duration": "0", - "CarbSize": "0", - "UserOverride": "0", - "TargetBG": "160", - "CorrectionFactor": "30.00", - "FoodBolusSize": "0.00", - "CorrectionBolusSize": "1.70", - "ActualTotalBolusRequested": "1.70", - "IsQuickBolus": "0", - "EventHistoryReportEventDesc": "0", - "EventHistoryReportDetails": "Correction Bolus", - "NoteID": "CF 1:30 - Carb Ratio 1:0 - Target BG 160", - "IndexID": "0", - "Note": "1183132" - } + return [ + TestTConnectEntryBolus.entryStdCorrection, + TestTConnectEntryBolus.entryStd, + TestTConnectEntryBolus.entryStdAutomatic ] - return data + def test_process_bolus_events(self): + bolusData = TestBolusSync.get_example_csv_bolus_events() + + bolusEvents = process_bolus_events(bolusData) + self.assertEqual(len(bolusEvents), 3) + + self.assertListEqual(bolusEvents, [ + TConnectEntry.parse_bolus_entry(bolusData[0]), + TConnectEntry.parse_bolus_entry(bolusData[1]), + TConnectEntry.parse_bolus_entry(bolusData[2]) + ]) - # TODO if __name__ == '__main__': unittest.main() \ No newline at end of file diff --git a/tests/test_process.py b/tests/test_process.py index eae1260..78bbc11 100644 --- a/tests/test_process.py +++ b/tests/test_process.py @@ -167,7 +167,10 @@ class TestProcessTimeRange(unittest.TestCase): tconnect.controliq.therapy_timeline = self.stub_therapy_timeline def fake_therapy_timeline_csv(time_start, time_end): - return TestBolusSync.get_example_csv_bolus_events() + return { + **self.stub_therapy_timeline_csv(time_start, time_end), + "bolusData": TestBolusSync.get_example_csv_bolus_events(), + } tconnect.ws2.therapy_timeline_csv = fake_therapy_timeline_csv