def test_db_site_get_empty(self): site_db = SiteDB() # get all items result = site_db.get_all() assert list(result) == [] # try to get an inexistant item with pytest.raises(ItemNotFoundError): site_db.get_by_id('not_existing')
def test_db_site_get_update_delete(self, init_sites): site_ids = init_sites site_db = SiteDB() # get all items result = site_db.get_all() sites = list(result) assert len(sites) == 2 for cur_site in sites: assert cur_site.id in site_ids # get an item by its ID site = site_db.get_by_id(sites[0].id) # update item data new_description = 'updated by patator' new_altitude = 42 site.description = new_description site.geographic_info.altitude = new_altitude site_db.update(site.id, site) # check that item has really been updated in database updated_site = site_db.get_by_id(site.id) assert updated_site.id == site.id assert updated_site.name == site.name assert updated_site.description == new_description assert (updated_site.geographic_info.latitude == site.geographic_info.latitude) assert (updated_site.geographic_info.longitude == site.geographic_info.longitude) assert updated_site.geographic_info.altitude == new_altitude # delete an item by its ID site_db.remove(site.id) # get an item by its ID with pytest.raises(ItemNotFoundError): # it has been removed... site_db.get_by_id(site.id)