def test_office_load_state(self): path = "db/" file_name = "mydb" file_ = file_name+".db" #clean up to avoid conflict between tests os.remove(path+file_) self.clear_stores() #memory office1 = Office('ooskks9') Office.add(office1) Office.save_state(file_name) #db engine = create_engine("sqlite:///"+path+file_, echo=False) Session = sessionmaker(bind=engine) session = Session() db_office = session.query(Room).filter_by(roomname='ooskks9'.upper()).first() #clear memory stores self.clear_stores() #memory Office.load_state(file_name) office = Office.from_name('ooskks9') #compare full_office = [office.name, office.capacity, office.type_] full_db_office = [db_office.roomname, db_office.roomcapacity, db_office.roomtype] session.close() self.assertEqual(full_db_office, full_office)
def create_room(room_name, room_type): try: room_input_index = 0 while room_input_index < len(room_name): room_type_curr = room_type[room_input_index].upper() room_name_curr = room_name[room_input_index].upper() if room_type_curr == "LIVINGSPACE": livingspace = LivingSpace(room_name_curr) LivingSpace.add(livingspace) print_pretty( " A living space called %s has been successfully created." % livingspace.name) elif room_type_curr == "OFFICE": office = Office(room_name_curr) Office.add(office) print_pretty( " An office called %s has been successfully created." % office.name) else: print_pretty( " The specified room type %s, is currently not supported." % room_type_curr) room_input_index += 1 except Exception as e: print_pretty(str(e))
def test_add_office(self): office = Office('MyOffice78') initial_room_count = len(Dojo.rooms()) initial_office_count = len(Office.rooms()) Office.add(office) new_room_count = len(Dojo.rooms()) new_office_count = len(Office.rooms()) self.assertEqual([initial_room_count+1, initial_office_count+1], [new_room_count, new_office_count])
def test_remove_office(self): office = Office('MyOffice89') Office.add(office) initial_room_count = len(Dojo.rooms()) initial_office_count = len(Office.rooms()) Office.remove(office) new_room_count = len(Dojo.rooms()) new_office_count = len(Office.rooms()) self.assertEqual([initial_room_count-1, initial_office_count-1], [new_room_count, new_office_count])
def test_available_office(self): result = Office.available() office = Office('MyO55e89') Office.add(office) staff = Staff("staff"+"Njsiritus", "staff"+"Otsdeno", "0700000537") office.allocate_to(staff) staff = Staff("staff"+"Njsiritus", "staff"+"Otsdeno", "0700001537") office.allocate_to(staff) result_2 = Office.available() staff = Staff("staff"+"Njsiritus", "staff"+"Otsdeno", "0700002537") office.allocate_to(staff) staff = Staff("staff"+"Njsiritus", "staff"+"Otsdeno", "0700003537") office.allocate_to(staff) result_3 = Office.available() self.assertTrue([result, result_3, type(result_2)], [False, False, "set"])
def test_add_an_existing_office(self): office = Office('MyOffice4545') Office.add(office) with self.assertRaises(ValueError): Office.add(office)