Пример #1
0
 def do_add_person(self, arg):
     """Usage: add_person <first_name> <last_name> <job_type> <accomodation>"""
     person = Person()
     first_name = arg['<first_name>']
     last_name = arg['<last_name>']
     job_type = arg['<job_type>']
     accomodation = arg['<accomodation>']
     person.add_person(first_name, last_name, job_type, accomodation)
Пример #2
0
class TestPerson(unittest.TestCase):
    def setUp(self):
        self.person = Person()

    # test add fellow who doesn't need living space or office
    @patch('app.person.Person.add')
    @patch('app.fellow.Fellow.fellow_names')
    @patch('app.room.Room.allocate_space')
    def test_add_fellow_who_dont_need_room(self, mock_allocate_space,
                                           mock_fellow_names, mock_add):
        mock_fellow_names.__iter__.return_value = []
        mock_allocate_space.return_value = """Kimani Ndegwa has been allocated Office:"""
        mock_add.return_value = True
        pers = self.person.add_person(person_name='Kimani Ndegwa',
                                      type_person='fellow',
                                      want_accomodation='n')
        self.assertIn('Kimani Ndegwa has been allocated Office:', pers)

    @patch('app.room.Room.get_room')
    @patch('app.person.Person.add')
    @patch('app.room.Room.allocate_space')
    @patch('app.staff.Staff.staff_names')
    def test_add_staff(self, mock_staff_names, mock_allocate_space,
                       mock_add, mock_get_room):
        mock_staff_names.__iter__.return_value = []
        mock_allocate_space.return_value = True
        mock_add.return_value = True
        mock_get_room.return_value = ' HAIL CESEAR!!'
        pers = self.person.add_person(person_name='Garbriel Mwata',
                                      type_person='staff',
                                      want_accomodation='n')
        self.assertIn('Allocated Office: HAIL CESEAR!!', pers)

    # test add staff and assign them livingspace
    def test_add_staff_assign_livingspace(self):
        pers = self.person.add_person(person_name='Njira', type_person='staff',
                                      want_accomodation='y')
        self.assertEqual(pers, 'staff cannot have accomodation')

    @patch('app.staff.Staff.staff_names')
    def test_add_two_people_who_share_name(self, mock_staff_names):
        mock_staff_names.__iter__.return_value = ['Joshua']
        pers = self.person.add_person(
            person_name='Joshua', type_person='staff')
        self.assertEqual(pers, 'Joshua already exists')

    @patch.dict('app.office.Office.office_n_occupants', {'Rm': ['we', 'ty']})
    def test_get_room_members(self):
        rm = self.person.get_room_members(room_name='Rm')
        self.assertEqual(rm, ['we', 'ty'])
    def allocateRoom(self, name="", jobType="", wantsRoom="NO"):
        self.name = name

        self.jobType = jobType.upper()
        #Check that wants room is only yes or no
        if not wantsRoom.upper() in ["Y", "YE", "YES", "N", "NO"]:
            print "Use 'yes' if you want room allocation, else use 'no'."
            return None
        elif len(Storage.list_of_all_rooms) < 1:
            print "No existing rooms to allocate you for now."
            return None
        else:
            #Set the wantsRoom variable so that staff cannot decline room allocation.
            if self.jobType == "STAFF":
                self.wantsRoom = "YES"
            else:
                self.wantsRoom = wantsRoom
            """
			Create the person instance and allocate room 
			if there are available rooms hence save the person in unallocated list.
			"""
            if self.wantsRoom.upper() in ["Y", "YE", "YES"]:
                self.wantsRoom = "YES"
                self.person = Person(self.name, self.jobType, self.wantsRoom,
                                     0, 0)
                Storage.list_of_all_people.extend([self.person])
                #call the random room allocator.
                #pass the person instance variables.
                self.randomRoomAllocator(self.person.name, self.person.jobType,
                                         self.person.wantsRoom,
                                         self.person.id_no)

            else:
                print "Be safe at where you will stay.\n"
