Modify tests and Delete city test

This commit is contained in:
Ruben Sanchez 2023-12-09 19:31:07 -05:00
parent a24f9fe7b7
commit 7f1ba28184

View File

@ -176,7 +176,7 @@ TestDBFactory
""" """
@unittest.skipIf(control.skip_test, control.skip_reason) @unittest.skipIf(control.skip_test, control.skip_reason)
def test_save_city(self): def test_create_city(self):
control.city.name = "Montreal" control.city.name = "Montreal"
city_id = control.database.persist_city( city_id = control.database.persist_city(
control.city, control.city,
@ -184,23 +184,38 @@ TestDBFactory
control.city.name, control.city.name,
control.application_id, control.application_id,
control.user_id) control.user_id)
# Check the city was updated
cities = control.database.cities_by_user_and_application(
control.user_id,
control.application_id)
for updated_city in cities:
if updated_city.id == city_id:
self.assertEqual(updated_city.name, control.city.name)
break
# Tear down after test
control.database.delete_city(city_id) control.database.delete_city(city_id)
@unittest.skipIf(control.skip_test, control.skip_reason) @unittest.skipIf(control.skip_test, control.skip_reason)
def test_get_update_city(self): def test_update_city(self):
# Create and update city name # Create and update city name
city_id = control.database.persist_city(control.city, city_id = control.database.persist_city(control.city,
control.pickle_path, control.pickle_path,
control.city.name, control.city.name,
control.application_id, control.application_id,
control.user_id) control.user_id)
# Update city
control.city.name = "Ottawa" control.city.name = "Ottawa"
control.city.pickle_path = "new_pickle_path"
control.database.update_city(city_id, control.city) control.database.update_city(city_id, control.city)
# Check the city was updated # Check the city was updated
cities = control.database.cities_by_user_and_application( cities = control.database.cities_by_user_and_application(
control.user_id, control.user_id,
control.application_id) # TODO: woudln't this be better wih a search by city id? control.application_id)
for updated_city in cities: for updated_city in cities:
if updated_city.id == city_id: if updated_city.id == city_id:
@ -210,6 +225,32 @@ TestDBFactory
# Delete extra city created # Delete extra city created
control.database.delete_city(city_id) control.database.delete_city(city_id)
@unittest.skipIf(control.skip_test, control.skip_reason)
def test_get_deleted_city(self):
control.city.name = "Montreal"
city_id = control.database.persist_city(
control.city,
control.pickle_path,
control.city.name,
control.application_id,
control.user_id)
control.database.delete_city(city_id)
# Check the city was deleted properly
cities = control.database.cities_by_user_and_application(
control.user_id,
control.application_id)
city_id_found = False
for updated_city in cities:
if updated_city.id == city_id:
city_id_found = True
break
self.assertTrue(not city_id_found, "The city_id was not deleted successfully")
@unittest.skipIf(control.skip_test, control.skip_reason) @unittest.skipIf(control.skip_test, control.skip_reason)
@unittest.skipIf(control.skip_insel_test, 'insel is not installed') @unittest.skipIf(control.skip_insel_test, 'insel is not installed')
def test_save_results(self): def test_save_results(self):