@@ -128,13 +128,73 @@ def test_add_duplicate_itinerary(self):
128128 self .assertFalse (same_name_result )
129129 self .assertFalse (duplicate_result )
130130
131- def test_add_invalid_itinerary (self ):
131+ def test_add_itinerary_with_invalid_dates (self ):
132132 """
133- Test adding a task with an invalid due date format .
134- Verify that the function handles invalid input gracefully and returns False.
133+ Test adding a task with invalid date formats (start_date, end_date, & flight departure and arrival datetimes) .
134+ Verify that the function handles invalid input as expected and returns False.
135135 """
136- result = add_itinerary (self .itineraries , "Test Task" , "Description" , "2024-12-01" , "Pending" )
137- self .assertFalse (result )
136+ test_itinerary = {
137+ "name" : "trip" , "location" : "Japan" , "description" : "description" , "start_date" : "12-12-2026" , "end_date" : "28-01-2027" , "flights" : [{
138+ "flight name" : "Perth to Narita" ,
139+ "departure airport" : "Perth" ,
140+ "departure date" : "12-12-2026 08:00" ,
141+ "arrival airport" : "Narita" ,
142+ "arrival date" : "12-12-2026 16:00"
143+ },
144+ {
145+ "flight name" : "Narita to Perth" ,
146+ "departure airport" : "Narita" ,
147+ "departure date" : "27-01-2027 23:00" ,
148+ "arrival airport" : "Perth" ,
149+ "arrival date" : "28-01-2027 07:00"
150+ }
151+ ],
152+ "attractions" : [{
153+ "attraction name" : "Hike" ,
154+ "address" : "123 Hike Lane" ,
155+ "summary" : "A cool hike with good views" ,
156+ "tag(s)" : "outdoors"
157+ },
158+ {
159+ "attraction name" : "Dinner spot" ,
160+ "address" : "49 Sweet Cove" ,
161+ "summary" : "A lovely dinner spot" ,
162+ "tag(s)" : "dinner, romantic"
163+ }
164+ ]}
165+
166+ # Flight item to use for departure_date validation (expected to assertFalse)
167+ invalid_departure_date = [{
168+ "flight name" : "Perth to Narita" ,
169+ "departure airport" : "Perth" ,
170+ "departure date" : "08:00 12-12-2026" ,
171+ "arrival airport" : "Narita" ,
172+ "arrival date" : "12-12-2026 16:00"
173+ }]
174+
175+ invalid_arrival_date = [{
176+ "flight name" : "Perth to Narita" ,
177+ "departure airport" : "Perth" ,
178+ "departure date" : "12-12-2026 08:00" ,
179+ "arrival airport" : "Narita" ,
180+ "arrival date" : "2026-12-12 16:00"
181+ }]
182+
183+ # Test start_date with reversed format ("YYYY-MM-DD") -> asserts False
184+ invalid_start_date_result = add_itinerary (self .itineraries , name = test_itinerary ["name" ], location = test_itinerary ["location" ], description = test_itinerary ["description" ], start_date = "2026-12-12" , end_date = test_itinerary ["end_date" ], flights = test_itinerary ["flights" ], attractions = test_itinerary ["attractions" ])
185+
186+ # Test end_date with American format ("MM-DD-YYYY") -> asserts False
187+ invalid_end_date_result = add_itinerary (self .itineraries , name = test_itinerary ["name" ], location = test_itinerary ["location" ], description = test_itinerary ["description" ], start_date = test_itinerary ["start_date" ], end_date = "01-28-2027" , flights = test_itinerary ["flights" ], attractions = test_itinerary ["attractions" ])
188+
189+ # Test invalid flight dates
190+ invalid_departure_date_result = add_itinerary (self .itineraries , name = test_itinerary ["name" ], location = test_itinerary ["location" ], description = test_itinerary ["description" ], start_date = test_itinerary ["start_date" ], end_date = test_itinerary ["end_date" ], flights = invalid_departure_date , attractions = test_itinerary ["attractions" ])
191+
192+ invalid_arrival_date_result = add_itinerary (self .itineraries , name = test_itinerary ["name" ], location = test_itinerary ["location" ], description = test_itinerary ["description" ], start_date = test_itinerary ["start_date" ], end_date = test_itinerary ["end_date" ], flights = invalid_arrival_date , attractions = test_itinerary ["attractions" ])
193+
194+ self .assertFalse (invalid_start_date_result )
195+ self .assertFalse (invalid_end_date_result )
196+ self .assertFalse (invalid_departure_date_result )
197+ self .assertFalse (invalid_arrival_date_result )
138198
139199 def test_delete_itinerary (self ):
140200 """
0 commit comments