Ejemplo n.º 1
0
 def test_livingspace_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('ojsdj89')
     LivingSpace.add(livingspace)
     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='ojsdj89'.upper()).first()
     #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.º 2
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.º 3
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.º 4
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.º 5
0
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))
Ejemplo n.º 6
0
 def test_add_new_room(self):
     room = LivingSpace("hl")
     initial_room_count = Dojo.room_count()
     initial_found_state = Dojo.has_room(room)
     Dojo.add_room(room)
     new_room_count = Dojo.room_count()
     new_found_state = Dojo.has_room(room)
     self.assertEqual([new_room_count, new_found_state],
                      [initial_room_count + 1, not initial_found_state])
Ejemplo n.º 7
0
def get_room(room_name):
    try:
        return LivingSpace.from_name(room_name)
    except ValueError:
        pass
    try:
        return Office.from_name(room_name)
    except ValueError:
        raise ValueError("specifed room is unknown")
Ejemplo n.º 8
0
 def test_remove_existing_room(self):
     room = LivingSpace("xd")
     Dojo.add_room(room)
     initial_room_count = Dojo.room_count()
     initial_found_state = Dojo.has_room(room)
     Dojo.remove_room(room)
     new_room_count = Dojo.room_count()
     new_found_state = Dojo.has_room(room)
     self.assertEqual([new_room_count, new_found_state],
                      [initial_room_count - 1, not initial_found_state])
Ejemplo n.º 9
0
def save_state(file_name="default"):
    file_name = str(file_name)
    path = "db/"
    file_ = file_name + ".db"
    try:
        if os.path.isfile(path + file_):
            os.remove(path + file_)
        Person.save_state(file_name)
        LivingSpace.save_state(file_name)
        Office.save_state(file_name)
        Allocation.save_state(file_name)
        print_pretty(
            "The current state of the application has successfully been saved in the db directory under the file: %s."
            % file_)
    except exc.DBAPIError:
        print_pretty(
            str("There is currently a problem with the specified file please try a different one."
                ))
    except Exception as e:
        print_pretty(str(e))
Ejemplo n.º 10
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.º 11
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.º 12
0
def load_state(file_name="default"):
    file_name = str(file_name)
    path = "db/"
    file_ = file_name + ".db"
    try:
        if os.path.isfile(path + file_):
            Person.load_state(file_name)
            LivingSpace.load_state(file_name)
            Office.load_state(file_name)
            Allocation.load_state(file_name)
            print_pretty(
                "The current state of the application has successfully been loaded from the file: %s under the directory db."
                % file_)
        else:
            raise Exception(
                "The specified db file (%s) does not exist under the db directory."
                % file_)
    except exc.DBAPIError:
        print_pretty(
            str("There is currently a problem with the specified file please try a different one."
                ))
    except Exception as e:
        print_pretty(str(e))
Ejemplo n.º 13
0
 def create_room(self, name, room_type):
     if room_type.lower() not in ['office', 'livingspace']:
         return (error('Only offices and livingspaces allowed!'))
     if not isinstance(name, str):
         return (error('Room names can only be strings!'))
     if name in self.all_rooms:
         return (error('Room %s exists!' % (name)))
     else:
         if room_type.lower() == 'office'.lower():
             # create an office
             self.room = Office(name)
             self.offices[name] = self.room.members
             self.all_rooms[name] = [room_type, self.room.members]
             return (success(
                 'An office called %s has been created successfully!' %
                 (name)))
         elif room_type.lower() == 'livingspace'.lower():
             # create a livingspace
             self.room = LivingSpace(name)
             self.livingspaces[name] = self.room.members
             self.all_rooms[name] = [room_type, self.room.members]
             return (success(
                 'A Livingspace called %s has been created successfully!' %
                 (name)))
Ejemplo n.º 14
0
	def test_print_empty_room(self):
		self.clear_stores()
		livingspace = LivingSpace("NDO1")
		with self.assertRaises(Exception):
			output = livingspace.allocations()
Ejemplo n.º 15
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])
Ejemplo n.º 16
0
 def test_creates_livingspace_instance(self):
     self.livingspace = LivingSpace('Amity')
     self.assertEqual(self.livingspace.capacity, 4)
     self.assertEqual(self.livingspace.members, [])