def test_it_prints_allocations(self): Amity.print_allocations('testfile') self.assertTrue(os.path.isfile('testfile.txt')) os.remove('testfile.txt')
def test_it_creates_office(self): amity = Amity() amity.create_room('o', 'Oculus') self.assertNotEqual(len(amity.all_rooms), 0) self.assertIn('OCULUS', Amity.office_spaces.keys()) amity.all_rooms = []
def test_it_saves_state(self): amity = Amity() amity.save_state('testdb') self.assertTrue(os.path.isfile('testdb.sqlite')) os.remove('testdb.sqlite')
def test_add_person(self): amity = Amity() amity.all_people = [] self.assertFalse('kironde' in amity.all_people) amity.add_person("kironde", "suubi", "F", "Y") self.assertNotEqual(len(Amity.all_people), 0)
def test_it_creates_living_area(self): amity = Amity() amity.create_room('l', 'Arduino') self.assertNotEqual(len(amity.all_rooms), 0) self.assertIn('ARDUINO', Amity.living_spaces.keys()) amity.all_rooms = []
class AmityInteractive(cmd.Cmd): intro() prompt = "Amity --> " file = None amity = Amity() @app_exec def do_create_room(self, arg): """Creates a new room Usage: create_room <room_type> <room_name>... """ names = arg["<room_name>"] room_type = arg["<room_type>"] if not len(names) or not room_type: print("Make sure you enter all details") elif room_type.upper() not in ["L", "O"]: print("Invalid room type entered. Use either O or L") else: for name in names: if not name.isalpha(): print("Room name can only contain alphabets. Try again") else: self.amity.create_room(room_type, name) @app_exec def do_add_person(self, arg): """ Adds a person and allocates rooms if available Usage: add_person <first_name> <last_name> <designation> [--wants_accommodation=N] """ first_name = arg["<first_name>"] last_name = arg["<last_name>"] designation = arg["<designation>"] wants_accommodation = arg["--wants_accommodation"] if not first_name.isalpha() or not last_name.isalpha(): print("Names can only contain alphabets.") elif designation.upper() not in ["F", "S"]: print("Invalid designation. Enter F or S") else: if not wants_accommodation: self.amity.add_person(first_name.upper(), last_name.upper(), designation.upper()) else: self.amity.add_person(first_name.upper(), last_name.upper(), designation.upper(), arg["--wants_accommodation"]) @app_exec def do_print_room(self, arg): """ Prints all the people in a given rooms Usage: print_room <room_name> """ Amity.print_room(arg["<room_name>"]) @app_exec def do_print_allocations(self, arg): """ Prints all rooms and the people in them. Usage: print_allocations [--o=filename] """ filename = arg["--o"] or "" self.amity.print_allocations(filename) @app_exec def do_print_unallocated(self, arg): """ Prints all the people that don't have relevant rooms Usage: print_unallocated [--o=filename] """ filename = arg["--o"] or "" self.amity.print_unallocated(filename) @app_exec def do_load_people(self, arg): """ Loads people from a text file to the app. Usage: load_people <filename> """ file_name = arg["<filename>"] if os.path.exists(file_name): self.amity.load_people(file_name) print("File loaded.") else: print("file does not exist") @app_exec def do_reallocate_person(self, arg): """ Reallocates person Usage: reallocate_person <first_name> <last_name> <room_type> <new_room> """ first_name = arg["<first_name>"] last_name = arg["<last_name>"] room_type = arg["<room_type>"] new_room = arg["<new_room>"] self.amity.reallocate_person(first_name, last_name, room_type, new_room) @app_exec def do_load_state(self, arg): """ Loads data from the specified db into the app. Usage: load_state <filename> """ self.amity.load_state(arg["<filename>"]) @app_exec def do_save_state(self, arg): """ Persists app data into the given db Usage: save_state [--db_name=sqlite_db] """ db = arg['--db_name'] if db: self.amity.save_state(db) else: self.amity.save_state() @app_exec def do_quit(self, arg): """ Exits the app. Usage: quit """ exit()
def do_print_room(self, arg): """ Prints all the people in a given rooms Usage: print_room <room_name> """ Amity.print_room(arg["<room_name>"])