def test_allocate_to_new_staff_space(self):
		office = Office("staff"+"Foin")
		staff = Staff("staff"+"Neritus", "staff"+"Otieno", "0784334537")
		result = len(allocations)
		office.allocate_to(staff)
		result_1 = len(allocations)
		self.assertEqual(result+1, result_1)
Exemple #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))
	def test_allocate_to_new_fellow_space(self):
		office = Office("staff"+"Foin")
		fellow = Fellow("staff"+"Neritus", "staff"+"Otieno", "0788934537", "Y")
		result = len(allocations)
		office.allocate_to(fellow)
		result_1 = len(allocations)
		self.assertEqual(result+1, result_1)
	def test_allocate_to_staff_no_space(self):
		office = Office("staff"+'Focusp')
		with self.assertRaises(ValueError):
			x = 0
			while (x <= 5):
				suffix = str(x)
				staff = Staff("staff"+"Neris"+suffix, "staff"+"Oten"+suffix, "078433448"+suffix,"N")
				office.allocate_to(staff)
				x += 1
	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])
Exemple #6
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))
 def test_print_populated_room(self):
     self.clear_stores()
     office = Office("NDO")
     Dojo.add_room(office)
     fellow = Fellow("Xone", "Ndobile", "0856443334", "y")
     fellow.register()
     office.allocate_to(fellow)
     allocations = office.allocations()
     output = Room.members(allocations)
     self.assertEqual(output, " 0856443334, NDOBILE, XONE, FELLOW\n")
 def test_print_existing_allocations_to_screen(self):
     self.clear_stores()
     office = Office("NDO2")
     Dojo.add_room(office)
     fellow = Fellow("Xone2", "Ndobile2", "0856443324", "y")
     fellow.register()
     office.allocate_to(fellow)
     allocations_ = Room.all_allocations()
     output = Room.members(allocations_, room_tag=True)
     expected_output = " NDO2-OFFICE, 0856443324, NDOBILE2, XONE2, FELLOW\n"
     self.assertEqual(output, expected_output)
Exemple #9
0
	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 test_arrogate_from_existing_staff(self):
		office = Office("staff"+'Focs')
		staff = Staff("staff"+"Erits", "staff"+"Teno", "0785534224", "Y")
		office.allocate_to(staff)
		allocated_1 = office.has_allocation(staff)
		office.arrogate_from(staff)
		allocated_2 = office.has_allocation(staff)
		self.assertEqual([allocated_1, allocated_2], [True, False])
 def test_print_existing_allocations_to_default_file(self):
     self.clear_stores()
     office = Office("ND2")
     Dojo.add_room(office)
     fellow = Fellow("Xne2", "Ndoile2", "0868443324", "y")
     fellow.register()
     office.allocate_to(fellow)
     allocations_ = Room.all_allocations()
     expected_output = Room.members(allocations_, room_tag=True)
     Room.to_file(expected_output)
     path = "output/"
     f = open(path + "File.txt", "r")
     output = f.read()  #"NDO2-Office, 0856443324, NDOBILE2, XONE2, FELLOW"
     f.close()
     self.assertEqual(expected_output, output)
 def test_print_existing_allocations_to_specific_file(self):
     self.clear_stores()
     office = Office("ND88")
     Dojo.add_room(office)
     fellow = Fellow("Xne88", "Ndoile88", "086800000", "y")
     fellow.register()
     office.allocate_to(fellow)
     allocations_ = Room.all_allocations()
     expected_output = Room.members(allocations_, room_tag=True)
     file_name = office.name + "-Allocations"
     Room.to_file(expected_output, file_name)
     path = "output/"
     f = open(path + file_name + ".txt", "r")
     output = f.read()
     f.close()
     self.assertEqual(expected_output, output)
Exemple #13
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")
Exemple #14
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))
Exemple #15
0
 def test_add_existing_room(self):
     room = Office("yc")
     Dojo.add_room(room)
     initial_room_count = Dojo.room_count()
     initial_found_state = Dojo.has_room(room)
     with self.assertRaises(ValueError):
         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, initial_found_state])
	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])