Пример #4
0
def postJsonHandler():
    content = request.get_json()
    if DEBUG is True:
        print("Request is json:", request.is_json)
        print("Content is:", content)
    name = content['name']
    age = content['age']
    gender = content['gender']
    weight = content['weight']
    activitylevel = content['activitylevel']
    goal = content['goal']
    length = content['length']
    #level = content['level']
    person = Person(name=name,
                    age=age,
                    gender=gender,
                    weight=weight,
                    activitylevel=activitylevel,
                    goal=goal,
                    length=length)
    return jsonify( \
        bmr=person.bmr, tdee=person.tdee, \
        proteinReqGram=person.proteinReqGram, proteinReqKcal=person.proteinReqKcal, proteinReqPerc=person.proteinReqPerc, \
        fatReqGram=person.fatReqGram, fatReqKcal=person.fatReqKcal, fatReqPerc=person.fatReqPerc, \
        carbReqGram=person.carbReqGram, carbReqKcal=person.carbReqKcal, carbReqPerc=person.carbReqPerc)
Пример #5
0
    def do_print_room(self, arg):
        """Usage: print_room <room_name>"""

        room_name = arg['<room_name>']

        print(Person().get_room_members(room_name))
        print('=' * 75)
class PersonTest(unittest.TestCase):

    def setUp(self):
        self.person_male = Person("Wahab Malik", "M")
        self.person_female = Person("Janet John", "F")
        self.person_male.room_name['office'] = 'Mars'
        self.person_male.room_name['livingspace'] = 'Sapele'

    def test_init_name(self):
        self.assertEqual("Wahab Malik", self.person_male.name)

    def test_init_gender(self):
        self.assertEqual("M", self.person_male.gender)

    def test_is_allocated(self):
        self.assertTrue(self.person_male.is_allocated('office'))

    def test_is_allocated_two(self):
        self.assertFalse(self.person_female.is_allocated("office"))

    def test_generate_id(self):
        first_id = self.person_male.generate_id()
        second_id = self.person_male.generate_id()
        self.assertNotEqual(first_id, second_id)

    def test_generate_id_two(self):
        first_id = self.person_male.generate_id()
        second_id = self.person_female.generate_id()
        self.assertNotEqual(first_id, second_id)
Пример #7
0
 def do_print_unallocated(self, arg):
     '''Usage: print_unallocated [--o=filename]'''
     person = Person()
     file = arg['--o']
     if file is not None:
         person.print_unallocated(file)
     else:
         person.print_unallocated()
Пример #8
0
    def retieve_data_from_db_for_all_people(self):
        self.openDB()
        try:
            self.cursor.execute('''
				SELECT * FROM Person
			''')
            info = self.cursor.fetchall()
            for rows in info:
                pp = Person(rows[0], rows[2], rows[3], 1, rows[1])
                Storage.list_of_all_people.append(pp)

        except Exception as e:
            raise e
        self.closeDB()
Пример #9
0
    def do_add_person(self, arg):
        """Usage: add_person <person_name> (FELLOW|STAFF) [<wants_accommodation>] """

        person_name = arg["<person_name>"]
        stf = arg['STAFF']
        flw = arg['FELLOW']

        if stf is None:
            type_person = flw
        else:
            type_person = stf

        need = 'n'
        if arg['<wants_accommodation>'] is not None:
            need = arg['<wants_accommodation>']

        print(Person().add_person(person_name, type_person.lower(),
                                  need.lower()))
        print('=' * 75)
class Test(unittest.TestCase):
	
	def setUp(self):
		self.person = Person("Marvin","FELLOW","YES")

	def test_instance_valriables(self):
		self.assertNotEqual(self.person.name,"",msg = "Invalid name credentials.")	
		self.assertIn(
			self.person.jobType.upper(),
			["STAFF","FELLOW"],msg = "Person can only be STAFF or FELLOW")	
		self.assertIn(
			self.person.wantsRoom.upper(),
			["Y","YE","YES","N","NO"], msg = "Use only YES or NO.")

	@patch('app.storage')	
	def test_person_not_in_system(self,test_storage):
		test_storage.people_info.return_value = {12345678 : "marvin kangethe", 98765432 : "john doe"}
		self.person.id_no = 22345678
		self.assertEqual(
			type(self.person.id_no),
			int, msg = "ID numbers must have an integer format.")
		
		self.assertFalse(
			bool(test_storage.people_info.return_value.has_key(self.person.id_no)),
			msg = "Person already in the system.")
 
		
	@patch('app.storage')
	def test_add_member_to_system(self,test_storage):
		test_storage.people_info.return_value = {12345678 : "Marvin Kangethe", 98765432 : "John Doe"}
		result = self.person.add_member_to_system()

		if result == "Member added successfully":
			self.assertTrue(test_storage.people_info.has_key(self.person.id_no),msg = "The person hasn't been added  yet.")
		else:
			self.assertNotEqual(self.person.name, "", msg = "Cannot add an empty person to the system.")
			self.assertNotEqual(self.person.id_no, 0, msg = "Cannot add a person without valid ID to the system.")
			self.assertTrue(test_storage.people_info.has_key(self.person.id_no), msg = "The person cannot be added to the system.")	
