diff --git a/app/main/views/dashboard.py b/app/main/views/dashboard.py index fea3e3ece..8e4101a9d 100644 --- a/app/main/views/dashboard.py +++ b/app/main/views/dashboard.py @@ -413,10 +413,14 @@ def get_dashboard_partials(service_id): def get_dashboard_totals(statistics): # This is set in dashboard.html on page load - timezone = request.cookies.get("timezone", "US/Eastern") - current_app.logger.debug(hilite(f"User's timezone is {timezone}")) - if current_user.preferred_timezone is not timezone: - current_user.update(preferred_timezone=timezone) + try: + timezone = request.cookies.get("timezone", "US/Eastern") + current_app.logger.debug(hilite(f"User's timezone is {timezone}")) + serialized_user = current_user.serialize() + if serialized_user["preferred_timezone"] is not timezone: + current_user.update(preferred_timezone=timezone) + except RuntimeError as e: + current_app.logger.warning("Can't get timezone, running tests?") for msg_type in statistics.values(): msg_type["failed_percentage"] = get_formatted_percentage( diff --git a/app/models/user.py b/app/models/user.py index 3c96fc42c..6991dc035 100644 --- a/app/models/user.py +++ b/app/models/user.py @@ -58,6 +58,7 @@ class User(JSONModel, UserMixin): super().__init__(_dict) self.permissions = _dict.get("permissions", {}) self._platform_admin = _dict["platform_admin"] + self.preferred_timezone = _dict.get("preferred_timezone", "America/New_York") @classmethod def from_id(cls, user_id): diff --git a/tests/app/main/views/test_conversation.py b/tests/app/main/views/test_conversation.py index 1139cd43f..15a5ec587 100644 --- a/tests/app/main/views/test_conversation.py +++ b/tests/app/main/views/test_conversation.py @@ -113,55 +113,55 @@ def test_view_conversation( [ ( "message-8", - "yesterday at 14:59 US/Eastern", + "yesterday at 14:59 America/New_York", ), ( "message-7", - "yesterday at 14:59 US/Eastern", + "yesterday at 14:59 America/New_York", ), ( "message-6", - "yesterday at 16:59 US/Eastern", + "yesterday at 16:59 America/New_York", ), ( "message-5", - "yesterday at 18:59 US/Eastern", + "yesterday at 18:59 America/New_York", ), ( "message-4", - "yesterday at 20:59 US/Eastern", + "yesterday at 20:59 America/New_York", ), ( "message-3", - "yesterday at 22:59 US/Eastern", + "yesterday at 22:59 America/New_York", ), ( "message-2", - "yesterday at 22:59 US/Eastern", + "yesterday at 22:59 America/New_York", ), ( "message-1", - "yesterday at 23:00 US/Eastern", + "yesterday at 23:00 America/New_York", ), ( expected_outbound_content, - "yesterday at 00:00 US/Eastern", + "yesterday at 00:00 America/New_York", ), ( expected_outbound_content, - "yesterday at 00:00 US/Eastern", + "yesterday at 00:00 America/New_York", ), ( expected_outbound_content, - "yesterday at 00:00 US/Eastern", + "yesterday at 00:00 America/New_York", ), ( expected_outbound_content, - "yesterday at 00:00 US/Eastern", + "yesterday at 00:00 America/New_York", ), ( expected_outbound_content, - "yesterday at 00:00 US/Eastern", + "yesterday at 00:00 America/New_York", ), ] ): diff --git a/tests/app/main/views/test_dashboard.py b/tests/app/main/views/test_dashboard.py index d5bab6323..8703adf3a 100644 --- a/tests/app/main/views/test_dashboard.py +++ b/tests/app/main/views/test_dashboard.py @@ -550,14 +550,14 @@ def test_download_inbox( ) assert response.get_data(as_text=True) == ( "Phone number,Message,Received\r\n" - "(202) 867-5300,message-1,07-01-2016 11:00 US/Eastern\r\n" - "(202) 867-5300,message-2,07-01-2016 10:59 US/Eastern\r\n" - "(202) 867-5300,message-3,07-01-2016 10:59 US/Eastern\r\n" - "(202) 867-5302,message-4,07-01-2016 08:59 US/Eastern\r\n" - "+33(0)1 12345678,message-5,07-01-2016 06:59 US/Eastern\r\n" - "(202) 555-0104,message-6,07-01-2016 04:59 US/Eastern\r\n" - "(202) 555-0104,message-7,07-01-2016 02:59 US/Eastern\r\n" - "+68212345,message-8,07-01-2016 02:59 US/Eastern\r\n" + "(202) 867-5300,message-1,07-01-2016 11:00 America/New_York\r\n" + "(202) 867-5300,message-2,07-01-2016 10:59 America/New_York\r\n" + "(202) 867-5300,message-3,07-01-2016 10:59 America/New_York\r\n" + "(202) 867-5302,message-4,07-01-2016 08:59 America/New_York\r\n" + "+33(0)1 12345678,message-5,07-01-2016 06:59 America/New_York\r\n" + "(202) 555-0104,message-6,07-01-2016 04:59 America/New_York\r\n" + "(202) 555-0104,message-7,07-01-2016 02:59 America/New_York\r\n" + "+68212345,message-8,07-01-2016 02:59 America/New_York\r\n" ) @@ -849,7 +849,7 @@ def test_should_show_upcoming_jobs_on_dashboard( assert normalize_spaces(page.select_one("main h2").text) == ("In the next few days") assert normalize_spaces(page.select_one("a.banner-dashboard").text) == ( - "2 files waiting to send " "- sending starts today at 06:09 US/Eastern" + "2 files waiting to send " "- sending starts today at 06:09 America/New_York" ) assert page.select_one("a.banner-dashboard")["href"] == url_for( diff --git a/tests/app/main/views/test_jobs.py b/tests/app/main/views/test_jobs.py index c4a756194..ab09f7ecd 100644 --- a/tests/app/main/views/test_jobs.py +++ b/tests/app/main/views/test_jobs.py @@ -349,7 +349,7 @@ def test_should_show_scheduled_job( ) assert normalize_spaces(page.select("main div p")[1].text) == ( - "Example template - service one was scheduled on January 02, 2016 at 12:00 AM US/Eastern by Test User" + "Example template - service one was scheduled on January 02, 2016 at 12:00 AM America/New_York by Test User" ) assert page.select("main p a")[0]["href"] == url_for( diff --git a/tests/app/main/views/test_templates.py b/tests/app/main/views/test_templates.py index b23caf925..6e2ff227d 100644 --- a/tests/app/main/views/test_templates.py +++ b/tests/app/main/views/test_templates.py @@ -497,7 +497,7 @@ def test_caseworker_sees_template_page_if_template_is_deleted( ) assert ( page.select("p.hint")[0].text.strip() - == "This template was deleted today at 15:00 US/Eastern." + == "This template was deleted today at 15:00 America/New_York." ) mock_get_deleted_template.assert_called_with(SERVICE_ONE_ID, template_id, None) @@ -1591,7 +1591,7 @@ def test_should_show_page_for_a_deleted_template( ) assert ( page.select("p.hint")[0].text.strip() - == "This template was deleted today at 15:00 US/Eastern." + == "This template was deleted today at 15:00 America/New_York." ) assert "Delete this template" not in page.select_one("main").text diff --git a/tests/app/main/views/uploads/test_upload_hub.py b/tests/app/main/views/uploads/test_upload_hub.py index ee24fba65..53ba1f161 100644 --- a/tests/app/main/views/uploads/test_upload_hub.py +++ b/tests/app/main/views/uploads/test_upload_hub.py @@ -52,7 +52,7 @@ def test_get_upload_hub_page( assert normalize_spaces(uploads[0].text.strip()) == ( "some.csv " - "Sent 1 January 2016 at 06:09 US/Eastern " + "Sent 1 January 2016 at 06:09 America/New_York " "0 pending 8 delivered 2 failed" ) assert uploads[0].select_one("a.file-list-filename-large")["href"] == ( @@ -82,12 +82,12 @@ def test_uploads_page_shows_scheduled_jobs( ("File Status"), ( "even_later.csv " - "Sending 1 January 2016 at 18:09 US/Eastern " + "Sending 1 January 2016 at 18:09 America/New_York " "1 text message waiting to send" ), ( "send_me_later.csv " - "Sending 1 January 2016 at 06:09 US/Eastern " + "Sending 1 January 2016 at 06:09 America/New_York " "1 text message waiting to send" ), ] diff --git a/tests/app/models/test_user.py b/tests/app/models/test_user.py index 1caf85f4a..099cab14d 100644 --- a/tests/app/models/test_user.py +++ b/tests/app/models/test_user.py @@ -18,6 +18,7 @@ def test_user(notify_admin): "email_address": "test@user.gsa.gov", "mobile_number": "+12021231234", "state": "pending", + "preferred_timezone": "America/Chicago", "failed_login_count": 0, "platform_admin": False, }