bmc_hub/tests/test_quick_time_calendar.py
Christian 4871dd2d9e Add comprehensive test coverage for various modules
- Introduced tests for mail templates including ranking, rendering, and attachment handling.
- Added tests for time billing selection and approval processes, ensuring proper validation and state management.
- Implemented tests for case types in JavaScript, focusing on loading and editing functionality.
- Created tests for contact mail AI integration, ensuring proper parsing and error handling.
- Developed tests for dark theme CSS contrast and loading order.
- Added tests for invoice fee service, covering various scenarios including exemptions and invalid inputs.
- Implemented vendor resource tests, ensuring proper file handling and query validation.
2026-10-08 08:58:02 +02:00

43 lines
2.1 KiB
Python

from datetime import datetime, timezone
from types import SimpleNamespace
from app.modules.calendar.backend import router as calendar
def test_quick_calendar_filters_and_preserves_interval(monkeypatch):
start = datetime(2026, 10, 7, 9, tzinfo=timezone.utc)
end = datetime(2026, 10, 7, 10, tzinfo=timezone.utc)
calls = []
def query(sql, params):
calls.append((sql, params))
return [dict(id=12, state='planned', description='Internt møde', user_name='CT',
user_id=3, customer_id=None, starts_at=start, ends_at=end)]
monkeypatch.setattr(calendar, 'execute_query', query)
events = calendar._get_calendar_events(SimpleNamespace(state=SimpleNamespace(user_id=3)),
start, end, True, None, 17, 'quick_planned')
assert len(calls) == 1
assert calls[0][1] == (['planned'], end, start, 3, 17)
assert 'q.user_id=%s' in calls[0][0] and 'q.customer_id=%s' in calls[0][0]
assert events[0]['end'] == end.isoformat()
assert events[0]['backgroundColor'] == '#336699'
assert events[0]['url'] == '/sag/new?quick_plan=12'
def test_registered_calendar_color_and_no_conversion_link(monkeypatch):
now = datetime(2026, 10, 7, 9)
monkeypatch.setattr(calendar, 'execute_query', lambda *_: [dict(id=2, state='registered',
description='Research', user_name='CT', user_id=3, starts_at=now, ends_at=now)])
events = calendar._get_calendar_events(SimpleNamespace(state=SimpleNamespace(user_id=3)),
now, now, True, None, None, 'quick_registered')
assert events[0]['backgroundColor'] == '#7c3aed'
assert events[0]['url'] == '/timetracking'
def test_existing_type_filter_does_not_query_quick_time(monkeypatch):
calls = []
monkeypatch.setattr(calendar, 'execute_query', lambda sql, params: calls.append(sql) or [])
now = datetime(2026, 10, 7)
calendar._get_calendar_events(SimpleNamespace(state=SimpleNamespace(user_id=3)),
now, now, True, None, None, 'deadline')
assert not any('quick_time_items' in sql for sql in calls)