Пример #11
0
    def load_people(self, filename='people.txt'):
        '''loads people into the database'''
        with open(filename, 'r') as input_file:
            people = input_file.readlines()
            data = []
            for persn in people:
                persn = persn.split(' ')
                if persn:
                    wants_accomodation = 'n'
                    person_name = persn[0]
                    if 'STAFF' in persn:
                        type_person = 'staff'
                    else:
                        type_person = 'fellow'

                    if len(persn) > 2:
                        ps = persn[2]
                        if '\n' in ps:
                            wants_accomodation = ps[:ps.index('\n')].lower()
                        else:
                            wants_accomodation = ps.lower()

                    arg_dict = {
                        "person_name": person_name,
                        "type_person": type_person,
                        "wants_accomodation": wants_accomodation
                    }
                data.append(arg_dict)
        for entry in data:
            ret_val = Person().add_person(
                person_name=entry["person_name"],
                type_person=entry["type_person"],
                want_accomodation=entry["wants_accomodation"])
            if ret_val == 'None':
                print ('No Rooms Available')
            else:
                print(ret_val)
Пример #12
0
 def do_load_people(self, arg):
     '''Usage: load_people <filename>'''
     person = Person()
     status = person.load_people_data(arg['<filename>'])
     print(status)
	def setUp(self):
		self.person = Person("Marvin","FELLOW","YES")
Пример #14
0
 def setUp(self):
     self.room = Room()
     self.person = Person()
Пример #15
0
 def do_reallocate_person(self, arg):
     """Usage: reallocate_person  <person_id> <room_name>"""
     person = Person()
     allocate_status = person.reallocate_person(int(arg['<person_id>']),
                                                arg['<room_name>'])
     print(allocate_status)
 def test_check_person_str(self):
     p1 = Person("Yousra", "Mashkoor", "Karachi street 123")
     self.assertEqual(
         str(p1),
         'First Name: Yousra\nLast Name: Mashkoor\nAddress: Karachi street 123'
     )
 def test_changeAddr(self):
     p1 = Person("Yousra", "Mashkoor", "Karachi street 123")
     p1.changeAddr("London lane 5")
     self.assertNotEqual("Karachi street 123", p1.Address)
Пример #18
0
 def setUp(self):
     self.person = Person()
 def setUp(self):
     self.person_male = Person("Wahab Malik", "M")
     self.person_female = Person("Janet John", "F")
     self.person_male.room_name['office'] = 'Mars'
     self.person_male.room_name['livingspace'] = 'Sapele'
Пример #20
0
 def setUp(self):
     self.person = Person()
     sys.stdout = StringIO()
Пример #21
0
 def setUp(self):
     self.person = Person("Billy Baggins")
