Skip to content

Commit 2ce14da

Browse files
Feat(unittest): unittests for adding duplicate itineraries finished, and passed after adding duplication checks in manage_itineraries.py
1 parent 0dc9377 commit 2ce14da

2 files changed

Lines changed: 20 additions & 10 deletions

File tree

Travel_Itinerary_Planner/src/manage_itineraries.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,16 @@ def add_itinerary(itinerary_list, name, location, description, start_date, end_d
4444
# print(new_itinerary)
4545
if itinerary_list:
4646
for itinerary in itinerary_list:
47-
if new_itinerary== itinerary:
47+
if new_itinerary == itinerary:
4848
print("This itinerary already exists!\nReturning to main menu...")
4949
return False
50+
elif new_itinerary["name"] == itinerary["name"]:
51+
print(f"'{new_itinerary["name"]}' already exists!\nReturning to main menu...")
52+
return False
5053
else:
5154
itinerary_list.append(new_itinerary)
55+
else:
56+
itinerary_list.append(new_itinerary)
5257
# Uncomment to print for itinerary_list validation:
5358
# print(itinerary_list)
5459

Travel_Itinerary_Planner/tests/test_manage_itineraries.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def test_add_itinerary(self):
4848
Test adding a new task to the task list.
4949
Verify that the task is successfully added and the list size increases.
5050
"""
51-
test_itinerary = [{
51+
test_itinerary = {
5252
"name": "trip", "location": "Japan", "description": "description", "start_date": "12-12-2026", "end_date": "28-01-2027", "flights": [{
5353
"flight name": "Perth to Narita",
5454
"departure airport": "Perth",
@@ -76,7 +76,7 @@ def test_add_itinerary(self):
7676
"summary": "A lovely dinner spot",
7777
"tag(s)": "dinner, romantic"
7878
}
79-
]}]
79+
]}
8080

8181
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=test_itinerary["flights"], attractions=test_itinerary["attractions"])
8282

@@ -86,10 +86,10 @@ def test_add_itinerary(self):
8686

8787
def test_add_duplicate_itinerary(self):
8888
"""
89-
Test adding a duplicate task with the same title.
90-
Verify that duplicates are not allowed and the function returns False.
89+
Test adding a duplicate itinerary with the same title but different values, then a complete copy of the itinerary.
90+
Verify that these itineraries are not allowed and the function returns False.
9191
"""
92-
test_itinerary = [{
92+
test_itinerary = {
9393
"name": "trip", "location": "Japan", "description": "description", "start_date": "12-12-2026", "end_date": "28-01-2027", "flights": [{
9494
"flight name": "Perth to Narita",
9595
"departure airport": "Perth",
@@ -117,11 +117,16 @@ def test_add_duplicate_itinerary(self):
117117
"summary": "A lovely dinner spot",
118118
"tag(s)": "dinner, romantic"
119119
}
120-
]}]
120+
]}
121121

122-
add_itinerary(self.itineraries, "Test Task", "Description", "01-12-2021", "Pending")
123-
result = add_itinerary(self.itineraries, "Test Task", "New Description", "02-12-2024", "Pending")
124-
self.assertFalse(result)
122+
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=test_itinerary["flights"], attractions=test_itinerary["attractions"])
123+
124+
same_name_result = add_itinerary(self.itineraries, name=test_itinerary["name"], location="Another location", description="Another description", start_date=test_itinerary["start_date"], end_date=test_itinerary["end_date"], flights=test_itinerary["flights"], attractions=test_itinerary["attractions"])
125+
126+
duplicate_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=test_itinerary["flights"], attractions=test_itinerary["attractions"])
127+
128+
self.assertFalse(same_name_result)
129+
self.assertFalse(duplicate_result)
125130

126131
def test_add_invalid_itinerary(self):
127132
"""

0 commit comments

Comments
 (0)