def assign_to_room(person, room=None): """Assign a person to a room. <room_name> is optional. """ # find a person by name if type(person) is str: person = Amity.find_person(person) # find a room by name if specified if type(room) is str: room = Amity.find_room(room) # is the room an office? if isinstance(room, Office): if not person.has_office(): Manager.assign_to_office(person, room) # is the room a living space? if isinstance(room, LivingSpace): if person.can_have_living_space() and \ not person.has_living_space(): Manager.assign_to_living_space(person, room) elif room is None: if not person.has_office(): Manager.assign_to_office(person) if isinstance(person, Fellow) and person.can_have_living_space(): if not person.has_living_space(): Manager.assign_to_living_space(person)
def get_members_in_room(room_name, print_stdio=False): """Given a room, this prints all members in it. """ room = Amity.find_room(room_name) occupants = ', '.join(occupant.name for occupant in room.occupants) if print_stdio is True: print occupants return occupants
def test_can_generate_and_assign_to_rooms(self): rooms = alloc.generate_rooms('office') self.assertEquals(len(rooms), 10) Amity.add_rooms(rooms) self.assertIsInstance(rooms[randint(0, 9)], Office) rooms = alloc.generate_rooms('living space') self.assertEquals(len(rooms), 10) Amity.add_rooms(rooms) self.assertIsInstance(rooms[randint(0, 9)], LivingSpace) self.assertEqual(Amity.room_count, 20) # test that file can be parsed PeopleFileParser.line_to_person(file_path) person_name = 'ANDREW PHILLIPS' Manager.assign_to_room(person_name, 'Room 1') Manager.assign_to_room(person_name, 'Room 10') person = Amity.find_person(person_name) self.assertEquals(person.office.name, 'Room 1') self.assertIn(person, Amity.find_room('Room 1').occupants) # test that manager can make allocations Manager.allocate() self.assertEquals([], Manager.get_list_of_unallocated_people())