59 lines
1.4 KiB
Python
59 lines
1.4 KiB
Python
import uuid
|
|
|
|
import pytest
|
|
|
|
from app.ics_service import parse_ics_to_busy_blocks
|
|
|
|
SAMPLE_ICS = """BEGIN:VCALENDAR
|
|
VERSION:2.0
|
|
PRODID:-//Test//Test//EN
|
|
BEGIN:VEVENT
|
|
DTSTART:20260106T150000Z
|
|
DTEND:20260106T160000Z
|
|
SUMMARY:Meeting
|
|
UID:test-1
|
|
DTSTAMP:20260101T000000Z
|
|
END:VEVENT
|
|
BEGIN:VEVENT
|
|
DTSTART:20260107T140000Z
|
|
DTEND:20260107T153000Z
|
|
SUMMARY:Another Meeting
|
|
UID:test-2
|
|
DTSTAMP:20260101T000000Z
|
|
END:VEVENT
|
|
END:VCALENDAR"""
|
|
|
|
|
|
def test_parse_ics_extracts_busy_blocks():
|
|
participant_id = str(uuid.uuid4())
|
|
blocks = parse_ics_to_busy_blocks(SAMPLE_ICS, participant_id)
|
|
|
|
assert len(blocks) == 2
|
|
assert all(str(b.participant_id) == participant_id for b in blocks)
|
|
|
|
|
|
def test_parse_ics_extracts_correct_times():
|
|
participant_id = str(uuid.uuid4())
|
|
blocks = parse_ics_to_busy_blocks(SAMPLE_ICS, participant_id)
|
|
|
|
sorted_blocks = sorted(blocks, key=lambda b: b.start_time)
|
|
|
|
assert sorted_blocks[0].start_time.hour == 15
|
|
assert sorted_blocks[0].end_time.hour == 16
|
|
|
|
assert sorted_blocks[1].start_time.hour == 14
|
|
assert sorted_blocks[1].end_time.hour == 15
|
|
assert sorted_blocks[1].end_time.minute == 30
|
|
|
|
|
|
def test_parse_empty_ics():
|
|
empty_ics = """BEGIN:VCALENDAR
|
|
VERSION:2.0
|
|
PRODID:-//Test//Test//EN
|
|
END:VCALENDAR"""
|
|
|
|
participant_id = str(uuid.uuid4())
|
|
blocks = parse_ics_to_busy_blocks(empty_ics, participant_id)
|
|
|
|
assert len(blocks) == 0
|