Skip to content

Commit 6bf5cf0

Browse files
authored
Merge pull request #35 from PPeitsch/feature/increase-coverage-time-log
Feat: Increase test coverage for time_log.py to 100%
2 parents 1cb6ece + 2765eaa commit 6bf5cf0

2 files changed

Lines changed: 46 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

88

9+
## [1.2.3] - 2025-08-22
10+
11+
### Added
12+
- Increased test coverage for the `time_log.py` module from 88% to 100%.
13+
14+
915
## [1.2.2] - 2025-08-22
1016

1117
### Added
@@ -141,6 +147,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
141147
- Flexible database configuration (SQLite/PostgreSQL).
142148

143149

150+
151+
[1.2.3]: https://github.com/PPeitsch/TimeTrack/compare/v1.2.2...v1.2.3
144152
[1.2.2]: https://github.com/PPeitsch/TimeTrack/compare/v1.2.1...v1.2.2
145153
[1.2.1]: https://github.com/PPeitsch/TimeTrack/compare/v1.2.0...v1.2.1
146154
[1.2.0]: https://github.com/PPeitsch/TimeTrack/compare/v1.1.1...v1.2.0

tests/test_routes.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,44 @@ def test_monthly_logs_route(self):
339339
self.assertIn("entries", entry)
340340
self.assertIn("total_hours", entry)
341341

342+
def test_monthly_logs_with_absence(self):
343+
# Create an absence entry
344+
with self.app.app_context():
345+
entry_date = date(2025, 4, 15)
346+
absence_entry = ScheduleEntry(
347+
employee_id=1, date=entry_date, entries=[], absence_code="VAC"
348+
)
349+
db.session.add(absence_entry)
350+
db.session.commit()
351+
352+
# Test getting monthly logs for the month with the absence
353+
response = self.client.get("/logs/monthly/2025/4")
354+
self.assertEqual(response.status_code, 200)
355+
data = json.loads(response.data)
356+
357+
# Find the absence entry in the response
358+
absence_found = False
359+
for entry in data:
360+
if entry["date"] == "2025-04-15":
361+
self.assertEqual(entry["type"], "VAC")
362+
self.assertEqual(entry["total_hours"], 0)
363+
absence_found = True
364+
break
365+
self.assertTrue(absence_found, "Absence entry not found in response")
366+
367+
def test_monthly_logs_exception(self):
368+
with self.app.app_context():
369+
with patch("app.routes.time_log.ScheduleEntry.query") as mock_query:
370+
# Configure the mock to raise an exception when used
371+
mock_query.filter.side_effect = Exception("Database connection failed")
372+
373+
# Test that the exception is handled and a 500 error is returned
374+
response = self.client.get("/logs/monthly/2025/5")
375+
self.assertEqual(response.status_code, 500)
376+
data = json.loads(response.data)
377+
self.assertIn("error", data)
378+
self.assertEqual(data["error"], "Database connection failed")
379+
342380

343381
if __name__ == "__main__":
344382
unittest.main()

0 commit comments

Comments
 (0)