11import http
22import urllib .parse
3+ from datetime import datetime
34
45import pytest
56from django .urls import reverse
@@ -22,18 +23,20 @@ def test_presentation_api(api_client: APIClient, create_presentation_set: Presen
2223def test_presentation_event_type_filter_api (api_client : APIClient ):
2324 # Given: 행사 2개에 각각 2 종류의 발표 유형이 있고, 각 발표 유형마다 1개의 발표가 있음.
2425 organization = Organization .objects .create (name = "Test Organization" )
25- event_1 : Event = Event .objects .create (organization = organization , name = "Test Event 1" )
26- event_2 : Event = Event .objects .create (organization = organization , name = "Test Event 2" )
26+ event_1 : Event = Event .objects .create (
27+ organization = organization , name = "Test Event 1" , event_start_at = datetime (2025 , 8 , 1 )
28+ )
29+ event_2 : Event = Event .objects .create (
30+ organization = organization , name = "Test Event 2" , event_start_at = datetime (2026 , 8 , 1 )
31+ )
2732
2833 event_1_prst_type_1 = PresentationType .objects .create (event = event_1 , name = "Type 1" )
2934 event_1_prst_type_2 = PresentationType .objects .create (event = event_1 , name = "Type 2" )
30- event_2_prst_type_1 = PresentationType .objects .create (event = event_2 , name = "Type 1" )
31- event_2_prst_type_2 = PresentationType .objects .create (event = event_2 , name = "Type 2" )
35+ PresentationType .objects .create (event = event_2 , name = "Type 1" )
36+ PresentationType .objects .create (event = event_2 , name = "Type 2" )
3237
3338 event_1_prst_type_1_prst = Presentation .objects .create (type = event_1_prst_type_1 , title = "Presentation 1" )
3439 event_1_prst_type_2_prst = Presentation .objects .create (type = event_1_prst_type_2 , title = "Presentation 2" )
35- event_2_prst_type_1_prst = Presentation .objects .create (type = event_2_prst_type_1 , title = "Presentation 3" )
36- Presentation .objects .create (type = event_2_prst_type_2 , title = "Presentation 4" )
3740
3841 # When: API 요청을 통해 행사 1의 발표 유형 1과 2에 해당하는 발표를 요청할 시
3942 qs = urllib .parse .urlencode (
@@ -51,16 +54,29 @@ def test_presentation_event_type_filter_api(api_client: APIClient):
5154 str (event_1_prst_type_2_prst .id ),
5255 }
5356
54- # When: API 요청을 통해 행사 유형은 지정하지 않고 유형 1에 해당하는 발표를 요청할 시
55- qs = urllib .parse .urlencode ({"types" : event_1_prst_type_1 .name })
56- response = api_client .get (f"{ reverse ('v1:presentation-list' )} ?{ qs } " )
5757
58- # Then: 행사 1의 발표 유형 1과 행사 2의 발표 유형 1에 해당하는 발표가 반환되어야 함.
59- assert response .status_code == http .HTTPStatus .OK
58+ @pytest .mark .django_db
59+ def test_presentation_defaults_to_latest_event (api_client : APIClient ):
60+ # Given: 2개의 행사가 있고, 각각 발표가 있음.
61+ organization = Organization .objects .create (name = "Test Organization" )
62+ old_event = Event .objects .create (
63+ organization = organization , name = "PyCon Korea 2025" , event_start_at = datetime (2025 , 8 , 1 )
64+ )
65+ new_event = Event .objects .create (
66+ organization = organization , name = "PyCon Korea 2026" , event_start_at = datetime (2026 , 8 , 1 )
67+ )
6068
69+ old_type = PresentationType .objects .create (event = old_event , name = "Talk" )
70+ new_type = PresentationType .objects .create (event = new_event , name = "Talk" )
71+
72+ Presentation .objects .create (type = old_type , title = "Old Presentation" )
73+ new_prst = Presentation .objects .create (type = new_type , title = "New Presentation" )
74+
75+ # When: event 파라미터 없이 요청
76+ response = api_client .get (reverse ("v1:presentation-list" ))
77+
78+ # Then: 최신 행사(2026)의 발표만 반환
79+ assert response .status_code == http .HTTPStatus .OK
6180 response_data = response .json ()
62- assert len (response_data ) == 2 , "Should return presentations for type 1 across all events"
63- assert {datum ["id" ] for datum in response_data } == {
64- str (event_1_prst_type_1_prst .id ),
65- str (event_2_prst_type_1_prst .id ),
66- }
81+ assert len (response_data ) == 1
82+ assert response_data [0 ]["id" ] == str (new_prst .id )
0 commit comments