Exemple #17
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))
 def test_print_existing_unallocated_to_screen(self):
     self.clear_stores()
     office = Office("NDO4")
     Dojo.add_room(office)
     fellow = Fellow("Xone4", "Ndobile4", "0856443354", "y")
     fellow.register()
     office.allocate_to(fellow)
     fellow = Fellow("Xone5", "Ndobile6", "0856443009", "n")
     fellow.register()
     office.allocate_to(fellow)
     fellow = Fellow("Xone3", "Ndobile3", "0856443344", "y")
     fellow.register()
     output = Room.all_unallocated_persons()
     expected_output = "0856443344, NDOBILE3, XONE3, FELLOW\n"
     self.assertEqual(output, expected_output)
	def test_add_an_existing_office(self):
		office = Office('MyOffice4545')
		Office.add(office)
		with self.assertRaises(ValueError):
			Office.add(office)
	def test_allocate_to_existing_staff_space(self):
		office = Office("staff"+"Focuspo")
		staff = Staff("staff"+"Nerits", "staff"+"Oteno", "0784334222", "N")
		office.allocate_to(staff)
		with self.assertRaises(ValueError):
			office.allocate_to(staff)
	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_isinstance_of_room(self):
		office = Office("staff"+'Focuspoint')
		self.assertIsInstance(office, Room)
	def test_notinstance_of_LivingSpace(self):
		office = Office("staff"+'Mkuru')
		self.assertNotIsInstance(office, LivingSpace)
Exemple #24
0
 def test_has_room(self):
     room = Office("x")
     x = Dojo.has_room(room)
     Dojo.add_room(room)
     y = Dojo.has_room(room)
     self.assertEqual([x, y], [False, True])
