def test_assign_location(user: User, object: Object): object_location_assignment = locations.get_current_object_location_assignment( object.id) assert object_location_assignment is None location = locations.create_location("Location", "This is an example location", None, user.id) locations.assign_location_to_object( object.id, location.id, None, user.id, "This object is stored at this location") object_location_assignment = locations.get_current_object_location_assignment( object.id) assert object_location_assignment.object_id == object.id assert object_location_assignment.location_id == location.id assert object_location_assignment.user_id == user.id assert object_location_assignment.description == "This object is stored at this location" user_log_entries = user_log.get_user_log_entries(user.id) assert [ e for e in user_log_entries if e.data.get('object_location_assignment_id', -1) == object_location_assignment.id and e.type == UserLogEntryType.ASSIGN_LOCATION ] object_log_entries = object_log.get_object_log_entries(object.id) assert [ e for e in object_log_entries if e.data.get('object_location_assignment_id', -1) == object_location_assignment.id and e.type == ObjectLogEntryType.ASSIGN_LOCATION ]
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_create_location(user: User): assert len(locations.get_locations()) == 0 locations.create_location("Example Location", "This is an example location", None, user.id) assert len(locations.get_locations()) == 1 location = locations.get_locations()[0] assert location.name == "Example Location" assert location.description == "This is an example location" assert location.parent_location_id is None user_log_entries = user_log.get_user_log_entries(user.id) assert user_log_entries[-1].type == UserLogEntryType.CREATE_LOCATION assert user_log_entries[-1].data['location_id'] == location.id
def test_create_location_with_parent_location(user: User): parent_location = locations.create_location("Parent Location", "This is an example location", None, user.id) assert len(locations.get_locations()) == 1 user_log_entries = user_log.get_user_log_entries(user.id) assert len(user_log_entries) == 1 location = locations.create_location("Example Location", "This is an example location", parent_location.id, user.id) assert len(locations.get_locations()) == 2 location = locations.get_location(location.id) assert location.name == "Example Location" assert location.description == "This is an example location" assert location.parent_location_id == parent_location.id user_log_entries = user_log.get_user_log_entries(user.id) assert len(user_log_entries) == 2 user_log_entry = [ e for e in user_log_entries if e.data.get('location_id', -1) == location.id ][0] assert user_log_entry.type == UserLogEntryType.CREATE_LOCATION assert user_log_entry.data['location_id'] == location.id