mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-18 21:49:37 -04:00
Cleanup
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
import pytest
|
||||
from unittest.mock import patch
|
||||
|
||||
from app.main.views.notifications import (
|
||||
|
||||
@@ -239,7 +239,10 @@ def test_all_activity_filters(client_request, mocker, filter_type, expected_limi
|
||||
|
||||
if expected_limit_days:
|
||||
mock_get_page_of_jobs.assert_any_call(
|
||||
SERVICE_ONE_ID, page=current_page, limit_days=expected_limit_days, use_processing_time=True
|
||||
SERVICE_ONE_ID,
|
||||
page=current_page,
|
||||
limit_days=expected_limit_days,
|
||||
use_processing_time=True,
|
||||
)
|
||||
else:
|
||||
mock_get_page_of_jobs.assert_any_call(SERVICE_ONE_ID, page=current_page)
|
||||
|
||||
@@ -1,21 +1,33 @@
|
||||
from unittest.mock import patch
|
||||
|
||||
from app.utils.s3_csv import convert_s3_csv_timestamps
|
||||
|
||||
|
||||
def test_convert_s3_csv_timestamps_with_real_format():
|
||||
s3_csv_content = """Phone Number,Template,Sent By,Carrier,Status,Time,Batch File,Carrier Response
|
||||
14254147167,Example text message template,Backstop Test User,,Failed,2024-03-15 17:19:00,one-off-f0b91c0f.csv,Phone has blocked SMS
|
||||
14254147755,Example text message template,Admin User,,Delivered,2024-03-15 20:30:00,batch1.csv,Success"""
|
||||
s3_csv_content = (
|
||||
"Phone Number,Template,Sent By,Carrier,Status,Time,Batch File,Carrier Response\n"
|
||||
"14254147167,Example text message template,Backstop Test User,,Failed,"
|
||||
"2024-03-15 17:19:00,one-off-f0b91c0f.csv,Phone has blocked SMS\n"
|
||||
"14254147755,Example text message template,Admin User,,Delivered,"
|
||||
"2024-03-15 20:30:00,batch1.csv,Success"
|
||||
)
|
||||
|
||||
with patch(
|
||||
"app.utils.s3_csv.convert_report_date_to_preferred_timezone"
|
||||
) as mock_convert:
|
||||
|
||||
with patch('app.utils.s3_csv.convert_report_date_to_preferred_timezone') as mock_convert:
|
||||
def mock_conversion(timestamp):
|
||||
return f"{timestamp} US/Eastern"
|
||||
|
||||
mock_convert.side_effect = mock_conversion
|
||||
|
||||
result = list(convert_s3_csv_timestamps(s3_csv_content))
|
||||
full_result = ''.join(result)
|
||||
full_result = "".join(result)
|
||||
|
||||
assert "Phone Number,Template,Sent By,Carrier,Status,Time,Batch File,Carrier Response" in result[0]
|
||||
assert (
|
||||
"Phone Number,Template,Sent By,Carrier,Status,Time,Batch File,Carrier Response"
|
||||
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")
|
||||
@@ -36,9 +48,14 @@ def test_convert_s3_csv_handles_headers_only():
|
||||
|
||||
|
||||
def test_convert_s3_csv_handles_bytes():
|
||||
csv_bytes = b"Phone Number,Template,Sent by,Batch File,Carrier Response,Status,Time,Carrier\n+12025551234,Test,John,,Success,delivered,2024-01-15 20:30:00,Verizon"
|
||||
csv_bytes = (
|
||||
b"Phone Number,Template,Sent by,Batch File,Carrier Response,Status,Time,Carrier\n"
|
||||
b"+12025551234,Test,John,,Success,delivered,2024-01-15 20:30:00,Verizon"
|
||||
)
|
||||
|
||||
with patch('app.utils.s3_csv.convert_report_date_to_preferred_timezone') as mock_convert:
|
||||
with patch(
|
||||
"app.utils.s3_csv.convert_report_date_to_preferred_timezone"
|
||||
) as mock_convert:
|
||||
mock_convert.return_value = "2024-01-15 03:30:00 PM US/Eastern"
|
||||
|
||||
result = list(convert_s3_csv_timestamps(csv_bytes))
|
||||
@@ -51,11 +68,16 @@ def test_convert_s3_csv_handles_malformed_dates():
|
||||
+12025551234,Test,John,,Success,delivered,INVALID_DATE,Verizon
|
||||
+12025555678,Test,Jane,,Success,delivered,2024-01-15 21:45:00,AT&T"""
|
||||
|
||||
with patch('app.utils.s3_csv.convert_report_date_to_preferred_timezone') as mock_convert:
|
||||
mock_convert.side_effect = [Exception("Invalid date"), "2024-01-15 04:45:00 PM US/Eastern"]
|
||||
with patch(
|
||||
"app.utils.s3_csv.convert_report_date_to_preferred_timezone"
|
||||
) as mock_convert:
|
||||
mock_convert.side_effect = [
|
||||
Exception("Invalid date"),
|
||||
"2024-01-15 04:45:00 PM US/Eastern",
|
||||
]
|
||||
|
||||
result = list(convert_s3_csv_timestamps(csv_content))
|
||||
full_result = ''.join(result)
|
||||
full_result = "".join(result)
|
||||
|
||||
assert "INVALID_DATE" in full_result
|
||||
assert "2024-01-15 04:45:00 PM US/Eastern" in full_result
|
||||
@@ -66,11 +88,13 @@ def test_finds_time_column_dynamically():
|
||||
Test Template,+12025551234,2024-01-15 20:30:00,delivered
|
||||
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:
|
||||
with patch(
|
||||
"app.utils.s3_csv.convert_report_date_to_preferred_timezone"
|
||||
) as mock_convert:
|
||||
mock_convert.side_effect = lambda x: f"{x} Converted"
|
||||
|
||||
result = list(convert_s3_csv_timestamps(csv_content))
|
||||
full_result = ''.join(result)
|
||||
full_result = "".join(result)
|
||||
|
||||
assert mock_convert.call_count == 2
|
||||
assert "2024-01-15 20:30:00 Converted" in full_result
|
||||
@@ -80,7 +104,7 @@ Another Template,+12025555678,2024-01-15 21:45:00,delivered"""
|
||||
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:
|
||||
with patch("app.utils.csv.current_user") as mock_user:
|
||||
mock_user.preferred_timezone = "US/Eastern"
|
||||
|
||||
result = convert_report_date_to_preferred_timezone("2024-01-15 20:30:00")
|
||||
|
||||
Reference in New Issue
Block a user