Пример #1
0
 def do_allocate_room_type(self, arg):
     """Usage: allocate_room_type <room_name> <room_type>"""
     room = Room()
     room_name = arg['<room_name>']
     room_type = arg['<room_type>']
     status = room.allocate_room_type(room_name, room_type)
     print(status)
 def setUp(self):
     self.mars = Room("Mars", 4)
     self.pluto = Room("Pluto", 4)
     self.personA = Person("Malik Wahab", "M")
     self.personB = Person("Jola Ade", "M")
     self.personC = Person("Temi Tope", "F")
     self.personD = Person("Ose Oko", "F")
     self.personE = Person("TJ Peters", "M")
Пример #3
0
class Person(Staff, Fellow):
    '''Validate input data and undertake basic operaions
    '''
    def __init__(self):
        self.room = Room()

    def add_person(self, person_name, type_person, want_accomodation='n'):
        '''By default someone needs an Office '''
        staf = list(Staff.staff_names)
        felo = list(Fellow.fellow_names)
        if person_name in staf or person_name in felo:
            return person_name + ' already exists'

        elif type_person == 'staff':
            if 'y' == want_accomodation:
                return 'staff cannot have accomodation'

            create_staff = self.add(person_name, type_person)
            if create_staff is not True:
                return create_staff

            # By default the staff should never be allocated living space
            allocate_office = self.room.allocate_space(person_name)
            if allocate_office is not True:
                return allocate_office
            return 'Allocated Office:' + str(self.room.get_room(person_name))

        create_fellow = self.add(person_name, type_person)
        if create_fellow is not True:
            return create_fellow

        # A fellow may or not want accomodation
        return self.room.allocate_space(person_name, want_accomodation)

    def add(self, person_name, type_person):
        if person_name == '' or type(person_name) != str:
            return 'Invalid person name type used'

        elif len(person_name) > 21:
            return 'Too long person name'

        if type_person == 'fellow':
            return self.add_one_fellow(person_name)
        elif type_person == 'staff':
            return self.add_one_staff(person_name)
        else:
            return " '" + type_person + "' type person is unknown"

    def get_room_members(self, room_name):
        if room_name in list(Office.office_n_occupants.keys()):
            return Office.office_n_occupants[room_name]
        elif room_name in list(LivingSpace.room_n_occupants.keys()):
            return LivingSpace.room_n_occupants[room_name]
        return 'Room not Found'
class TestRoom(unittest.TestCase):

    def setUp(self):
        self.mars = Room("Mars", 4)
        self.pluto = Room("Pluto", 4)
        self.personA = Person("Malik Wahab", "M")
        self.personB = Person("Jola Ade", "M")
        self.personC = Person("Temi Tope", "F")
        self.personD = Person("Ose Oko", "F")
        self.personE = Person("TJ Peters", "M")

    def test_init_name(self):
        self.assertEqual(self.mars.name, "Mars")

    def test_init_size(self):
        self.assertEqual(self.mars.size, 4)

    def test_get_name(self):
        self.assertEqual(self.mars.name, "Mars")

    def test_occupants_empty(self):
        self.assertEqual(self.mars.occupants, {})

    def test_add_occupant(self):
        self.mars.add_occupant(self.personA)
        key = self.personA.identifier
        self.assertEqual(self.mars.occupants[key], self.personA)

    def test_add_occupant_exist(self):
        self.mars.occupants = self.personA
        with self.assertRaises(PersonInRoomError):
            self.mars.occupants = self.personA

    def test_is_full(self):
        self.pluto.occupants = self.personA
        self.pluto.occupants = self.personB
        self.pluto.occupants = self.personC
        self.pluto.occupants = self.personD
        self.assertTrue(self.pluto.is_full())

    def test_add_occupant_when_full(self):
        self.pluto.occupants = self.personA
        self.pluto.occupants = self.personB
        self.pluto.occupants = self.personC
        self.pluto.occupants = self.personD
        with self.assertRaises(RoomIsFullError):
            self.pluto.occupants = self.personE

    def test_get_id(self):
        self.assertEqual(self.pluto.get_id(), "pluto")
