def test_allocate_to_new_fellow_space(self): livingspace = LivingSpace('Focuspoin') fellow = Fellow("Neritus", "Otieno", "0784334220", "Y") result = len(allocations) livingspace.allocate_to(fellow) result_1 = len(allocations) self.assertEqual(result+1, result_1)
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_arrogate_from_existing_fellow(self): livingspace = LivingSpace('Focs') fellow = Fellow("Erits", "Teno", "0785534224", "Y") livingspace.allocate_to(fellow) allocated_1 = livingspace.has_allocation(fellow) livingspace.arrogate_from(fellow) allocated_2 = livingspace.has_allocation(fellow) self.assertEqual([allocated_1, allocated_2], [True, False])
def test_allocate_to_fellow_no_space(self): livingspace = LivingSpace('Focusp') with self.assertRaises(ValueError): x = 0 while (x <= 7): suffix = str(x) fellow = Fellow("Neris"+suffix, "Oten"+suffix, "078433448"+suffix,"N") livingspace.allocate_to(fellow) x += 1
def add_person(first_name, last_name, phone, type_, opt_in="N"): try: type_ = type_.upper() if type_ == "FELLOW": fellow = Fellow(first_name, last_name, phone, opt_in) fellow.register() first_name = fellow.first_name last_name = fellow.last_name type_ = fellow.type_ available_offices = Office.available() if available_offices is False: print_pretty(" There are currently no available offices.") else: selection = random.choice(list(available_offices)) office = Office(selection) office.allocate_to(fellow) print_pretty( " The fellow: %s has been allocated to the office: %s." % (fellow.last_name, office.name)) if fellow.opt_in == "Y": available_livingspaces = LivingSpace.available() if available_livingspaces is False: print_pretty( " There are currently no available living spaces.") else: selection = random.choice(list(available_livingspaces)) livingspace = LivingSpace(selection) livingspace.allocate_to(fellow) print_pretty( " The fellow: %s has been allocated to the living space: %s." % (fellow.last_name, livingspace.name)) print_pretty(" A %s: %s %s has been successfully created." % (type_, first_name, last_name)) elif type_ == "STAFF": staff = Staff(first_name, last_name, phone, opt_in) staff.register() first_name = staff.first_name last_name = staff.last_name type_ = staff.type_ available_offices = Office.available() if available_offices is False: print_pretty(" There are currently no available offices.") else: selection = random.choice(list(available_offices)) office = Office(selection) office.allocate_to(staff) print_pretty( " The staff: %s has been allocated to the office: %s." % (staff.last_name, office.name)) print_pretty(" A %s: %s %s has been successfully created." % (type_, first_name, last_name)) else: print_pretty(" %s is currently not a supported role." % type_) #print(persons_detail) except Exception as e: print_pretty(str(e))
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_allocate_to_new_staff_space(self): livingspace = LivingSpace('Focus') staff = Staff("Neritus", "Otieno", "0784334123") with self.assertRaises(TypeError): result = livingspace.allocate_to(staff)
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_allocate_to_existing_fellow_space(self): livingspace = LivingSpace('Focuspo') fellow = Fellow("Nerits", "Oteno", "0784334222", "N") livingspace.allocate_to(fellow) with self.assertRaises(ValueError): livingspace.allocate_to(fellow)