def test_get_location_tree(user: User): child_location2 = locations.create_location("Location", "This is an example location", None, user.id) parent_location = locations.create_location("Location", "This is an example location", None, user.id) location = locations.create_location("Location", "This is an example location", parent_location.id, user.id) child_location1 = locations.create_location("Location", "This is an example location", location.id, user.id) locations.update_location(child_location2.id, "Location", "This is an example location", location.id, user.id) locations_map, locations_tree = locations.get_locations_tree() child_location2 = locations.get_location(child_location2.id) assert locations_map == { parent_location.id: parent_location, location.id: location, child_location1.id: child_location1, child_location2.id: child_location2 } assert locations_tree == { parent_location.id: { location.id: { child_location1.id: {}, child_location2.id: {} } } }
def test_update_location_which_does_not_exist(user: User): location = locations.create_location("Location", "This is an example location", None, user.id) with pytest.raises(errors.LocationDoesNotExistError): locations.update_location(location.id + 1, "Location", "This is an example location", None, user.id)
def test_update_location(user: User): parent_location = locations.create_location("Parent Location", "This is an example location", None, user.id) location = locations.create_location("Location", "This is an example location", None, user.id) assert len(locations.get_locations()) == 2 locations.update_location(location.id, "Updated Location", "This is a location description", None, user.id) assert len(locations.get_locations()) == 2 location = locations.get_location(location.id) assert location.name == "Updated Location" assert location.description == "This is a location description" assert location.parent_location_id is None locations.update_location(location.id, "Updated Location", "This is a location description", parent_location.id, user.id) location = locations.get_location(location.id) assert location.parent_location_id == parent_location.id user_log_entries = user_log.get_user_log_entries(user.id) assert [ e for e in user_log_entries if e.data.get('location_id', -1) == location.id and e.type == UserLogEntryType.UPDATE_LOCATION ]
def test_update_location_self_parent(user: User): location = locations.create_location("Location", "This is an example location", None, user.id) with pytest.raises(errors.CyclicLocationError): locations.update_location(location.id, "Updated Location", "This is a location description", location.id, user.id)
def test_update_location_cyclic(user: User): parent_location = locations.create_location("Parent Location", "This is an example location", None, user.id) location = locations.create_location("Location", "This is an example location", parent_location.id, user.id) with pytest.raises(errors.CyclicLocationError): locations.update_location(parent_location.id, "Parent Location", "This is an example location", location.id, user.id)