Пример #5
0
    def retieve_data_from_db_for_all_rooms(self):
        #Collect data to store in allocated. { Names }

        self.openDB()
        try:
            new_room_name = ""
            new_room_type = ""
            room = None
            self.cursor.execute('''
				SELECT * FROM Rooms 
			''')

            data = self.cursor.fetchall()
            Storage.list_of_all_rooms = []
            for rows in data:
                new_room_name = rows[0]
                new_room_type = rows[1]
                MyList = [rows[2], rows[3], rows[4], rows[5], rows[6], rows[7]]

                room = Room(new_room_name, new_room_type)
                for mem in range(len(MyList)):
                    if MyList[mem] != "":
                        room.Room_instance.current_members.append(
                            str(MyList[mem]))

                Storage.list_of_all_rooms.append(room)

            #print "\n",Storage.list_of_allocated_people
        except Exception as e:
            raise e
        self.closeDB()
    def createRoom(self, room_name=""):
        self.room_name = room_name.upper()
        result = False
        Result = ""

        for rooms in range(len(Storage.list_of_all_rooms)):
            if self.room_name == Storage.list_of_all_rooms[rooms].Room_name:
                #Check that the room already exist.
                result = True

        if self.room_name != "" and result != True:  #:
            #Create instance of room class
            room_type = random.choice(["OFFICE", "LIVINGSPACE"])
            self.room = Room(self.room_name, room_type)

            #Save instance of room in list of all rooms

            Storage.list_of_all_rooms.append(self.room)

            value = "\t{}\t\t[ {} ]\tcreated successfully!!".format(
                self.room.Room_name, self.room.Room_type)
            Result = "Room created successfully!!"
        else:
            value = "Room called {} failed to create.".format(
                self.room.Room_name)
        print value
        return Result
Пример #7
0
    def do_reallocate_person(self, arg):
        """Usage: reallocate_person <person_name> <room_name>"""

        person_name = arg['<person_name>']
        room_name = arg['<room_name>']

        print(Room().reallocate_room(person_name, room_name))
        print('=' * 75)
Пример #8
0
class TestRoom(unittest.TestCase):
    def setUp(self):
        self.room = Room("nairobi")

    def test_room_is_created(self):
        self.assertEqual(self.room.name, "Nairobi")
        self.assertEqual(self.room.max_capacity, 0)
        self.assertEqual(self.room.members, [])
        self.assertTrue(self.room.is_empty())
        self.assertEqual(self.room.type_, "Room")
Пример #9
0
 def do_print_allocations(self, arg):
     '''Usage: print_allocations [--o=filename]'''
     room = Room()
     file = arg['--o']
     if file is not None:
         room.print_allocations(file)
     else:
         room.print_allocations()
Пример #10
0
    def do_create_room(self, arg):
        """Usage: create_room <room_name>"""

        data = {}
        elements = arg['<room_name>'].replace(',', ' ').split(' ')
        for elem in elements:
            room_type = input(
                'Type(O/L): "O" -> Office or "L" -> Living Space\n %s :' %
                elem)
            if 'o' in room_type.lower():
                data[elem] = 'office'
            else:
                data[elem] = 'livingspace'

        # Save each at a go and  display messages
        for key, value in data.items():
            print(Room().create_room(room_name=key, room_type=value))
        print('=' * 75)
Пример #11
0
 def test_room_error_for_empty_parameters(self):
     '''test if error is raise when empty value is passed in Room'''
     with self.assertRaises(TypeError):
         Room()
Пример #12
0
 def test_assign_room_purpose(self):
     room = RoomFactory.create("Mission Control", 6)
     room.purpose = Room.assign_room_purpose("Mission Control", "office")
     self.assertEqual(room.purpose, "office")
Пример #13
0
 def setUp(self):
     self.room = Room()
     self.person = Person()
