Fixed disable button, formated time to include time zone (#2850)

This commit is contained in:
Alex Janousek
2025-08-21 10:05:41 -04:00
committed by GitHub
parent 54d14844fe
commit c6da0448fa
12 changed files with 161 additions and 52 deletions

View File

@@ -107,5 +107,9 @@ def test_s3_csv_gets_timezone_converted(
_test_page_title=False,
)
mock_convert.assert_called_once_with(b"csv,data")
# Now it passes the user_timezone parameter
assert mock_convert.call_count == 1
call_args = mock_convert.call_args
assert call_args[0][0] == b"csv,data"
assert "user_timezone" in call_args[1]
assert response.status_code == 200

View File

@@ -1500,7 +1500,10 @@ def test_new_folder_is_created_if_only_new_folder_is_filled_out(
assert mock_move_to_template_folder.called is False
mock_create_template_folder.assert_called_once_with(
SERVICE_ONE_ID, name="new folder", parent_id=None, created_by_id="6ce466d0-fd6a-11e5-82f5-e0accb9d11a6"
SERVICE_ONE_ID,
name="new folder",
parent_id=None,
created_by_id="6ce466d0-fd6a-11e5-82f5-e0accb9d11a6",
)
@@ -1538,7 +1541,10 @@ def test_should_be_able_to_move_to_new_folder(
)
mock_create_template_folder.assert_called_once_with(
SERVICE_ONE_ID, name="new folder", parent_id=None, created_by_id="6ce466d0-fd6a-11e5-82f5-e0accb9d11a6"
SERVICE_ONE_ID,
name="new folder",
parent_id=None,
created_by_id="6ce466d0-fd6a-11e5-82f5-e0accb9d11a6",
)
mock_move_to_template_folder.assert_called_once_with(
service_id=SERVICE_ONE_ID,

View File

@@ -90,14 +90,14 @@ def get_notifications_csv_mock(
None,
[
"Phone Number,Template,Sent by,Batch File,Carrier Response,Status,Time,Carrier\n",
"8005555555,foo,,,Did not like it,Delivered,1943-04-19 08:00:00,AT&T Mobility\r\n",
"8005555555,foo,,,Did not like it,Delivered,1943-04-19 08:00:00 AM US/Eastern,AT&T Mobility\r\n",
],
),
(
"Anne Example",
[
"Phone Number,Template,Sent by,Batch File,Carrier Response,Status,Time,Carrier\n",
"8005555555,foo,Anne Example,,Did not like it,Delivered,1943-04-19 08:00:00,AT&T Mobility\r\n", # noqa
"8005555555,foo,Anne Example,,Did not like it,Delivered,1943-04-19 08:00:00 AM US/Eastern,AT&T Mobility\r\n", # noqa
],
),
],
@@ -145,7 +145,7 @@ def test_generate_notifications_csv_without_job(
"bar.csv",
"Did not like it",
"Delivered",
"1943-04-19 08:00:00",
"1943-04-19 08:00:00 AM US/Eastern",
"AT&T Mobility",
],
),
@@ -174,7 +174,7 @@ def test_generate_notifications_csv_without_job(
"bar.csv",
"Did not like it",
"Delivered",
"1943-04-19 08:00:00",
"1943-04-19 08:00:00 AM US/Eastern",
"AT&T Mobility",
"🐜",
"🐝",
@@ -206,7 +206,7 @@ def test_generate_notifications_csv_without_job(
"bar.csv",
"Did not like it",
"Delivered",
"1943-04-19 08:00:00",
"1943-04-19 08:00:00 AM US/Eastern",
"AT&T Mobility",
"🐜,🐜",
"🐝,🐝",
@@ -383,6 +383,47 @@ def test_get_errors_for_csv(
def test_convert_report_date_to_preferred_timezone():
"""Test that timezone conversion includes AM/PM and timezone name."""
original = "2023-11-16 05:00:00"
altered = convert_report_date_to_preferred_timezone(original)
assert altered == "2023-11-16 00:00:00"
assert altered == "2023-11-16 12:00:00 AM US/Eastern"
original = "2023-11-16 17:30:00"
altered = convert_report_date_to_preferred_timezone(original)
assert altered == "2023-11-16 12:30:00 PM US/Eastern"
original = "2023-11-16 17:00:00"
altered = convert_report_date_to_preferred_timezone(original)
assert altered == "2023-11-16 12:00:00 PM US/Eastern"
original = "2023-11-16 05:00:00"
altered = convert_report_date_to_preferred_timezone(original)
assert altered == "2023-11-16 12:00:00 AM US/Eastern"
def test_convert_report_date_with_custom_timezone(mocker):
"""Test timezone conversion with a user who has a custom timezone."""
mocker.patch(
"app.utils.csv.get_user_preferred_timezone", return_value="America/Los_Angeles"
)
original = "2023-11-16 15:22:18"
altered = convert_report_date_to_preferred_timezone(original)
assert altered == "2023-11-16 07:22:18 AM America/Los_Angeles"
def test_convert_report_date_with_explicit_timezone():
"""Test timezone conversion with explicitly provided timezone."""
original = "2023-11-16 15:22:18"
altered = convert_report_date_to_preferred_timezone(
original, target_timezone="America/Los_Angeles"
)
assert altered == "2023-11-16 07:22:18 AM America/Los_Angeles"
altered = convert_report_date_to_preferred_timezone(
original, target_timezone="US/Eastern"
)
assert altered == "2023-11-16 10:22:18 AM US/Eastern"
altered = convert_report_date_to_preferred_timezone(original, target_timezone="UTC")
assert altered == "2023-11-16 03:22:18 PM UTC"

View File

@@ -16,7 +16,7 @@ def test_convert_s3_csv_timestamps_with_real_format():
"app.utils.s3_csv.convert_report_date_to_preferred_timezone"
) as mock_convert:
def mock_conversion(timestamp):
def mock_conversion(timestamp, target_timezone=None):
# Just return the timestamp as-is for testing
return timestamp
@@ -30,8 +30,12 @@ def test_convert_s3_csv_timestamps_with_real_format():
in result[0]
)
assert mock_convert.call_count == 2
mock_convert.assert_any_call("2024-03-15 17:19:00")
mock_convert.assert_any_call("2024-03-15 20:30:00")
mock_convert.assert_any_call(
"2024-03-15 17:19:00", target_timezone="US/Eastern"
)
mock_convert.assert_any_call(
"2024-03-15 20:30:00", target_timezone="US/Eastern"
)
assert "2024-03-15 17:19:00" in full_result
assert "2024-03-15 20:30:00" in full_result
@@ -92,7 +96,7 @@ Another Template,+12025555678,2024-01-15 21:45:00,delivered"""
with patch(
"app.utils.s3_csv.convert_report_date_to_preferred_timezone"
) as mock_convert:
mock_convert.side_effect = lambda x: f"{x} Converted"
mock_convert.side_effect = lambda x, target_timezone=None: f"{x} Converted"
result = list(convert_s3_csv_timestamps(csv_content))
full_result = "".join(result)
@@ -106,11 +110,11 @@ def test_actual_timezone_conversion():
from app.utils.csv import convert_report_date_to_preferred_timezone
with patch("app.utils.csv.current_user") as mock_user:
mock_user.is_authenticated = True
mock_user.preferred_timezone = "US/Eastern"
result = convert_report_date_to_preferred_timezone("2024-01-15 20:30:00")
# Should be in 24-hour format without AM/PM or timezone
assert "15:30:00" in result
assert "PM" not in result
assert "US/Eastern" not in result
# Should now be in 12-hour format with AM/PM and timezone
assert "03:30:00 PM" in result
assert "US/Eastern" in result