def test_allocations_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 livingspace = LivingSpace('hwan') LivingSpace.add(livingspace) fellow = Fellow("onon", "ekek", "000009", "Y") fellow.register() livingspace.allocate_to(fellow) prev_allocations = Room.all_allocations().copy() Allocation.save_state(file_name) #clear memory stores self.clear_stores() empty_allocations = Room.all_allocations().copy() #db Allocation.load_state(file_name) loaded_allocations = Room.all_allocations().copy() #compare expected_output = ["HWAN", "LIVINGSPACE", "000009"] output = [prev_allocations[0], empty_allocations, loaded_allocations[0]] self.assertEqual(output, [expected_output, [], expected_output])
def test_livingspace_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 livingspace1 = LivingSpace('oju5nf89') LivingSpace.add(livingspace1) LivingSpace.save_state(file_name) #db engine = create_engine("sqlite:///"+path+file_, echo=False) Session = sessionmaker(bind=engine) session = Session() db_livingspace = session.query(Room).filter_by(roomname='oju5nf89'.upper()).first() #clear memory stores self.clear_stores() #memory LivingSpace.load_state(file_name) livingspace = LivingSpace.from_name('oju5nf89') #compare full_livingspace = [livingspace.name, livingspace.capacity, livingspace.type_] full_db_livingspace = [db_livingspace.roomname, db_livingspace.roomcapacity, db_livingspace.roomtype] session.close() self.assertEqual(full_db_livingspace, full_livingspace)
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_living_space(self): livingspace = LivingSpace('MySpace78') initial_room_count = len(Dojo.rooms()) initial_livingspace_count = len(LivingSpace.rooms()) LivingSpace.add(livingspace) new_room_count = len(Dojo.rooms()) new_livingspace_count = len(LivingSpace.rooms()) self.assertEqual([initial_room_count+1, initial_livingspace_count+1], [new_room_count, new_livingspace_count])
def test_remove_living_space(self): livingspace = LivingSpace('MySpace89') LivingSpace.add(livingspace) initial_room_count = len(Dojo.rooms()) initial_livingspace_count = len(LivingSpace.rooms()) LivingSpace.remove(livingspace) new_room_count = len(Dojo.rooms()) new_livingspace_count = len(LivingSpace.rooms()) self.assertEqual([initial_room_count-1, initial_livingspace_count-1], [new_room_count, new_livingspace_count])
def test_available_livingspace(self): result = LivingSpace.available() livingspace = LivingSpace('MyO55e80') LivingSpace.add(livingspace) fellow = Fellow("staff"+"Njsiritus", "staff"+"Otsdeno", "0700004537", "Y") livingspace.allocate_to(fellow) fellow = Fellow("staff"+"Njsiritus", "staff"+"Otsdeno", "0700005537", "Y") livingspace.allocate_to(fellow) fellow = Fellow("staff"+"Njsiritus", "staff"+"Otsdeno", "0700006537", "Y") livingspace.allocate_to(fellow) result_2 = LivingSpace.available() fellow = Fellow("staff"+"Njsiritus", "staff"+"Otsdeno", "0700007537", "Y") livingspace.allocate_to(fellow) fellow = Fellow("staff"+"Njsiritus", "staff"+"Otsdeno", "0700008537", "Y") livingspace.allocate_to(fellow) fellow = Fellow("staff"+"Njsiritus", "staff"+"Otsdeno", "0700009537", "Y") livingspace.allocate_to(fellow) result_3 = LivingSpace.available() self.assertTrue([result, result_3, type(result_2)], [False, False, "set"])
def test_allocations_save_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 livingspace = LivingSpace('hwan') LivingSpace.add(livingspace) fellow = Fellow("onon", "ekek", "000009", "Y") fellow.register() livingspace.allocate_to(fellow) Allocation.save_state(file_name) #db engine = create_engine("sqlite:///"+path+file_, echo=False) Session = sessionmaker(bind=engine) session = Session() db_allocation = session.query(Allocation).first() #compare db_output = [db_allocation.roomname, db_allocation.roomtype, db_allocation.phonenumber] self.assertEqual(Room.all_allocations()[0], db_output) session.close()
def test_add_an_existing_living_space(self): livingspace = LivingSpace('MySpace4545') LivingSpace.add(livingspace) with self.assertRaises(ValueError): LivingSpace.add(livingspace)