Esempio n. 1
0
    def test_new_ciq_iob_data(self):
        tconnect = TConnectApi()

        # datetimes are unused by the API fake
        start = datetime.datetime(2021, 4, 20, 12, 0)
        end = datetime.datetime(2021, 4, 21, 12, 0)

        tconnect.controliq.therapy_timeline = self.stub_therapy_timeline

        iobData = TestIOBSync.get_example_csv_iob_events()
        def fake_therapy_timeline_csv(time_start, time_end):
            return {
                **self.stub_therapy_timeline_csv(time_start, time_end),
                "iobData": iobData,
            }

        tconnect.ws2.therapy_timeline_csv = fake_therapy_timeline_csv

        nightscout = NightscoutApi()

        nightscout.last_uploaded_entry = self.stub_last_uploaded_entry
        nightscout.last_uploaded_activity = self.stub_last_uploaded_activity

        process_time_range(tconnect, nightscout, start, end, pretend=False, features=[BOLUS, BASAL, IOB])

        pprint.pprint(nightscout.uploaded_entries)
        self.assertEqual(len(nightscout.uploaded_entries["activity"]), 1)
        self.assertDictEqual(dict(nightscout.uploaded_entries), {
            "activity": [
                # the most recent IOB entry is added
                NightscoutEntry.iob(6.80, "2021-10-12 00:10:30-04:00")
        ]})
        self.assertDictEqual(nightscout.put_entries, {})
        self.assertListEqual(nightscout.deleted_entries, [])
Esempio n. 2
0
 def test_iob(self):
     self.assertEqual(
         NightscoutEntry.iob(iob=2.05,
                             created_at="2021-03-16 00:25:21-04:00"), {
                                 "activityType": "tconnect_iob",
                                 "iob": 2.05,
                                 "created_at": "2021-03-16 00:25:21-04:00",
                                 "enteredBy": "Pump (tconnectsync)"
                             })
Esempio n. 3
0
    def test_updates_ciq_iob_data(self):
        tconnect = TConnectApi()

        # datetimes are unused by the API fake
        start = datetime.datetime(2021, 4, 20, 12, 0)
        end = datetime.datetime(2021, 4, 21, 12, 0)

        tconnect.controliq.therapy_timeline = self.stub_therapy_timeline

        iobData = TestIOBSync.get_example_csv_iob_events()
        iobData[0]["created_at"] = start
        iobData[0]["_id"] = "sentinel_existing_iob_id"

        def fake_therapy_timeline_csv(time_start, time_end):
            return {
                **self.stub_therapy_timeline_csv(time_start, time_end),
                "iobData": iobData,
            }

        tconnect.ws2.therapy_timeline_csv = fake_therapy_timeline_csv

        nightscout = NightscoutApi()

        nightscout.last_uploaded_entry = self.stub_last_uploaded_entry

        def fake_last_uploaded_activity(activityType):
            if activityType == IOB_ACTIVITYTYPE:
                return iobData[0]
            return self.stub_last_uploaded_activity(activityType)

        nightscout.last_uploaded_activity = fake_last_uploaded_activity

        process_time_range(tconnect, nightscout, start, end, pretend=False, features=[IOB])

        pprint.pprint(nightscout.uploaded_entries)
        self.assertEqual(len(nightscout.uploaded_entries["activity"]), 1)
        self.assertDictEqual(dict(nightscout.uploaded_entries), {
            "activity": [
                # the most recent IOB entry is added
                NightscoutEntry.iob(6.80, "2021-10-12 00:10:30-04:00")
        ]})
        self.assertDictEqual(nightscout.put_entries, {})
        self.assertListEqual(nightscout.deleted_entries, [
            "activity/sentinel_existing_iob_id"
        ])