Пример #22
0
class TestPerson(unittest.TestCase):
    def setUp(self):
        self.person = Person()
        sys.stdout = StringIO()

    def test_person_class_instance(self):
        self.assertIsInstance(self.person, Person)

    @patch.dict('app.room.Room.total_rooms', {'oculus': [], 'haskel': []})
    @patch.dict('app.person.Person.total_people', {1: 'MigwiNdungu'})
    @patch('app.room.Room.offices')
    @patch('app.room.Room.livingspaces')
    @patch('app.person.Person.fellows')
    @patch('app.person.Person.staff')
    def test_it_adds_a_person(self, mock_staff, mock_fellows,
                              mock_livingspaces, mock_offices):
        mock_livingspaces.__iter__.return_value = ['haskel']
        mock_offices.__iter__.return_value = ['oculus']
        mock_fellows.__iter__.return_value = []
        mock_staff.__iter__.return_value = []

        already_present = self.person.add_person('Migwi', 'Ndungu', 'Fellow',
                                                 'Y')
        self.assertEqual(
            already_present,
            'oops! Someone with the username MigwiNdungu already exists')

        no_accomodation = self.person.add_person('Ben', 'Kamau', 'Fellow', 'N')
        self.assertEqual(no_accomodation,
                         'BenKamau added to unallocated-people')

        staff_accomodation = self.person.add_person('Michelle', 'Korir',
                                                    'Staff', 'Y')
        self.assertEqual(
            staff_accomodation,
            'NOTE: Staff members are not allocated livings paces')

        successfull_staff_add = self.person.add_person('Buck', 'Speed',
                                                       'Staff', 'N')
        self.assertEqual(successfull_staff_add,
                         'Staff member added successfully')

    @patch.dict(
        'app.room.Room.total_rooms', {
            'oculus': [1, 2, 5, 6, 9, 10],
            'narnia': [3, 4, 7, 8, 11, 12],
            'haskel': [1, 2, 3, 4]
        })
    @patch.dict(
        'app.person.Person.total_people', {
            1: 'MigwiNdungu',
            2: 'JosephMuli',
            3: 'Josh',
            4: 'Njira',
            5: 'kevin',
            6: 'mwangi',
            7: 'john',
            8: 'milkah',
            9: 'noelah',
            10: 'serah',
            11: 'sila',
            12: 'mary'
        })
    @patch('app.room.Room.offices')
    @patch('app.room.Room.livingspaces')
    @patch('app.person.Person.fellows')
    @patch('app.person.Person.staff')
    def test_adding_to_fully_occupied_rooms(self, mock_staff, mock_fellows,
                                            mock_livingspaces, mock_offices):
        mock_livingspaces.__iter__.return_value = ['haskel']
        mock_offices.__iter__.return_value = ['oculus']
        mock_fellows.__iter__.return_value = []
        mock_staff.__iter__.return_value = []

        fully_occupied_office = self.person.add_person('Jimmy', 'Kamau',
                                                       'Staff', 'N')
        self.assertEqual(
            fully_occupied_office,
            'all offices are currently fully occupied, adding to staff-unallocated-without-offices...'
        )

        fully_occupied_ls = self.person.add_person('Alex', 'Magana', 'Fellow',
                                                   'Y')
        self.assertEqual(
            fully_occupied_ls,
            'sorry all living spaces are currently fully occupied, adding to unallocated...'
        )

    @patch.dict('app.room.Room.total_rooms', {'oculus': []})
    @patch.dict('app.person.Person.total_people', {1: 'Migwi'})
    @patch('app.room.Room.offices')
    @patch('app.room.Room.livingspaces')
    @patch('app.person.Person.fellows')
    @patch('app.person.Person.staff')
    def test_response_on_no_rooms(self, mock_staff, mock_fellows,
                                  mock_livingspaces, mock_offices):
        mock_offices.__iter__.return_value = ['oculus']
        mock_livingspaces.__iter__.return_value = []
        mock_fellows.__iter__.return_value = []
        mock_staff.__iter__.return_value = []

        msg = self.person.add_person('joan', 'ngugi', 'Fellow', 'Y')
        self.assertEqual(msg, "There are currently no livingspaces")

    @patch.dict(
        'app.room.Room.total_rooms', {
            'oculus': [1],
            'green': [],
            'mordor': [],
            'shire': [23, 43, 52, 12, 32, 32],
            'haskel': [],
            'python': [1],
            'ruby': [],
            'blue': [98, 75, 45, 24, 76, 99]
        })
    @patch.dict('app.person.Person.total_people', {1: 'Migwi', 2: 'jojo'})
    @patch('app.room.Room.offices')
    @patch('app.room.Room.livingspaces')
    @patch('app.person.Person.fellows')
    @patch('app.person.Person.staff')
    def test_reallocation(self, mock_staff, mock_fellows, mock_livingspaces,
                          mock_offices):
        mock_livingspaces.__iter__.return_value = [
            'haskel', 'python', 'ruby', 'blue'
        ]
        mock_offices.__iter__.return_value = ['oculus', 'mordor', 'shire']
        mock_fellows.__iter__.return_value = ['Migwi']
        mock_staff.__iter__.return_value = ['jojo']

        fully_occupied = self.person.reallocate_person(1, 'shire')
        self.assertEqual(fully_occupied, "Sorry the office is occupied fully")

        already_present = self.person.reallocate_person(1, 'oculus')
        self.assertEqual(
            already_present,
            "The Person is already allocated in the requested room")

        msg = self.person.reallocate_person(1, 'mordor')
        self.assertEqual(msg, "Allocation to New office successfull!")

        person_msg = self.person.reallocate_person(3, 'mordor')
        self.assertEqual(person_msg, "The person ID does not exist!")

        room_msg = self.person.reallocate_person(1, 'shell')
        self.assertEqual(room_msg, "The room doesn't exist!")

        fellow_reallocate_livingspace = self.person.reallocate_person(
            1, 'ruby')
        self.assertEqual(fellow_reallocate_livingspace,
                         "Allocation to New livingSpace successful!")

        fully_occupied_ls = self.person.reallocate_person(1, 'blue')
        self.assertEqual(fully_occupied_ls,
                         "Sorry the LivingSpace is currently fully occupied!")

        unallocated_room = self.person.reallocate_person(1, 'green')
        self.assertEqual(unallocated_room, "green  was not  Allocated")

    @patch('app.person.Person.add_person')
    def test_loads_people(self, mock_add_person):
        mock_add_person.return_value = ''
        sample_read_text = 'OLUWAFEMI SULE FELLOW Y'
        with patch("__builtin__.open",
                   mock_open(read_data=sample_read_text)) as mock_file:
            self.person.load_people_data('list.txt')
        # assert open("people.txt", 'r').readlines() == sample_read_text
        mock_file.assert_called_with("list.txt")

    @patch.dict('app.room.Room.total_rooms', {
        'oculus': [1],
        'mordor': [2],
        'python': [1]
    })
    @patch.dict('app.person.Person.total_people', {
        1: 'Migwi',
        2: 'jojo',
        3: 'jimbo'
    })
    @patch('app.room.Room.offices')
    @patch('app.room.Room.livingspaces')
    @patch('app.person.Person.fellows')
    @patch('app.person.Person.staff')
    @patch('app.person.Person.unallocated_people')
    @patch('app.person.Person.fellows_not_allocated_office')
    @patch('app.person.Person.staff_not_allocated_office')
    def test_commit_people(self, mock_staff_not_allocated_office,
                           mock_fellows_not_allocated_office,
                           mock_unallocated_people, mock_staff, mock_fellows,
                           mock_livingspaces, mock_offices):
        mock_livingspaces.__iter__.return_value = ['python']
        mock_offices.__iter__.return_value = ['oculus', 'mordor']
        mock_fellows.__iter__.return_value = ['Migwi']
        mock_staff.__iter__.return_value = ['jojo', 'jimbo']
        mock_staff_not_allocated_office.__iter__.return_value = ['jimbo']
        mock_fellows_not_allocated_office.__iter__.return_value = []
        mock_unallocated_people.__iter__.return_value = []

        create_db('elsis.db')
        msg = self.person.commit_people('elsis.db')
        self.assertEqual(msg, 'Person data commit successfull')

    @patch.dict('app.room.Room.total_rooms', {
        'oculus': [1],
        'mordor': [2],
        'python': [1]
    })
    @patch.dict('app.person.Person.total_people', {
        1: 'Migwi',
        2: 'jojo',
        3: 'jimbo'
    })
    @patch('app.room.Room.offices')
    @patch('app.room.Room.livingspaces')
    @patch('app.person.Person.fellows')
    @patch('app.person.Person.staff')
    @patch('app.person.Person.unallocated_people')
    @patch('app.person.Person.fellows_not_allocated_office')
    @patch('app.person.Person.staff_not_allocated_office')
    def test_load_people(self, mock_staff_not_allocated_office,
                         mock_fellows_not_allocated_office,
                         mock_unallocated_people, mock_staff, mock_fellows,
                         mock_livingspaces, mock_offices):
        mock_livingspaces.__iter__.return_value = ['python']
        mock_offices.__iter__.return_value = ['oculus', 'mordor']
        mock_fellows.__iter__.return_value = ['Migwi']
        mock_staff.__iter__.return_value = ['jojo', 'jimbo']
        mock_staff_not_allocated_office.__iter__.return_value = ['jimbo']
        mock_fellows_not_allocated_office.__iter__.return_value = []
        mock_unallocated_people.__iter__.return_value = []

        msg = self.person.load_people('elsis.db')
        self.assertEqual(msg, 'People loaded successfully')