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 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())
def print_list_of_allocations(): """This prints the list of allocations """ for room, occupants in Manager.get_list_of_allocations(): print str(room) Manager.get_members_in_room(room.name, print_stdio=True)
def allocate(): for person in Amity.people_collection: Manager.assign_to_room(person)
{ 'id': 6, 'type': 'E', 'gn': 'Susan', 'sn': 'Gallagaher', 't': 'AppleCare', 'm': 4 }, { 'id': 7, 'type': 'E', 'gn': 'John', 'sn': 'Couch', 't': 'Education', 'm': 4 }, { 'id': 8, 'type': 'E', 'gn': 'Jonathan', 'sn': 'Ive', 't': 'Design', 'm': 1 }, { 'id': 9, 'type': 'M', 'gn': 'Philip', 'sn': 'Schiller', 't': 'Product Marketing', 'm': 1 }, { 'id': 10, 'type': 'E', 'gn': 'Eddy', 'sn': 'Cue', 't': 'Internet Services', 'm': 9 }, { 'id': 11, 'type': 'E', 'gn': 'Greg', 'sn': 'Joswiak', 't': 'iPhone & iPod Marketing', 'm': 9 }, ] # Employee Dictionary employees = {} # Load Sample Data into Classes and store in our "employees" Dictionary for p in data: # Pick which class we're using if p['type'] == 'M': e = Manager() else: e = Employee() # Basic Data e.id = p['id'] e.givenname = p['gn'] e.surname = p['sn'] e.title = p['t'] # If the person has a manager, record it if 'm' in p: e.manager = employees[p['m']] employees[p['m']].reports.append(e) # Add to Employee Directory
def test_can_assign_singly_to_room(self): self.assertEquals(Amity.room_collection[1].has_female_occupant(), False) Manager.assign_to_room(self.f, self.l) self.assertEquals(Amity.room_collection[1].has_female_occupant(), True)
def assign_all(room_name): for person in persons: Manager.assign_to_room(person, room_name)