Exemplo n.º 1
0
	def test_fellow_load_state(self):
		path = "db/"
		file_name = "mydb"
		file_ = file_name+".db"
		#clean up to avoid conflict between tests
		os.remove(path+file_)
		#clear memory stores
		self.clear_stores()
		#memory
		fellow1 = Fellow("osdflkjsd", "eksdlkfjk", "774881228", "Y")
		fellow1.register()
		Person.save_state(file_name)
		#clear memory stores
		self.clear_stores()
		#memory
		Person.load_state(file_name)
		fellow = Fellow.from_phone("774881228")
		#db
		engine = create_engine("sqlite:///"+path+file_, echo=False)
		Session = sessionmaker(bind=engine)
		session = Session()
		db_fellow = session.query(Person).filter_by(phonenumber="774881228").first()
		session.close()
		#compare
		full_fellow = [fellow.first_name, fellow.last_name, fellow.phone, fellow.type_, fellow.opt_in]
		full_db_fellow = [db_fellow.firstname, db_fellow.lastname, db_fellow.phonenumber, db_fellow.role, db_fellow.optin]
		self.assertEqual(full_db_fellow, full_fellow)
Exemplo n.º 2
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])
Exemplo n.º 3
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))
Exemplo n.º 4
0
 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")
Exemplo n.º 5
0
 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)
Exemplo n.º 6
0
 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)
Exemplo n.º 7
0
 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)
Exemplo n.º 8
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()
Exemplo n.º 9
0
 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)
Exemplo n.º 10
0
 def test_register_new_phone(self):
     fellow = Fellow("Standard", "SKIDH", "84900874855", "Y")
     initial_person_count = len(persons_detail)
     fellow.register()
     new_person_count = len(persons_detail)
     self.assertEqual(initial_person_count + 1, new_person_count)
Exemplo n.º 11
0
 def test_register_phone_exists_error(self):
     fellow = Fellow("LIOLZ", "SKIDH", "8483664855", "Y")
     fellow.register()
     fellow_1 = Staff("LIOLZ", "SKIDH", "8483664855", "Y")
     with self.assertRaises(ValueError):
         fellow_1.register()