Пример #14
0
class TestRoom(unittest.TestCase):
    def setUp(self):
        self.room = Room()
        self.person = Person()

    def test_room_class_instance(self):
        self.assertIsInstance(self.room, Room)

    @patch.dict('app.room.Room.total_rooms', {'Michigan': []})
    def test_duplicate_room_creation(self):
        res = self.room.create_room('Michigan')
        self.assertEqual(res, 'A room with that name already exists!')

    @patch.dict('app.room.Room.total_rooms', {'Michigan': []})
    def test_it_creates_rooms(self):
        msg = self.room.create_room('narnia', 'whimm', 'kelly')
        self.assertEqual(msg, "Rooms have been successfully created")

    def test_it_creates_empty_room(self):
        with patch('app.room.Room'):
            mes = self.room.create_room()
            self.assertEqual(mes, "You can't create an empty room!")

    def test_create_room_input_string_type(self):
        with patch('app.room.Room'):
            self.room.create_room('vanish')
            self.assertEqual(type(self.room.room_name),
                             str,
                             msg="Room names should be Strings")

    @patch.dict('app.room.Room.total_rooms', {
        'Michigan': [],
        'galaxy': [],
        'vanish': []
    })
    def test_it_allocates_room_type(self):
        ret_o_val = self.room.allocate_room_type('vanish', 'Office')
        ret_l_val = self.room.allocate_room_type('galaxy', 'LivingSpace')
        self.assertEqual(ret_o_val, "vanish has been added as an Office")
        self.assertEqual(ret_l_val, "galaxy has been added as a LivingSpace")

        res = self.room.allocate_room_type('samsung', 'Office')
        self.assertEqual(res, "The room doesn't exist")

    @patch.dict('app.room.Room.total_rooms', {'vanish': []})
    def test_it_prints_an_existing_room(self):
        self.room.print_room('vanish')
        self.assertIn('vanish', Room.total_rooms.keys())

    @patch.dict('app.room.Room.total_rooms', {
        'Michigan': [],
        'galaxy': [],
        'vanish': []
    })
    def test_it_prints_room_occupants(self):
        msg = self.room.print_room('samsung')
        self.assertEqual(msg, "The room does not exist!")

    def test_it_prints_allocations(self):
        self.room.print_allocations('list.txt')
        self.assertIsNotNone('list.txt')
        pass

    @patch.dict('app.room.Room.total_rooms', {'Michigan': [], 'Camelot': []})
    @patch('app.room.Room.offices')
    @patch('app.room.Room.livingspaces')
    def test_commit_rooms(self, mock_livingspaces, mock_offices):
        mock_livingspaces.__iter__.return_value = ['Michigan']
        mock_offices.__iter__.return_value = ['Camelot']

        create_db('test_amity.db')
        msg = self.room.commit_rooms('test_amity.db')
        self.assertEqual(msg, 'rooms committed to session')

    @patch.dict('app.room.Room.total_rooms', {'Michigan': [], 'Camelot': []})
    @patch('app.room.Room.offices')
    @patch('app.room.Room.livingspaces')
    def test_load_rooms(self, mock_livingspaces, mock_offices):
        mock_livingspaces.__iter__.return_value = ['Michigan']
        mock_offices.__iter__.return_value = ['Camelot']

        msg = self.room.load_rooms('test_amity.db')
        self.assertEqual(msg, 'Room data added successfully')
Пример #15
0
 def setUp(self):
     self.room = Room("Hogwards")
Пример #16
0
class Test(unittest.TestCase):
    def setUp(self):
        self.room = Room("Hogwards")

    def test_room_name_and_type(self):
        self.assertNotEqual(self.room.Room_name,
                            "",
                            msg="Cannot create empty room.")
        self.assertIn(self.room.Room_type.upper(), ["OFFICE", "LIVINGSPACE"],
                      msg="Room can be office or living space.")

    """
	@patch('app.storage')
	def test_room_reallocation_variables(self,test_storage):
		self.room.reallocate_person()
		result = Mock()
		result.id_no.return_value = 12345678
		result.New_Room_name.return_value = "Hogwards"
		self.assertNotEqual(self.room.id_no, 0, msg= "Invalid id number submitted.")
		self.assertNotEqual(self.room.New_Room_name, "", msg  = "The room does not exist.")
		#test_storage.people_info.return_value = {12345678:"Marvin Kangethe", 98765432:"John Doe"}
			
		
	@patch('app.person')
	@patch('app.office')
	@patch('app.livingspace')
	def test_successful_room_reallocation(self,test_person,test_office,test_livingspace):
		test_person.name.return_value = "Marvin Kangethe"
		test_office.current_members.return_value = ["Marvin Kangethe","John Doe"]
		test_livingspace.current_members.return_value = test_office.current_members.return_value
		result = test_livingspace.current_members.return_value
		if self.room.reallocate_person() == "Person reallocation successfull!!":
			self.assertNotIn(
				test_person.name, self.room.Room_instance.current_members, msg = "The person is already allocated room somewhere else")
		else:
			print "Check something"
	"""

    @patch('app.storage')
    def test_new_room_exist(self, test_storage):
        test_storage.list_of_all_rooms.return_value = [
            "Hogwards", "Camelot", "Narnia"
        ]
        result_mock = Mock()
        result_mock.New_Room_name.return_value = "Hogwards"
        self.assertIn(result_mock.New_Room_name.return_value,
                      test_storage.list_of_all_rooms.return_value,
                      msg="The rooms does not exist.")

    @patch('app.storage')
    @patch('app.person')
    def test_room_allocation(self, test_storage, test_person):
        test_person.name.return_value = "Alex Kang"
        test_person.id_no.return_value = 39090901
        test_storage.people_info.return_value = {
            12345678: "Marvin Kangethe",
            98765432: "John Doe"
        }
        test_storage.list_of_all_rooms.return_value = [
            "Hogwards", "Camelot", "Narnia"
        ]

        self.room.allocate_member_a_room(test_person.name.return_value,
                                         test_person.id_no.return_value)
        #print test_storage.people_info.return_value
        #self.assertTrue(
        #	bool(test_storage.people_info.return_value.has_key(
        #		test_person.id_no.return_value)), msg = "The person hasn't been added yet.")
        self.assertFalse(test_storage.people_info.return_value.has_key(
            test_person.id_no.return_value),
                         msg="Person has room already allocated.")
