def do_load_people(self, arg): ''' Usage: load_people <filename>''' file_name = arg["<filename>"] if os.path.exists(file_name): Dojo.load_people(file_name) else: print("File not found")
def test_create_ls(self): previous_room_count = len(Dojo.all_rooms) self.assertFalse('zebaki' in Dojo.all_rooms) Dojo.create_room('livingspace', 'zebaki') self.assertTrue('zebaki'.upper() in Dojo.all_rooms) new_room_count = len(Dojo.all_rooms) self.assertEqual(previous_room_count + 1, new_room_count)
def test_create_office(self): previous_room_count = len(Dojo.all_rooms) self.assertFalse('saturn' in Dojo.all_rooms) Dojo.create_room('office', 'saturn') self.assertTrue('saturn'.upper() in Dojo.all_rooms) new_room_count = len(Dojo.all_rooms) self.assertEqual(previous_room_count + 1, new_room_count)
def test_reallocate_person(self): Dojo.create_room('livingspace', 'oregon') Dojo.create_room('office', 'makel') Dojo.add_person('joel', 'kanye', 'F', 'Y') self.assertIn('joel kanye', Dojo.living_space_rooms['oregon']) Dojo.create_room('GO', 'l') Dojo.reallocate_person_to_ls('Hesbon Laban', 'hela') self.assertIn('Hesbon Laban', Dojo.living_space_rooms['hela']) self.assertNotIn('Hesbon Laban', Dojo.living_space_rooms['oregon'])
def do_add_person(self, arg): '''Usage: add_person <firstname> <lastname> <position> [--wants_accomodation=N] ''' first_name = arg["<firstname>"] last_name = arg["<lastname>"] pos = arg["<position>"] wants_accomodation = arg["--wants_accomodation"] Dojo.add_person(first_name, last_name, pos.upper(), str(wants_accomodation))
def test_add_fellow(self): Dojo.create_room('MARS', 'O') previous_fellow_count = len(Dojo.fellows) self.assertFalse('AMBA MAY' in Dojo.all_people) Dojo.add_person('amba', 'may', 'F') self.assertTrue('AMBA MAY' in Dojo.all_people) current_fellow_count = len(Dojo.fellows) self.assertEqual(previous_fellow_count + 1, current_fellow_count, 'Person fellow has not been added')
def test_add_person_staff(self): Dojo.create_room('MARS', 'O') previous_staff_count = len(Dojo.staffs) self.assertFalse('MARK ZUCK' in Dojo.all_people) Dojo.add_person('MARK', 'ZUCK', 'S') self.assertTrue('MARK ZUCK' in Dojo.all_people) current_staff_count = len(Dojo.staffs) self.assertEqual(previous_staff_count + 1, current_staff_count, 'Person staff has not been added')
def test_load_people_read_lines(self): dirname = os.path.dirname(os.path.realpath(__file__)) with mock.patch.object(Dojo, 'add_person') as mock_method: Dojo.load_people(os.path.join(dirname, 'dojo.txt')) mock_method.assert_any_call(firstname='OLUWAFEMI', lastname='SULE', position='F', wants_accomodation='Y') mock_method.assert_any_call(firstname='LEIGH', lastname='RILEY', position='S', wants_accomodation='N') self.assertEqual(mock_method.call_count, 7)
def do_reallocate_person(self, arg): ''' Usage: reallocate_person <firstname> <lastname> <new_room_name>''' first_name = arg["<firstname>"] last_name = arg["<lastname>"] full_name = first_name + " " + last_name new_room = arg["<new_room_name>"] if new_room.upper() in Dojo.office_rooms: Dojo.reallocate_person_to_office(full_name.upper(), new_room.upper()) elif new_room.upper() in Dojo.ls_rooms: Dojo.reallocate_person_to_ls(full_name.upper(), new_room.upper()) else: print('%s is not a room in Dojo' % new_room)
class TestAddPerson(unittest.TestCase): def setUp(self): self.instance_dojo = Dojo() def test_add_Fellow(self): number_at_start = len(self.instance_dojo.list_of_fellows) self.instance_dojo.add_person('sammy', 'fellow') number_after_add = len(self.instance_dojo.list_of_fellows) self.assertEqual(number_after_add, number_at_start + 1) def test_add_person(self): number_at_start = len(self.instance_dojo.list_of_staff) self.instance_dojo.add_person('sammy', 'staff') number_after_add = len(self.instance_dojo.list_of_staff) self.assertEqual(number_after_add, number_at_start + 1)
class TestCreateRoom(unittest.TestCase): def setUp(self): self.instance_dojo = Dojo() # check if office is created def test_create_office(self): no_on_start = len(self.instance_dojo.list_of_offices) self.instance_dojo.create_room('blue', 'office') no_after_creation = len(self.instance_dojo.list_of_offices) self.assertEqual(no_after_creation, no_on_start + 1) # add living Space def test_create_living(self): no_on_start = len(self.instance_dojo.list_of_living_space) self.instance_dojo.create_room('yellow', 'living') no_after_creation = len(self.instance_dojo.list_of_living_space) self.assertEqual(no_after_creation, no_on_start + 1)
def do_print_allocations(self, arg): '''Usage: print_allocations [--o=filename] ''' filename = arg["--o"] Dojo.print_allocations(filename)
def do_print_room(self, arg): ''' Usage: print_room <room_name>''' room_name = arg["<room_name>"] Dojo.print_room(room_name)
def setUp(self): self.instance_dojo = Dojo()
def test_does_not_reallocate_to_a_full_ls_room(self): Dojo.create_room('livingspace', 'oregon') Dojo.create_room('office', 'makel') previous_count = len(Dojo.living_space_rooms['oregon']) Dojo.add_person('hellen', 'degenerez', 'F', 'Y') Dojo.add_person('viona', 'awuor', 'F', 'Y') Dojo.add_person('patrice', 'leah', 'F', 'Y') Dojo.add_person('okindo', 'omutuka', 'F', 'Y') current_count = len(Dojo.living_space_rooms['oregon']) self.assertEqual(previous_count + 4, current_count) Dojo.create_room('livingspace', 'oregon') Dojo.add_person('anderson', 'masese', 'F', 'Y') response = Dojo.reallocate_person_to_ls('anderson masese', 'oregon') self.assertEqual(response, 'OREGON is already full')
def test_room_does_not_exist(self): Dojo.create_room('office', 'zebaki') self.assertTrue('venus' in Dojo.all_rooms) response = Dojo.create_room('office', 'venus') self.assertEqual(response, "Room already exists")
def do_create_room(self, arg): '''Usage: create_room <room_type> <room_name>...''' room_name = arg["<room_name>"] room_type = arg["<room_type>"] Dojo.create_room(room_type, room_name)
class Dojo_Interface(cmd.Cmd): launch() prompt = 'Dojo->>' dojo_space = Dojo() @docopt_cmd def do_create_room(self, arg): """Usage: create_room <room_type> <room_names> """ roomtype = arg["<room_type>"] roomnames = ''.join(arg["<room_names>"]).split(',') for roomname in roomnames: self.dojo_space.create_room(roomtype, roomname) @docopt_cmd def do_add_person(self, arg): """Usage: add_person <person_name> <email_address> <role> [<wants_accomodation>]""" name = arg["<person_name>"] email_address = arg["<email_address>"] role = arg["<role>"] accomodation_option = arg["<wants_accomodation>"] if role.upper() == "STAFF" and accomodation_option == "y": print(text_format.CRED + "\nWARNING! Staff cannot be allocated accomodation space\n" + text_format.CEND) return self.dojo_space.add_person(name, email_address, role, accomodation_option) @docopt_cmd def do_print_room(self, arg): """Usage: print_room <room_name>""" roomname = arg["<room_name>"] print(self.dojo_space.print_room(roomname)) @docopt_cmd def do_print_allocations(self, arg): """Usage: print_allocations [--o=filename]""" filename = arg["--o"] print(self.dojo_space.print_allocations(filename)) @docopt_cmd def do_print_unallocated(self, arg): """Usage: print_unallocated [--o=filename]""" filename = arg["--o"] print(self.dojo_space.print_unallocated(filename)) @docopt_cmd def do_load_people(self, arg): """Usage: load_people <filename>""" file_name = arg["<filename>"] print(self.dojo_space.load_people(file_name)) @docopt_cmd def do_reallocate_person(self, arg): """Usage: reallocate_person <emailaddress> <new_roomname>""" email = arg["<emailaddress>"] new_room = arg["<new_roomname>"] print(self.dojo_space.reallocate_person(email, new_room)) @docopt_cmd def do_save_state(self, arg): """Usage: save_state <database_name>""" db_name = arg["<database_name>"] print(self.dojo_space.save_state(db_name)) @docopt_cmd def do_load_state(self, arg): """Usage: load_state <database_name>""" db_name = arg["<database_name>"] print(self.dojo_space.load_state(db_name)) def do_quit(self, arg): """Quits interactive mode""" print('...soon I shall become a memory waiting to be erased') print('... Goodbye!') exit()
def test_return_random_ls_room(self): Dojo.create_room('livingspace', 'zebaki') Dojo.create_room('livingspace', 'pluto') random_ls = Dojo.generate_random_living_space() self.assertIn(random_ls, Dojo.living_space_rooms)
class TestDojoClass(TestCase): def setUp(self): self.my_dojo = Dojo() def test_successfully_create_room(self): initial_room_count = self.my_dojo.total_number_of_rooms sanctuary = self.my_dojo.create_room('Sanctuary', 'office') self.assertTrue(sanctuary, msg='Sanctuary room was not created successfully') new_room_count = self.my_dojo.total_number_of_rooms self.assertEqual(new_room_count - initial_room_count, 1, msg='Inaccurate Number of rooms') def test_valid_room_type(self): invalid_room_type = self.my_dojo.create_room('war room', 'bathroom') self.assertEqual(invalid_room_type, ' Enter a valid room type!', msg='Permits invalid room types to be created') self.assertIn(' Enter a valid room type e.g. Office, Living space', self.my_dojo.create_multiple_rooms('pantry', 'one', 'two')) def test_valid_input_for_create_room(self): with self.assertRaises(TypeError): self.my_dojo.create_room('Sanctuary', 5) def test_successfully_add_person(self): self.my_dojo.create_room('command center', 'office') initial_people_count = len(self.my_dojo.list_of_people) self.my_dojo.add_person('John', 'Staff') new_people_count = len(self.my_dojo.list_of_people) self.assertEqual(new_people_count - initial_people_count, 1, msg='Inaccurate number of people') def test_successfully_allocate_living_space(self): self.my_dojo.create_room('penthouse', 'living space') self.my_dojo.create_room('command center', 'office') self.assertIn('penthouse', self.my_dojo.living_spaces.keys()) self.assertIn('command center', self.my_dojo.office_spaces.keys()) initial_num_of_occupants = len(self.my_dojo.living_spaces['penthouse'].occupants) self.my_dojo.add_person('kimberly', 'fellow', True) new_num_of_occupants = len(self.my_dojo.living_spaces['penthouse'].occupants) self.assertEqual(new_num_of_occupants - initial_num_of_occupants, 1, msg='Inaccurate number of occupants in ' 'room') def test_successfully_allocate_office_space(self): self.my_dojo.create_room('command center', 'office') self.my_dojo.create_room('cozy space', 'living space') initial_num_of_occupants = len(self.my_dojo.office_spaces['command center'].occupants) self.my_dojo.add_person('tinky winky', 'fellow') self.my_dojo.add_person('dipsy', ' staff') final_num_of_occupants = len(self.my_dojo.office_spaces['command center'].occupants) new_assignees = final_num_of_occupants - initial_num_of_occupants self.assertEqual(new_assignees, 2, msg='Inaccurate number of occupants. Expected 2!') self.assertEqual(self.my_dojo.office_spaces['command center'].occupants, ['tinky winky', 'dipsy'], msg='{} != ' '[\'tinky winky\', \'dipsy\']'.format( self.my_dojo.office_spaces['command center'].occupants)) def test_successfully_create_multiple_rooms(self): initial_room_count = self.my_dojo.number_of_offices self.my_dojo.create_multiple_rooms('office', 'War room', 'kitchen') final_room_count = self.my_dojo.number_of_offices num_of_new_offices = final_room_count - initial_room_count self.assertEqual(num_of_new_offices, 2, msg='Inaccurate number of offices') def test_successfully_add_multiple_people(self): self.my_dojo.create_multiple_rooms('office', 'War room', 'kitchen') initial_staff_count = self.my_dojo.total_number_of_staff self.my_dojo.add_multiple_people('staff', 'Harry', 'Hermione', 'Voldermort') final_staff_count = self.my_dojo.total_number_of_staff num_of_new_staff = final_staff_count - initial_staff_count self.assertEqual(num_of_new_staff, 3, msg='Inaccurate number of new staff') def test_rejects_duplicate_rooms(self): self.my_dojo.create_room('ops center', 'office') self.assertEqual(self.my_dojo.create_room('ops center', 'office'), ' A room called ops center already exists!\n', msg='Does not detect duplicate room entry') def test_print_room(self): self.my_dojo.create_room('ops center', 'office') self.my_dojo.add_person('Wolverine', 'staff') occupant_list = self.my_dojo.print_room('ops center') self.assertEqual(1, len(occupant_list), msg='Incorrect number of occupants') self.assertEqual(['Wolverine'], occupant_list, msg='Wolverine not in list of occupants') def test_fellow_unallocated_living_space(self): self.my_dojo.create_room('main office', 'office') self.my_dojo.add_person('Professor X', 'fellow') self.assertEqual('', self.my_dojo.list_of_fellows['Professor X'].living_space_assigned) self.assertIn('There are no rooms of type living spaces!', self.my_dojo.add_person('Storm', 'fellow', True)) self.assertIn('Storm', self.my_dojo.unallocated_people) def test_duplicate_name(self): self.my_dojo.add_person('Cyclops', 'staff') self.assertIn('A person with this name already exists', self.my_dojo.add_person('Cyclops', 'fellow'), msg='Duplicate name permitted!') def test_valid_person_position_check(self): self.assertIn('Enter a valid position e.g. Fellow, Staff', self.my_dojo.add_person('Magneto', 'villain'), msg='Invalid position permitted') self.assertIn('Enter a valid position e.g. Staff, Fellow', self.my_dojo.add_multiple_people('good guys', 'logan', 'mystique'), msg='Invalid position permitted') def test_no_office_spaces_with_free_space(self): self.my_dojo.create_room('home', 'office') self.my_dojo.add_multiple_people('staff', 'hulk', 'black panther', 'black widow', 'iron man', 'loki', 'thor') self.assertFalse(self.my_dojo.all_rooms['home'].has_free_space) self.assertIn('No offices with free space!', self.my_dojo.add_person('captain america', 'staff'), msg='No alert of no free office space') def test_no_living_spaces_with_free_space(self): self.my_dojo.create_room('home', 'office') self.my_dojo.create_room('penthouse', 'living space') self.my_dojo.add_person('the flash', 'fellow', True) self.my_dojo.add_person('arrow', 'fellow', True) self.my_dojo.add_person('aquaman', 'fellow', True) self.my_dojo.add_person('joker', 'fellow', True) self.assertFalse(self.my_dojo.all_rooms['penthouse'].has_free_space) self.assertIn('No living spaces with free space!', self.my_dojo.add_person('supergirl', 'fellow', True)) def test_print_unallocated(self): self.assertIn('Nobody is unallocated', self.my_dojo.print_unallocated()) self.my_dojo.add_person('Unallocated guy', 'staff') self.assertIsNone(self.my_dojo.print_unallocated()) def test_print_allocations(self): self.assertIn('No rooms have been created yet!', self.my_dojo.print_allocations()) self.my_dojo.create_room('main', 'office') self.my_dojo.add_person('Unallocated guy', 'staff') self.assertIsNone(self.my_dojo.print_allocations())
def setUp(self): self.the_dojo = Dojo()
class TestDojo(unittest.TestCase): def setUp(self): self.the_dojo = Dojo() # check if office is instance of room def test_office_is_instance_of_room(self): self.assertTrue(issubclass(Office, Room)) # check if living space is instance of room def test_livingspace_is_instance_of_room(self): self.assertTrue(issubclass(LivingSpace, Room)) # check if fellow is instance of person def test_fellow_is_instance_of_person(self): self.assertTrue(issubclass(Fellow, Person)) # check if staff is instance of person def test_staff_is_instance_of_person(self): self.assertTrue(issubclass(Staff, Person)) def test_create_room_invalid_room_entered(self): valhalla_lounge = self.the_dojo.create_room("LOUNGE", "VALHALLA") self.assertEqual(valhalla_lounge, 'You have entered an invalid room. Please enter office or Livingspace') # check if room is created def test_create_room_successfully(self): initial_office_count = len(self.the_dojo.dojo_offices) self.the_dojo.create_room("OFFICE", "KILIMANJARO") new_office_count = len(self.the_dojo.dojo_offices) self.assertEqual((new_office_count - initial_office_count), 1) # check if created toom is an instance of class Room def test_create_room_is_instance_of_class_room(self): Serengeti_office = self.the_dojo.create_room('OFFICE', 'SERENGETI') self.assertIsInstance(Serengeti_office, Room) # Test if maximum capacity of the office is 6 def test_create_room_max_capacity_of_office_is_six(self): Simba_office = self.the_dojo.create_room('OFFICE', 'SIMBA') max_number = Simba_office.max_people self.assertEqual(max_number, 6) # Test if maximum capacity of the living space is 4 def test_create_room_max_capacity_of_living_space_is_four(self): Nzoia_livingspace = self.the_dojo.create_room('LIVINGSPACE', 'NZOIA') max_number = Nzoia_livingspace.max_people self.assertEqual(max_number, 4) def test_create_room_with_same_name_as_another_room(self): self.the_dojo.dojo_offices['RED'] = [] number_of_rooms = len(self.the_dojo.dojo_offices) self.the_dojo.create_room('OFFICE', 'RED') new_number_of_rooms = len(self.the_dojo.dojo_offices) self.assertEqual(number_of_rooms, new_number_of_rooms) # check if person is added def test_add_person_is_added(self): new_person = self.the_dojo.add_person('ANDREW', 'STAFF', 'N') self.assertTrue(new_person) def test_add_person_office_is_allocated_automatically(self): self.the_dojo.dojo_offices['RED'] = [] number_of_people = len(self.the_dojo.dojo_offices['RED'] ) self.the_dojo.add_person('LILIAN', 'STAFF', 'N') new_number_of_people = len(self.the_dojo.dojo_offices['RED'] ) self.assertEqual((new_number_of_people - number_of_people),1) # check if room is allocated def test_add_person_room_is_allocated_to_staff(self): self.the_dojo.create_room('OFFICE', 'RED') initial_person_in_office_count = len(self.the_dojo.dojo_offices['RED']) self.the_dojo.add_person('CHARLES', 'STAFF','N') new_person_in_office_count = len(self.the_dojo.dojo_offices['RED']) self.assertEqual((new_person_in_office_count - initial_person_in_office_count), 1) # check if adding accomodation for staff returns an error def test_add_person_adding_accomodation_for_staff(self): self.the_dojo.create_room('LIVINGSPACE', 'RED') initial_person_in_living_space_count = len(self.the_dojo.dojo_livingspaces['RED']) self.the_dojo.add_person('WANJIKU', 'STAFF', 'Y') new_person_in_livingspace_count = len(self.the_dojo.dojo_livingspaces['RED']) self.assertEqual((new_person_in_livingspace_count-initial_person_in_living_space_count),0) def test_add_person_return_message_when_staff_is_allocated_livingspace(self): livingspace = self.the_dojo.create_room('LIVINGSPACE', 'RED') new_staff_member = self.the_dojo.add_person('WANJIKU', 'STAFF', 'Y') self.assertEqual(new_staff_member, 'Sorry there are no living spaces available for staff') def test_add_person_is_added_to_unallocated_if_no_rooms(self): unallocated_people = len(self.the_dojo.unallocated) self.the_dojo.add_person('CHRIS','FELLOW', 'Y') new_unallocated_people = len(self.the_dojo.unallocated) self.assertEqual((new_unallocated_people - unallocated_people),1) # add a staff member and check if type of person is staffperson def test_add_person_check_if_added_person_is_instance_staff(self): new_staff_member = self.the_dojo.add_person('BRENDA', 'STAFF', 'N') self.assertIsInstance(new_staff_member, Staff) # add fellow who wants accomodation. check if living space is allocated def test_add_person_if_living_space_is_allocated_for_fellow_who_wants_accommodation(self): livingspace = self.the_dojo.create_room('LIVINGSPACE', 'RED') self.the_dojo.create_room('OFFICE', 'BLUE') initial_person_in_living_space_count = len(self.the_dojo.dojo_livingspaces['RED']) new_fellow = self.the_dojo.add_person('MUNA', 'FELLOW', 'Y') new_person_in_livingspace_count = len(self.the_dojo.dojo_livingspaces['RED']) self.assertEqual((new_person_in_livingspace_count-initial_person_in_living_space_count),1) def test_rooms_allocation_for_available_rooms(self): self.the_dojo.dojo_livingspaces['RED'] = [] self.the_dojo.dojo_livingspaces['BLACK'] = [] available_rooms = self.the_dojo.rooms_allocation(self.the_dojo.dojo_livingspaces) self.assertListEqual(available_rooms, ['RED', 'BLACK']) def test_allocate_office_for_unallocated_person(self): unallocated_person = Fellow('JOHN DOE') self.the_dojo.unallocated[unallocated_person] = ['FELLOW','Needs office'] person_id = id(unallocated_person) self.the_dojo.create_room('OFFICE', 'RED') self.the_dojo.allocate_office(person_id, 'RED') self.assertIn(unallocated_person, self.the_dojo.dojo_offices['RED']) def test_print_room_with_no_people(self): self.the_dojo.create_room('OFFICE', 'RED') print_room = self.the_dojo.print_room('RED') self.assertEqual(print_room, 'THIS ROOM IS CURRENTLY EMPTY') def test_print_room_that_does_not_exist(self): print_room = self.the_dojo.print_room('BLACK') self.assertEqual(print_room, 'Sorry the room does not exist') def test_print_allocations_before_creating_rooms(self): print_allocations = self.the_dojo.print_allocations(None) self.assertEqual(print_allocations, 'There are currently no allocations') def test_print_allocations_without_filename(self): self.the_dojo.dojo_offices['RED'] = [] self.the_dojo.dojo_offices['WHITE'] = [] self.the_dojo.dojo_livingspaces['BLUE'] = [] self.the_dojo.load_people('sample.txt') print_allocations = self.the_dojo.print_allocations(None) self.assertEqual(print_allocations,'Successfully printed to the screen') def test_print_allocations_with_filename(self): self.the_dojo.dojo_offices['RED'] = [] self.the_dojo.dojo_offices['WHITE'] = [] self.the_dojo.dojo_livingspaces['BLUE'] = [] self.the_dojo.load_people('sample.txt') print_allocations = self.the_dojo.print_allocations('trial.txt') self.assertEqual(print_allocations,'Successfully printed to a txt file') def test_print_unallocated_before_adding_person(self): print_unallocated = self.the_dojo.print_unallocated(None) self.assertEqual(print_unallocated, 'There are no unallocated people') def test_print_unallocated_without_filename(self): self.the_dojo.add_person('BRENDA', 'STAFF', 'N') self.the_dojo.add_person('VIRGINIA', 'STAFF', 'N') print_unallocated = self.the_dojo.print_unallocated(None) self.assertEqual(print_unallocated, 'Successfuly printed to the screen') def test_print_unallocated_with_file_name(self): self.the_dojo.add_person('BRENDA', 'STAFF', 'N') self.the_dojo.add_person('VIRGINIA', 'STAFF', 'N') print_unallocated = self.the_dojo.print_unallocated('unallocated.txt') self.assertEqual(print_unallocated, 'Successfully printed to a txt file') def test_allocate_livingspace_for_unallocated_person(self): unallocated_person = Fellow('AWESOME PERSON') self.the_dojo.unallocated[unallocated_person] = ['FELLOW','Needs office', 'Needs Living space'] person_id = id(unallocated_person) self.the_dojo.create_room('LIVINGSPACE', 'WHITE') self.the_dojo.allocate_livingspace(person_id, 'WHITE') self.assertIn(unallocated_person, self.the_dojo.dojo_livingspaces['WHITE']) def test_reallocate_person_successful_message(self): new_person = Staff('STEVE JOBS') self.the_dojo.dojo_offices['BLUE'] = [new_person] self.the_dojo.dojo_offices['RED'] = [] person_id = id(new_person) self.the_dojo.reallocate_person(person_id, 'RED', 'OFFICE') def test_reallocate_person_from_office_to_office(self): new_person = Staff('CHARLES ODUK') self.the_dojo.dojo_offices['BLUE'] = [new_person] self.the_dojo.dojo_offices['RED'] = [] person_id = id(new_person) self.the_dojo.reallocate_person(person_id, 'RED', 'OFFICE') self.assertIn(new_person,self.the_dojo.dojo_offices['RED']) def test_load_people_from_txt_file(self): self.the_dojo.dojo_offices['RED'] = [] self.the_dojo.dojo_offices['WHITE'] = [] self.the_dojo.dojo_livingspaces['BLUE'] = [] self.the_dojo.load_people('sample.txt') self.assertTrue((len(self.the_dojo.dojo_offices['RED']) > 0)) self.assertTrue((len(self.the_dojo.dojo_offices['WHITE']) > 0)) self.assertTrue((len(self.the_dojo.dojo_livingspaces['BLUE']) > 0)) def test_load_state_succesfully_loaded_state_message(self): result = self.the_dojo.load_state('default.db') self.assertEqual(result, 'You have successfully loaded the previously saved state!!!') def test_load_state_previously_saved_state(self): number_of_offices = len(self.the_dojo.dojo_offices) self.the_dojo.load_state('default.db') new_number_of_offices = len(self.the_dojo.dojo_offices) self.assertTrue((new_number_of_offices - number_of_offices) > 0) def test_save_state_successful_message(self): self.the_dojo.load_state('default.db') result = self.the_dojo.save_state(None) self.assertEqual(result, 'Current state successfully saved!!')
def test_does_not_reallocate_to_a_full_office_room(self): Dojo.create_room('office', 'blue') previous_count = len(Dojo.office_rooms['blue']) Dojo.add_person('degenez', 'hellen', 'F') Dojo.add_person('viona', 'awuor', 'F') Dojo.add_person('patrice', 'leah', 'S') Dojo.add_person('okindo', 'omutka', 'F') Dojo.add_person('liza', 'muli', 'S') Dojo.add_person('justin', 'Mzonge', 'S') current_count = len(Dojo.office_rooms['blue']) self.assertEqual(previous_count + 6, current_count) Dojo.create_room('office', 'guantanamo') Dojo.add_person('anderson', 'masese', 'F') response = Dojo.reallocate_person_to_office('anderson masese', 'blue') self.assertEqual(response, 'BLUE is already full')
def do_print_unallocated(self, arg): '''Usage: print_unallocated [--o=filename] ''' filename = arg["--o"] Dojo.print_unallocated(filename)
def save_state_on_interrupt(): print("saving state...") Dojo.save_state()
dojo print_allocations [<-o=filename>] dojo print_unallocated [<print_unallocated>] dojo (-h | --help | --version) Options: -i, --interactive Interactive Mode -h, --help Show this screen and exit. """ import cmd import sys from docopt import docopt, DocoptExit from app.dojo import Dojo the_dojo = Dojo() def docopt_cmd(func): def fn(self, arg): try: opt = docopt(fn.__doc__, arg) except DocoptExit as e: # The DocoptExit is thrown when the args do not match. # We print a message to the user and the usage block. print('Invalid Command!') print(e) return except SystemExit: # The SystemExit exception prints the usage for --help # We do not need to do the print here.
def test_return_random_office_room(self): Dojo.create_room('office', 'blue') Dojo.create_room('office', 'green') random_office = Dojo.generate_random_office() self.assertIn(random_office, Dojo.office_rooms)
create_room :create a room of a certain type add_person :add a person to the system <room_type> :office or living <room_name> :enter a desired room name <name> :the name of the person <p_type> :indicate whether the person is staff or fellow [<accommodation>] : y or Y if the person wants accommodation, if not leave blank """ import sys import cmd from docopt import docopt, DocoptExit from app.dojo import Dojo new_dojo = Dojo() def docopt_cmd(func): """ This decorator is used to simplify the try/except block and pass the result of the docopt parsing to the called action. """ def fn(self, arg): try: opt = docopt(fn.__doc__, arg) except DocoptExit as e: # The DocoptExit is thrown when the args do not match. # We print a message to the user and the usage block.
def setUp(self): self.my_dojo = Dojo()
def test_does_reallocate_to_same_ls_room(self): Dojo.create_room('livingspace', 'oregon') Dojo.add_person('Mary', 'Mwenda', 'F', 'Y') response = Dojo.reallocate_person_to_ls('Mary Mwenda ', 'oregon') self.assertEqual(response, 'MARY MWENDA is already allocated to oregon')