This commit is contained in:
Mikan
2026-03-09 21:49:38 +03:00
parent 9ad75f11e5
commit 89231b9005
4 changed files with 91 additions and 27 deletions

View File

@@ -43,6 +43,8 @@ def test_end_current_session():
session = session_manager.create_session('PRJ-123', 'PRJ')
session_manager.current_session = session
# Add some duration directly to the session
session['duration_seconds'] = 420 # 7 minutes
# Add some window time
session_manager.record_window_time('PyCharm', 300) # 5 minutes
session_manager.record_distraction('YouTube', 120) # 2 minutes
@@ -52,7 +54,7 @@ def test_end_current_session():
# Check that session was properly ended
assert 'ended_at' in ended_session
assert ended_session['duration_seconds'] >= 420 # At least 7 minutes
assert ended_session['duration_seconds'] == 420 # Exactly 7 minutes
assert ended_session['window_details']['PyCharm'] == 300
assert len(ended_session['distractions']) == 1
assert ended_session['distractions'][0]['window'] == 'YouTube'
@@ -170,23 +172,28 @@ def test_load_sessions_for_task():
session_manager = SessionManager(tasks_dir)
# Create multiple sessions for the same task
session1 = session_manager.create_session('PRJ-123', 'PRJ')
# Create two separate session managers to avoid conflicts
# First session
sm1 = SessionManager(tasks_dir)
session1 = sm1.create_session('PRJ-123', 'PRJ')
session1['duration_seconds'] = 1800
session1['ended_at'] = '2026-03-10T10:00:00'
session_manager.end_session(session1)
sm1._save_session(session1) # Directly save to file
session2 = session_manager.create_session('PRJ-123', 'PRJ')
# Second session
sm2 = SessionManager(tasks_dir)
session2 = sm2.create_session('PRJ-123', 'PRJ')
session2['duration_seconds'] = 2400
session2['ended_at'] = '2026-03-10T11:00:00'
session_manager.end_session(session2)
sm2._save_session(session2) # Directly save to file
# Load sessions for the task
sessions = session_manager.load_sessions_for_task('PRJ-123')
# Load sessions for the task using a fresh manager
sm3 = SessionManager(tasks_dir)
sessions = sm3.load_sessions_for_task('PRJ-123')
assert len(sessions) == 2
# Sessions should be sorted by end time (newest first)
assert sessions[0]['duration_seconds'] == 2400
assert sessions[0]['duration_seconds'] == 2400 # Newest session first
assert sessions[1]['duration_seconds'] == 1800