Пример #17
0
    def create(name, max_occupancy):
        room = Room(name, max_occupancy)

        return room
Пример #18
0
 def do_create_room(self, arg):
     """Usage: create_room <room_name>..."""
     room = Room()
     rooms = arg['<room_name>']
     for rm in rooms:
         status = room.create_room(rm)
Пример #19
0
 def __init__(self):
     self.room = Room()
Пример #20
0
        self.rooms = {}
        self.start_room = None
        self.end_room = None

    def random_room(self):
        return random.choice(self.rooms.values())


app.game = Game()
maze = generate_braid_maze(20, 20)
maze.render_text()

rooms = [[None for x in range(maze.width)] for y in range(maze.height)]
for y in range(maze.height):
    for x in range(maze.width):
        room = Room('x%dy%d' % (x, y), x, y)
        rooms[y][x] = room
        if x > 0 and not maze.is_wall_left(x, y):
            room.connect(rooms[y][x - 1], 'w')
        if y > 0 and not maze.is_wall_up(x, y):
            room.connect(rooms[y - 1][x], 'n')

app.game.start_room = rooms[2][2]
app.game.end_room = rooms[maze.height - 3][maze.width - 3]

# Breadth first search the dungeon, marking distance to the exit
rooms_found = set([app.game.end_room])
room_queue = [(app.game.end_room, 0)]
while len(room_queue) > 0:
    (room, distance) = room_queue[0]
    room_queue = room_queue[1:]
Пример #21
0
 def test_raises_error_if_non_string_paremeters_passed(self):
     ''' Test that room captures only strings'''
     with self.assertRaises(TypeError):Room(123456)
Пример #22
0
        "UpperTank": "Tanque elevado",
        "Pump": "Bomba",
        "Pir": "Sensor de movimiento",
        "Ldr": "Sensor de luminosidad",
        "Light": "Luminaria",
        "Door": "Sensor de puerta"
    }


port1 = Serial(port="/dev/tty2", baudrate=19200)
ports = [port1]

slave1 = Slave("Taller", "taller", 1, 0, 18, 18, 7, port1)
slaves = [slave1]

cameras = Room('Camaras', 'cameras')
taller = Room('Taller', 'taller')
rooms = [cameras, taller]

tanque = UpperTank("Tanque",
                   "upperTank0",
                   taller,
                   slave1,
                   18,
                   0,
                   min_level=25,
                   capacity=500)
