def rellocate_person(self, person_id, new_room_id):
        """Rellocate person to the room specified.

        Raises:
            KeyError

        Arguments
            person_id: Id of person to be rellocated
            new_room_id: room to be relocated to

        """
        try:
            person_obj = self.amity.persons[person_id]
        except KeyError:
            raise KeyError("Invalid Person Id provided")
        try:
            new_room_obj = self.amity.rooms[new_room_id]
        except KeyError:
            raise KeyError("Invalid Room Id provided")
        room_type = Amity.get_room_type(new_room_obj)
        old_room_name = person_obj.room_name.get(room_type)
        try:
            new_room_obj.add_occupant(person_obj)
        except (RoomIsFullError, PersonInRoomError) as err:
            raise err
        else:
            if old_room_name:
                old_room_obj = self.amity.rooms[old_room_name]
                del old_room_obj.occupants[person_obj.identifier]
            person_obj.room_name[room_type] = new_room_obj.get_id()
    def allocate_room(self, person_id, room_dict):
        """Allocate a random room from the supplied room dictionary
           to person of specified id

        Raises:
            KeyError
            PersonInRoomError

        Arguments
            person_id: id pf person object to be allocated to a random room
            room_dict: a dictionary object of type room

        Return:
            boolean: true on successful allocation

        """
        person_obj = self.amity.persons[person_id]
        no_of_rooms = len(room_dict.keys())
        if no_of_rooms < 1:
            raise NoRoomError
        i = 0
        while i <= no_of_rooms:
            i += 1
            room_obj = RoomAllocation.select_random(room_dict)
            if not room_obj.is_full():
                break
            if i == no_of_rooms:
                raise NoRoomError("No free room to allocate Person")
        room_type = Amity.get_room_type(room_obj)
        if person_obj.is_allocated(room_type):
            raise PersonAllocatedError
        else:
            room_obj.add_occupant(person_obj)
            person_obj.room_name[room_type] = room_obj.get_id()
            return True
    def print_room(self, room_id):
        """Build the string of a room with the persons in it.

        Arguments:
            room_id - id of room to print

        """
        room = self.amity.rooms[room_id]
        room_string = ""
        room_type = Amity.get_room_type(room)
        room_string += "\n--" + room.name + "(" + room_type + ")--\n"
        persons = room.occupants
        for i in persons:
            room_string += self.print_person(persons[i])
        return room_string
    def remove_room(self, room_id):
        """Remove a specified room from amity
        render all person in room unallocated

        Arguments
            room_id - id of room to be remove from amity

        """
        room = self.amity.rooms[room_id]
        room_type = Amity.get_room_type(room)
        persons = room.occupants
        for i in persons:
            person = persons[i]
            del person.room_name[room_type]
        del self.amity.rooms[room_id]
 def test_get_room_type_thee(self):
     self.assertIsNone(Amity.get_room_type({}))
 def test_get_room_type_two(self):
     self.assertEqual(Amity.get_room_type(self.officeA), 'office')
 def test_get_room_type(self):
     self.assertEqual(Amity.get_room_type(self.livingA), 'livingspace')