Ejemplo n.º 1
0
 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])
Ejemplo n.º 2
0
 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()
Ejemplo n.º 3
0
 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)
Ejemplo n.º 4
0
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))
Ejemplo n.º 5
0
	def test_instantiate_room_from_name(self):
		livingspace  = LivingSpace('MyLLLLL')
		LivingSpace.add(livingspace)
		office = Office('MyJJJSS')
		Office.add(office)
		livingspace1 = LivingSpace.from_name("MyLLLLL")
		office1 = Office.from_name("MyJJJSS")
		self.assertEqual(office.name, office1.name)
Ejemplo n.º 6
0
	def test_reallocate_staff_to_livingspace(self):
		office = Office('M777848')
		Office.add(office)
		staff = Staff("jjjkkdsj", "liidsls", "0799034987")
		office.allocate_to(staff)
		livingspace1 = LivingSpace('U988934')
		LivingSpace.add(livingspace1)
		with self.assertRaises(Exception):
			Room.reallocate(staff, livingspace1)
Ejemplo n.º 7
0
	def test_reallocate_fellow_to_livingspace(self):
		livingspace  = LivingSpace('My9990')
		LivingSpace.add(livingspace)
		fellow = Fellow("jjjsj", "lksls", "07009987", "Y")
		livingspace.allocate_to(fellow)
		livingspace1  = LivingSpace('My9991')
		LivingSpace.add(livingspace1)
		Room.reallocate(fellow, livingspace1)
		self.assertEqual([livingspace1.has_allocation(fellow), livingspace.has_allocation(fellow)],
						 [True, False])