Skip to main content
Glama
test_calendar_service.py5.86 kB
""" 캘린더 서비스 테스트 """ import pytest from datetime import datetime from src.models import CalendarEventRequest, EventCategory, EventStatus from src.services import CalendarService from src.exceptions import EventNotFound, UnauthorizedAccess class TestCalendarService: """캘린더 서비스 테스트 클래스""" def setup_method(self): """각 테스트 메서드 실행 전 설정""" self.service = CalendarService() self.user_id = 1 def test_fetch_events(self): """이벤트 조회 테스트""" result = self.service.fetch_events(self.user_id) assert result.success is True assert len(result.data) == 2 # 샘플 데이터 2개 assert all(event.user_id == self.user_id for event in result.data) def test_create_event_success(self): """이벤트 생성 성공 테스트""" request = CalendarEventRequest( title="새 이벤트", start_time=datetime(2025, 8, 3, 15, 0), duration=90, category=EventCategory.STUDY, description="새로운 학습 이벤트", stamina_cost=25 ) result = self.service.create_event(request, self.user_id) assert result.success is True assert result.data.title == "새 이벤트" assert result.data.category == EventCategory.STUDY assert result.data.stamina_cost == 25 def test_create_event_time_conflict(self): """시간 충돌 시 이벤트 생성 실패 테스트""" # 기존 이벤트와 겹치는 시간 request = CalendarEventRequest( title="충돌 이벤트", start_time=datetime(2025, 8, 2, 10, 30), # 기존 이벤트와 겹침 duration=60, category=EventCategory.WORK ) result = self.service.create_event(request, self.user_id) assert result.success is False assert "이미 다른 일정이 있습니다" in result.error def test_update_event_success(self): """이벤트 수정 성공 테스트""" request = CalendarEventRequest( title="수정된 제목", start_time=datetime(2025, 8, 3, 16, 0), duration=120, category=EventCategory.REST, description="수정된 설명" ) result = self.service.update_event(1, request, self.user_id) assert result.success is True assert result.data.title == "수정된 제목" assert result.data.category == EventCategory.REST def test_update_nonexistent_event(self): """존재하지 않는 이벤트 수정 시 예외 발생 테스트""" request = CalendarEventRequest( title="존재하지 않는 이벤트", start_time=datetime(2025, 8, 3, 16, 0), duration=60, category=EventCategory.WORK ) with pytest.raises(EventNotFound): self.service.update_event(999, request, self.user_id) def test_delete_event_success(self): """이벤트 삭제 성공 테스트""" result = self.service.delete_event(1, self.user_id) assert result.success is True # 삭제 확인 with pytest.raises(EventNotFound): self.service.get_event_by_id(1, self.user_id) def test_delete_nonexistent_event(self): """존재하지 않는 이벤트 삭제 시 예외 발생 테스트""" with pytest.raises(EventNotFound): self.service.delete_event(999, self.user_id) def test_get_event_by_id_success(self): """ID로 이벤트 조회 성공 테스트""" result = self.service.get_event_by_id(1, self.user_id) assert result.success is True assert result.data.id == 1 assert result.data.title == "팀 미팅" def test_get_event_by_id_not_found(self): """존재하지 않는 ID로 이벤트 조회 시 예외 발생 테스트""" with pytest.raises(EventNotFound): self.service.get_event_by_id(999, self.user_id) def test_complete_event_success(self): """이벤트 완료 처리 성공 테스트""" result = self.service.complete_event(1, self.user_id, 75) assert result.success is True assert result.data.status == EventStatus.COMPLETED assert result.data.stamina_after_completion == 75 def test_unauthorized_access(self): """권한 없는 사용자의 접근 시 예외 발생 테스트""" unauthorized_user_id = 999 with pytest.raises(UnauthorizedAccess): self.service.get_event_by_id(1, unauthorized_user_id) with pytest.raises(UnauthorizedAccess): self.service.delete_event(1, unauthorized_user_id) def test_time_conflict_detection(self): """시간 충돌 감지 테스트""" # 겹치는 시간 has_conflict = self.service._has_time_conflict( datetime(2025, 8, 2, 10, 30), 60, self.user_id ) assert has_conflict is True # 겹치지 않는 시간 no_conflict = self.service._has_time_conflict( datetime(2025, 8, 2, 12, 0), 60, self.user_id ) assert no_conflict is False def test_to_response_conversion(self): """Entity를 Response로 변환 테스트""" result = self.service.get_event_by_id(1, self.user_id) response = self.service.to_response(result.data) assert response.id == result.data.id assert response.title == result.data.title assert response.category == result.data.category assert response.status == result.data.status

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/highthon-16/MCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server