Skip to content

Commit

Permalink
Issue jwoglom#56 Put a common replace_with_user_tz() function that de…
Browse files Browse the repository at this point in the history
…faults to using the TIMEZONE_NAME tz in the users .env file, defaults to 'America/New_York' if no .env file. Updated the applicable date strings with -04:00 in test_therapy_event.py and it seems to work for me, test come back ok
  • Loading branch information
jyaw committed Aug 29, 2022
1 parent ec84afd commit 37e3b3f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
25 changes: 13 additions & 12 deletions tests/domain/test_therapy_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from tconnectsync.domain.bolus import Bolus

from tconnectsync.domain.therapy_event import BolusTherapyEvent, CGMTherapyEvent
from ..util.utilities import replace_with_user_tz

class TestCGMTherapyEvent(unittest.TestCase):
maxDiff = None
Expand Down Expand Up @@ -103,8 +104,8 @@ def test_standard_to_bolus(self):
description="Standard",
complete="1",
completion="Completed",
request_time="2022-07-21 12:27:36-04:00",
completion_time="2022-07-21 12:29:21-04:00",
request_time=replace_with_user_tz("2022-07-21 12:27:36-04:00"),
completion_time=replace_with_user_tz("2022-07-21 12:29:21-04:00"),
insulin="4.17",
requested_insulin="4.17",
carbs="25",
Expand Down Expand Up @@ -176,8 +177,8 @@ def test_correction_to_bolus(self):
description="Automatic Bolus/Correction",
complete="1",
completion="Completed",
request_time="2022-07-21 11:53:08-04:00",
completion_time="2022-07-21 11:55:24-04:00",
request_time=replace_with_user_tz("2022-07-21 11:53:08-04:00"),
completion_time=replace_with_user_tz("2022-07-21 11:55:24-04:00"),
insulin="2.9",
requested_insulin="2.9",
carbs="0",
Expand Down Expand Up @@ -259,16 +260,16 @@ def test_extended_bolus_incomplete_to_bolus(self):
description="Extended 50.00%/0.00",
complete="0",
completion="",
request_time="2022-08-09 23:19:15-04:00",
completion_time="2022-08-09 23:20:04-04:00",
request_time=replace_with_user_tz("2022-08-09 23:19:15-04:00"),
completion_time=replace_with_user_tz("2022-08-09 23:20:04-04:00"),
insulin="0.2",
requested_insulin="0.2",
carbs="0",
bg="131",
user_override="1",
extended_bolus="1",
bolex_completion_time="",
bolex_start_time="2022-08-09 23:20:04-04:00"
bolex_start_time=replace_with_user_tz("2022-08-09 23:20:04-04:00")
)))

extendedBolusJson = {
Expand Down Expand Up @@ -347,21 +348,21 @@ def test_extended_bolus_complete_to_bolus(self):
description="Extended 50.00%/0.00",
complete="1",
completion="Completed",
request_time="2022-08-09 23:19:15-04:00",
completion_time="2022-08-09 23:20:04-04:00",
request_time=replace_with_user_tz("2022-08-09 23:19:15-04:00"),
completion_time=replace_with_user_tz("2022-08-09 23:20:04-04:00"),
insulin="0.2",
requested_insulin="0.2",
carbs="0",
bg="131",
user_override="1",
extended_bolus="1",
bolex_completion_time="2022-08-09 23:35:03-04:00",
bolex_start_time="2022-08-09 23:20:04-04:00"
bolex_completion_time=replace_with_user_tz("2022-08-09 23:35:03-04:00"),
bolex_start_time=replace_with_user_tz("2022-08-09 23:20:04-04:00")
)))


BOLUS_FULL_EXAMPLES = [
TestBolusTherapyEvent.standardJson,
TestBolusTherapyEvent.correctionJson,
TestBolusTherapyEvent.extendedBolusJson
]
]
Empty file added tests/util/__init__.py
Empty file.
10 changes: 10 additions & 0 deletions tests/util/utilities.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import arrow
from tconnectsync.secret import TIMEZONE_NAME

"""
Replaces timezone in string with provided timezone string, defaults to 'America/New_York'
Example 1: replace_datetime_tz("2021-04-01 23:15:30-04:00")
Example 2: replace_datetime_tz("2021-04-01 23:15:30-04:00", 'America/Chicago')
"""
def replace_with_user_tz(date, tz=TIMEZONE_NAME):
return arrow.get(date, tzinfo=tz).format()

0 comments on commit 37e3b3f

Please sign in to comment.