Files
TimeTracker/tests/test_time_entry_freeze.py
Dries Peeters 90dde470da style: standardize code formatting and normalize line endings
- Normalize line endings from CRLF to LF across all files to match .editorconfig
- Standardize quote style from single quotes to double quotes
- Normalize whitespace and formatting throughout codebase
- Apply consistent code style across 372 files including:
  * Application code (models, routes, services, utils)
  * Test files
  * Configuration files
  * CI/CD workflows

This ensures consistency with the project's .editorconfig settings and
improves code maintainability.
2025-11-28 20:05:37 +01:00

43 lines
1.4 KiB
Python

"""Tests demonstrating time-control with freezegun and model time calculations."""
import datetime as dt
import pytest
from app import db
from app.models import TimeEntry
from factories import UserFactory, ProjectFactory
@pytest.mark.unit
def test_active_timer_duration_without_real_time(app, time_freezer):
"""Create a running timer at T0 and stop it at T0+90 minutes using time freezer."""
freezer = time_freezer("2024-01-01 09:00:00")
with app.app_context():
user = UserFactory()
project = ProjectFactory()
entry = TimeEntry(
user_id=user.id,
project_id=project.id,
start_time=dt.datetime(2024, 1, 1, 9, 0, 0),
notes="Work session",
source="auto",
billable=True,
)
db.session.add(entry)
db.session.commit()
# Advance frozen time and compute duration deterministically without tz side-effects
freezer.stop()
freezer = time_freezer("2024-01-01 10:30:00")
entry = db.session.get(TimeEntry, entry.id)
entry.end_time = entry.start_time + dt.timedelta(minutes=90)
entry.calculate_duration()
db.session.commit()
# Duration should be exactly 90 minutes = 5400 seconds (ROUNDING_MINUTES=1 in TestingConfig)
db.session.refresh(entry)
assert entry.duration_seconds == 5400
assert entry.end_time.hour == 10
assert entry.end_time.minute == 30