Exemple #25
0
    def reallocate(cls, person, room):
        #Check if room user is allocating to has the allocation or is lacking capacity
        if room.has_allocation(person):
            raise ValueError(
                "%s-%s is already in %s-%s" %
                (person.phone, person.last_name, room.name, room.type_))
        if room.has_capacity() is False:
            raise ValueError("Sorry %s is at capacity" % room.name)
        #Get all current allocations to the given person
        current_allocations = []
        allocated_phones = cls.all_allocated_phones()
        if person.phone in allocated_phones:
            for allocation in allocations:
                phone = allocation[2]
                if phone == person.phone:
                    current_allocations.append(allocation)
        """Fellow or Staff allocated to Office or LivingSpace

				if person is Fellow and person has allocation to office alone:
					if destined room type is office:
						allow reallocation from office
					if destined room type is LivingSpace:
						allow allocation to LivingSpace
				if person is Fellow and person has allocation to livingspace alone:
					if destined room type is office:
						allow allocation to office
					if destined room type is LivingSpace:
						allow reallocation from LivingSpace
				if person is Staff and has allocation to office alone:
					allow reallocation from office
		"""
        """Fellow allocated to Office and LivingSpace

				if person is Fellow and person has allocation to both office and livingspace:
					if destined room type is office:
						allow reallocation from office
					if destined room type is LivingSpace:
						allow reallocation from LivingSpace
		"""

        if len(current_allocations) > 0:
            if len(current_allocations) is 1:
                allocation = current_allocations[0]
                allocated_type = allocation[1]
                allocated_name = allocation[0]
                if person.type_ is "FELLOW":
                    if allocated_type == room.type_:
                        if room.type_ == "LIVINGSPACE":
                            #if person is Fellow and person has allocation to livingspace alone and destined room type is LivingSpace
                            from app.models.livingspace import LivingSpace
                            old = LivingSpace.from_name(allocated_name)
                            old.arrogate_from(person)
                            room.allocate_to(person)
                            return "The %s: %s %s has been successfully reallocated to the %s: %s" % (
                                person.type_, person.first_name,
                                person.last_name, room.type_, room.name)
                        elif room.type_ == "OFFICE":
                            #if person is Fellow and person has allocation to office alone and destined room type is office
                            from app.models.office import Office
                            old = Office.from_name(allocated_name)
                            old.arrogate_from(person)
                            room.allocate_to(person)
                            return "The %s: %s %s has been successfully reallocated to the %s: %s" % (
                                person.type_, person.first_name,
                                person.last_name, room.type_, room.name)
                        else:
                            raise ValueError(
                                "Data in Invalid State. Room type other than LivingSpace and Office allocated."
                            )
                    else:
                        #if person is Fellow and person has allocation to either livingspace or office alone and destined room type is the opposite
                        if person.type_ == "STAFF":
                            raise ValueError(
                                "Cannot reallocate staff to livingspace.")
                        room.allocate_to(person)
                        print("%s-%s reallocated to %s-%s" %
                              (person.last_name, person.type_, room.name,
                               room.type_))
                elif person.type_ == "STAFF":
                    if allocated_type == room.type_:
                        if room.type_ == "OFFICE":
                            #if person is Staff and has allocation to office alone
                            from app.models.office import Office
                            old = Office.from_name(allocated_name)
                            old.arrogate_from(person)
                            room.allocate_to(person)
                            return "%s-%s reallocated to %s-%s" % (
                                person.last_name, person.type_, room.name,
                                room.type_)
                        else:
                            raise ValueError(
                                "Cannot reallocate staff to livingspace.")
                    else:
                        raise ValueError(
                            "Staff may only be allocated to offices. Allocated room type and destined room type to dont match."
                        )
            elif len(current_allocations) is 2:
                allocation1 = current_allocations[0]
                allocated_type1 = allocation1[1]
                allocated_name1 = allocation1[0]
                allocation2 = current_allocations[1]
                allocated_type2 = allocation2[1]
                allocated_name2 = allocation2[0]
                if person.type_ == "FELLOW":
                    if allocated_type1 == room.type_:
                        if room.type_ == "LIVINGSPACE":
                            #if person is Fellow and person has allocation to both office and livingspace and destined room type is LivingSpace
                            from app.models.livingspace import LivingSpace
                            old = LivingSpace.from_name(allocated_name1)
                            old.arrogate_from(person)
                            room.allocate_to(person)
                            return "The %s: %s %s has been successfully reallocated to the %s: %s" % (
                                person.type_, person.first_name,
                                person.last_name, room.type_, room.name)
                        elif room.type_ == "OFFICE":
                            #if person is Fellow and person has allocation to both office and livingspace and destined room type is office
                            from app.models.office import Office
                            old = Office.from_name(allocated_name1)
                            old.arrogate_from(person)
                            room.allocate_to(person)
                            return "The %s: %s %s has been successfully reallocated to the %s: %s" % (
                                person.type_, person.first_name,
                                person.last_name, room.type_, room.name)
                        else:
                            raise ValueError(
                                "Data in Invalid State. Room type other than LivingSpace and Office allocated"
                            )
                    elif allocated_type2 == room.type_:
                        if room.type_ == "LIVINGSPACE":
                            #if person is Fellow and person has allocation to both office and livingspace and destined room type is LivingSpace
                            from app.models.livingspace import LivingSpace
                            old = LivingSpace.from_name(allocated_name2)
                            old.arrogate_from(person)
                            room.allocate_to(person)
                            return "The %s: %s %s has been successfully reallocated to the %s: %s" % (
                                person.type_, person.first_name,
                                person.last_name, room.type_, room.name)
                        elif room.type_ == "OFFICE":
                            #if person is Fellow and person has allocation to both office and livingspace and destined room type is office
                            from app.models.office import Office
                            old = Office.from_name(allocated_name2)
                            old.arrogate_from(person)
                            room.allocate_to(person)
                            return "The %s: %s %s has been successfully reallocated to the %s: %s" % (
                                person.type_, person.first_name,
                                person.last_name, room.type_, room.name)
                        else:
                            raise ValueError(
                                "Data in Invalid State. Room type other than LivingSpace and Office allocated"
                            )
                    else:
                        raise ValueError(
                            "Data in Invalid State. Allocated room type and destined room type to dont match"
                        )
                else:
                    raise ValueError(
                        "Data in Invalid State. A non fellow cannot have more than one allocation"
                    )
            else:
                raise ValueError(
                    "Data in Invalid State. Person can have no more than 2 allocations"
                )
        else:
            if room.type_ == "LIVINGSPACE":
                if person.type_ == "STAFF":
                    raise ValueError("Cannot reallocate staff to livingspace.")
                room.allocate_to(person)
                return "The %s: %s %s has been successfully reallocated to the %s: %s" % (
                    person.type_, person.first_name, person.last_name,
                    room.type_, room.name)
            elif room.type_ == "OFFICE":
                room.allocate_to(person)
                return "The %s: %s %s has been successfully reallocated to the %s: %s" % (
                    person.type_, person.first_name, person.last_name,
                    room.type_, room.name)