@@ -127,11 +127,12 @@ def test_add_duplicate_itinerary(self):
127127
128128 self .assertFalse (same_name_result )
129129 self .assertFalse (duplicate_result )
130+ self .assertEqual (len (self .itineraries ), 1 )
130131
131132 def test_add_itinerary_with_invalid_dates (self ):
132133 """
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.
134+ Test adding itineraries with invalid date formats (start_date, end_date, & flight departure and arrival datetimes).
135+ Verify that the add_itinerary() AND validate_dates() functions handle invalid input as expected and returns False.
135136 """
136137 test_itinerary = {
137138 "name" : "trip" , "location" : "Japan" , "description" : "description" , "start_date" : "12-12-2026" , "end_date" : "28-01-2027" , "flights" : [{
@@ -186,7 +187,7 @@ def test_add_itinerary_with_invalid_dates(self):
186187 # Test end_date with American format ("MM-DD-YYYY") -> asserts False
187188 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" ])
188189
189- # Test invalid flight dates
190+ # Test invalid flight dates -> asserts False
190191 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" ])
191192
192193 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" ])
@@ -195,6 +196,113 @@ def test_add_itinerary_with_invalid_dates(self):
195196 self .assertFalse (invalid_end_date_result )
196197 self .assertFalse (invalid_departure_date_result )
197198 self .assertFalse (invalid_arrival_date_result )
199+ self .assertEqual (len (self .itineraries ), 0 )
200+
201+ def test_edit_itinerary (self ):
202+ """
203+ Test editing an itinerary's items (uses two itineraries).
204+ Verify that ALL types of items in a specific itinerary can be edited smoothly, which includes:
205+
206+ new_name (edits name of trip) - covers string types that can be accessed in the first level of the itinerary dictionary, i.e. name, location & description.
207+ new_start_date (edits trip start_date) - covers validation of a trip's start & end dates.
208+ new_departure_airport (in flights list) - validates that departure & arrival airport is changed, and for the correct flight.
209+ Note: the "flight name" value should ALSO change to reflect the new departure airport.
210+ new_departure_date (in 'flights') - validates that departure & arrival date is validated by the validate_dates() function, then changed for the correct flight.
211+ new_attraction_name (in 'attractions') - since each item in an attraction dictionary is a type of string and tested the same way, only one needs to be tested.
212+ """
213+ test_Japan_itinerary = {
214+ "name" : "trip" , "location" : "Japan" , "description" : "description" , "start_date" : "12-12-2026" , "end_date" : "28-01-2027" , "flights" : [{
215+ "flight name" : "Perth to Narita" ,
216+ "departure airport" : "Perth" ,
217+ "departure date" : "12-12-2026 08:00" ,
218+ "arrival airport" : "Narita" ,
219+ "arrival date" : "12-12-2026 16:00"
220+ },
221+ {
222+ "flight name" : "Narita to Perth" ,
223+ "departure airport" : "Narita" ,
224+ "departure date" : "27-01-2027 23:00" ,
225+ "arrival airport" : "Perth" ,
226+ "arrival date" : "28-01-2027 07:00"
227+ }
228+ ],
229+ "attractions" : [{
230+ "attraction name" : "Hike" ,
231+ "address" : "123 Hike Lane" ,
232+ "summary" : "A cool hike with good views" ,
233+ "tag(s)" : "outdoors"
234+ },
235+ {
236+ "attraction name" : "Dinner spot" ,
237+ "address" : "49 Sweet Cove" ,
238+ "summary" : "A lovely dinner spot" ,
239+ "tag(s)" : "dinner, romantic"
240+ }
241+ ]}
242+
243+ test_England_itinerary = {
244+ "name" : "England 2020" , "location" : "England" , "description" : "Trip to England in 2020" , "start_date" : "21-09-2020" , "end_date" : "04-10-2020" , "flights" : [{
245+ "flight name" : "Perth to London" ,
246+ "departure airport" : "Perth" ,
247+ "departure date" : "21-09-2020 05:00" ,
248+ "arrival airport" : "London" ,
249+ "arrival date" : "21-09-2020 21:00"
250+ },
251+ {
252+ "flight name" : "London to Perth" ,
253+ "departure airport" : "London" ,
254+ "departure date" : "04-10-2020 23:00" ,
255+ "arrival airport" : "Perth" ,
256+ "arrival date" : "05-10-2020 15:30"
257+ }
258+ ],
259+ "attractions" : [{
260+ "attraction name" : "London Eye" ,
261+ "address" : "Somewhere in city" ,
262+ "summary" : "A glorified ferris wheel that shows the city surrounds" ,
263+ "tag(s)" : "view, relaxing"
264+ },
265+ {
266+ "attraction name" : "Shakespeare's Globe" ,
267+ "address" : "12 address strees" ,
268+ "summary" : "A reconstructed theatre" ,
269+ "tag(s)" : "entertainment, history"
270+ }
271+ ]}
272+
273+ new_name = "Japan 2026-27"
274+ new_start_date = "27-12-2026"
275+ new_departure_airport = "Sydney"
276+ new_departure_date = "23-09-2020 13:30"
277+ new_attraction_name = "London Theatre"
278+ add_itinerary (self .itineraries , name = test_Japan_itinerary ["name" ], location = test_Japan_itinerary ["location" ], description = test_Japan_itinerary ["description" ], start_date = test_Japan_itinerary ["start_date" ], end_date = test_Japan_itinerary ["end_date" ], flights = test_Japan_itinerary ["flights" ], attractions = test_Japan_itinerary ["attractions" ])
279+ add_itinerary (self .itineraries , name = test_England_itinerary ["name" ], location = test_England_itinerary ["location" ], description = test_England_itinerary ["description" ], start_date = test_England_itinerary ["start_date" ], end_date = test_England_itinerary ["end_date" ], flights = test_England_itinerary ["flights" ], attractions = test_England_itinerary ["attractions" ])
280+
281+ edit_itinerary (self .itineraries , test_Japan_itinerary ["name" ], "name" , "N/A" , "N/A" , new_name )
282+ self .assertNotEqual (self .itineraries [0 ]["name" ], test_Japan_itinerary ["name" ])
283+ self .assertEqual (self .itineraries [0 ]["name" ], new_name )
284+
285+ edit_itinerary (self .itineraries , self .itineraries [0 ]["name" ], "start_date" , "N/A" , "N/A" , new_start_date )
286+ self .assertNotEqual (self .itineraries [0 ]["start_date" ], test_Japan_itinerary ["start_date" ])
287+ self .assertEqual (self .itineraries [0 ]["start_date" ], new_start_date )
288+
289+ old_departure_airport = test_England_itinerary ["flights" ][0 ]["departure airport" ]
290+ old_flight_name = test_England_itinerary ["flights" ][0 ]["flight name" ]
291+ edit_itinerary (self .itineraries , self .itineraries [1 ]["name" ], "departure airport" , test_England_itinerary ["flights" ][0 ]["flight name" ], "N/A" , new_departure_airport )
292+ self .assertNotEqual (self .itineraries [1 ]["flights" ][0 ]["departure airport" ], old_departure_airport )
293+ self .assertNotEqual (self .itineraries [1 ]["flights" ][0 ]["flight name" ], old_flight_name )
294+ self .assertEqual (self .itineraries [1 ]["flights" ][0 ]["departure airport" ], new_departure_airport )
295+
296+ old_departure_date = test_England_itinerary ["flights" ][0 ]["departure date" ]
297+ edit_itinerary (self .itineraries , self .itineraries [1 ]["name" ], "departure date" , test_England_itinerary ["flights" ][0 ]["flight name" ], "N/A" , new_departure_date )
298+ self .assertNotEqual (self .itineraries [1 ]["flights" ][0 ]["departure date" ], old_departure_date )
299+ self .assertEqual (self .itineraries [1 ]["flights" ][0 ]["departure date" ], new_departure_date )
300+
301+ old_attraction_name = test_England_itinerary ["attractions" ][1 ]["attraction name" ]
302+ edit_itinerary (self .itineraries , self .itineraries [1 ]["name" ], "attraction name" , "N/A" , test_England_itinerary ["attractions" ][1 ]["attraction name" ], new_attraction_name )
303+ self .assertNotEqual (self .itineraries [1 ]["attractions" ][1 ]["attraction name" ], old_attraction_name )
304+ self .assertEqual (self .itineraries [1 ]["attractions" ][1 ]["attraction name" ], new_attraction_name )
305+
198306
199307 def test_delete_itinerary (self ):
200308 """
0 commit comments