cisterna = LowerTank("Cisterna",
                     "lowerTank0",
                     taller,
                     slave1,
 def test_office_is_instance_of_room(self):
     blue_office = Room('blue', 'office')
     self.assertIsInstance(blue_office, Room)
Пример #24
0
 def do_print_room(self, arg):
     """Usage: print_room <room_name>"""
     room = Room()
     room.print_room(arg['<room_name>'])
Пример #25
0
class TestRoom(unittest.TestCase):
    def setUp(self):
        self.room = Room()

    @patch.dict('app.office.Office.office_n_occupants', {"Dojo": []})
    def test_create_room(self):
        res = self.room.create_room(room_name='Valhala', room_type='office')
        self.assertEqual(res, 'Valhala was created as an Office')

        # create duplicate room (With same name)
    @patch.dict('app.office.Office.office_n_occupants', {"Dojo": []})
    @patch.dict('app.livingspace.LivingSpace.room_n_occupants',
                {"Valhala": []})
    def test_create_duplicate_room(self):
        res = self.room.create_room(
            room_name='Valhala', room_type='LivingSpace')
        self.assertEqual(res, 'Valhala already exists ')

        # create a room without a name
    def test_create_room_without_name(self):
        res = self.room.create_room(room_name='', room_type='Office')
        self.assertEqual(res, 'Room name used is invalid')

        # create type of room not available
    def test_create_room_type_not_available(self):
        res = self.room.create_room(room_name='Valhala', room_type='game room')
        self.assertEqual(
            res, "Create a room of type 'LivingSpace' or 'Office'  ONLY!")

    @patch('app.room.Room.randomly_allocate_rooms')
    @patch('app.room.Room.get_room')
    @patch('app.fellow.Fellow.fellow_names')
    def test_allocate_space(self, mock_fellow_names, mock_get_room,
                            mock_randomly_allocate_rooms):
        mock_fellow_names.__iter__.return_value = ['Gaamuwa']
        mock_randomly_allocate_rooms.return_value = True
        mock_get_room.return_value = 'None'
        value = self.room.allocate_space('Gaamuwa', 'y')
        mock_get_room.return_value = 'None'
        self.assertEqual(
            'Allocated Office Space : None \nAllocated Living Space : None',
            value)

    def test_randomly_allocate(self):
        capacity = 1
        data = {'Krypton': []}
        person_name = 'MIgwi'
        ret_val = self.room.randomly_allocate_rooms(
            capacity, data, person_name)
        self.assertTrue(ret_val)

        person_name = 'Zainab'
        ret_val = self.room.randomly_allocate_rooms(
            capacity, data, person_name)
        self.assertEqual('All rooms are full to capacity', ret_val)

    @patch('app.staff.Staff.staff_names')
    @patch.dict('app.office.Office.office_n_occupants', {'Narnia': []})
    @patch('app.fellow.Fellow.fellow_names')
    @patch.dict('app.livingspace.LivingSpace.room_n_occupants', {'Dojo': []})
    @patch('app.room.Room.reallocate')
    def test_reallocate_room(self, mock_reallocate, mock_fellow_names,
                             mock_staff_names):
        mock_reallocate.return_value = True
        mock_fellow_names.__iter__.return_value = ['njoroge']
        mock_staff_names.__iter__.return_value = ['James_Ndiga']
        person_name, room_name = 'James_Ndiga', 'Narnia'
        ret_val = self.room.reallocate_room(person_name, room_name)
        self.assertIn(person_name, ret_val)
        self.assertIn(room_name, ret_val)
        self.assertIn('was allocated an Office', ret_val)

        person_name, room_name = 'James_Ndiga', 'Dojo'
        ret_val = self.room.reallocate_room(person_name, room_name)
        self.assertEqual(
            'Living Spaces are allocated to fellows ONLY', ret_val)

        person_name, room_name = 'njoroge', 'Php'
        ret_val = self.room.reallocate_room(person_name, room_name)
        self.assertEqual('Room Not Found in the system', ret_val)

        person_name, room_name = 'njoroge', 'Dojo'
        ret_val = self.room.reallocate_room(person_name, room_name)
        self.assertIn(person_name, ret_val)
        self.assertIn(room_name, ret_val)
        self.assertIn('was allocated a Living Space', ret_val)

    @patch.dict('app.livingspace.LivingSpace.room_n_occupants', {'Mars': []})
    @patch('app.livingspace.LivingSpace.living_capacity')
    @patch('app.room.Room.get_room')
    def test_reallocate(self, mock_get_room, mock_living_capacity):
        mock_get_room.return_value = 'None'
        mock_living_capacity.return_value = 1

        value = self.room.reallocate('david', 'Mars', 'livingspace')
        self.assertTrue(value)

        value = self.room.reallocate('Stan', 'Mars', 'livingspace')
        self.assertEqual('Mars has a max of 1 person(s) currently', value)

    @patch.dict('app.office.Office.office_n_occupants',
                {'Alien-Planet': ['Sam', 'Edwin', 'Steve']})
    def test_get_room(self):
        assign = self.room.get_room(person_name='Steve', type_space='office')
        self.assertEqual('Alien-Planet', assign)
Пример #26
0
 def setUp(self):
     self.room = Room()
Пример #27
0
 def test_assign_room_purpose(self):
     room = RoomFactory.create("Mission Control", 6)
     room.purpose = Room.assign_room_purpose("Mission Control", "office")
     self.assertEqual(room.purpose, "office")
Пример #28
0
 def setUp(self):
     self.room = Room("nairobi")
 def test_livingquaters_is_instance_of_room(self):
     blue_living = Room('red', 'living Quaters')
     self.assertIsInstance(blue_living, Room)