Test: Verify export functionality respects zero-hour filtering
All checks were successful
Build Tamigo CLI / Build Linux Binary (pull_request) Successful in 54s
Build Tamigo CLI / Build Windows Binary (pull_request) Successful in 43s
Build Tamigo CLI / Build Linux Binary (push) Successful in 54s
Build Tamigo CLI / Build Windows Binary (push) Successful in 44s
All checks were successful
Build Tamigo CLI / Build Linux Binary (pull_request) Successful in 54s
Build Tamigo CLI / Build Windows Binary (pull_request) Successful in 43s
Build Tamigo CLI / Build Linux Binary (push) Successful in 54s
Build Tamigo CLI / Build Windows Binary (push) Successful in 44s
This commit was merged in pull request #2.
This commit is contained in:
@@ -68,6 +68,49 @@ class TestTamigoExport(unittest.TestCase):
|
|||||||
self.assertIn("2025-03-10", work_days)
|
self.assertIn("2025-03-10", work_days)
|
||||||
self.assertEqual(work_days["2025-03-10"]["hours"], 0)
|
self.assertEqual(work_days["2025-03-10"]["hours"], 0)
|
||||||
|
|
||||||
|
@patch('tamigo.select_date_range')
|
||||||
|
@patch('questionary.select')
|
||||||
|
@patch('questionary.text')
|
||||||
|
@patch('tamigo.console')
|
||||||
|
def test_export_worked_hours_respects_zero_hour_filtering(self, mock_console, mock_text, mock_select, mock_date_range):
|
||||||
|
from tamigo import export_worked_hours
|
||||||
|
|
||||||
|
# Mock API response with a 0-hour shift
|
||||||
|
mock_shifts = [
|
||||||
|
{
|
||||||
|
"Date": "/Date(1741564800000)/", # 2025-03-10
|
||||||
|
"StartTime": "2025-03-10T09:00:00Z",
|
||||||
|
"ActualShiftHours": 0,
|
||||||
|
"ActualShiftText": "Sick Day",
|
||||||
|
"IsAbsent": False
|
||||||
|
}
|
||||||
|
]
|
||||||
|
self.client.get_employee_actual_shifts.return_value = mock_shifts
|
||||||
|
mock_date_range.return_value = (datetime(2025, 3, 1), datetime(2025, 3, 15))
|
||||||
|
|
||||||
|
# 1. Test with show_zero_hours = False -> Should NOT export anything
|
||||||
|
with patch('tamigo.current_config', {'show_zero_hours': False}):
|
||||||
|
export_worked_hours(self.client)
|
||||||
|
# Verify the warning was printed
|
||||||
|
mock_console.print.assert_any_call("[warning]WARNING: NO LOG ENTRIES DETECTED.[/warning]")
|
||||||
|
self.assertFalse(os.path.exists("tamigo_export_20250301_20250315.csv"))
|
||||||
|
|
||||||
|
# 2. Test with show_zero_hours = True -> Should export the 0-hour day
|
||||||
|
mock_select.return_value.ask.return_value = "CSV"
|
||||||
|
mock_text.return_value.ask.return_value = "test_zero_export.csv"
|
||||||
|
|
||||||
|
with patch('tamigo.current_config', {'show_zero_hours': True}):
|
||||||
|
export_worked_hours(self.client)
|
||||||
|
|
||||||
|
self.assertTrue(os.path.exists("test_zero_export.csv"))
|
||||||
|
with open("test_zero_export.csv", "r") as f:
|
||||||
|
rows = list(csv.reader(f))
|
||||||
|
self.assertEqual(len(rows), 2) # Header + 1 data row
|
||||||
|
self.assertEqual(rows[1][0], "2025-03-10")
|
||||||
|
self.assertEqual(rows[1][1], "0.00")
|
||||||
|
|
||||||
|
os.remove("test_zero_export.csv")
|
||||||
|
|
||||||
@patch('tamigo.select_date_range')
|
@patch('tamigo.select_date_range')
|
||||||
@patch('tamigo.get_worked_days')
|
@patch('tamigo.get_worked_days')
|
||||||
@patch('questionary.select')
|
@patch('questionary.select')
|
||||||
|
|||||||
Reference in New Issue
Block a user