Beispiel #1
0
	def test_staff_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
		staff1 = Staff("kdjsn", "ejsjssk", "40000412")
		staff1.register()
		Person.save_state(file_name)
		#db
		engine = create_engine("sqlite:///"+path+file_, echo=False)
		Session = sessionmaker(bind=engine)
		session = Session()
		db_staff = session.query(Person).filter_by(phonenumber="40000412").first()
		#clear memory stores
		self.clear_stores()
		#memory
		Person.load_state(file_name)
		staff = Staff.from_phone("40000412")
		#compare
		full_staff = [staff.first_name, staff.last_name, staff.phone, staff.type_, staff.opt_in]
		full_db_staff = [db_staff.firstname, db_staff.lastname, db_staff.phonenumber, db_staff.role, db_staff.optin]
		session.close()
		self.assertEqual(full_db_staff, full_staff)
Beispiel #2
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_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)
	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_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_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
Beispiel #7
0
def get_person(phone):
    try:
        return Fellow.from_phone(phone)
    except ValueError:
        pass
    try:
        return Staff.from_phone(phone)
    except ValueError:
        raise ValueError("specifed phone is unknown")
    def post(self):
        """
        Function that checks if the staff login was successful (checks for staff email and password) in case login is
        successful, a JWT Token is created and returned for that staff.

        :return: Response and a login boolean based on success of login, if successful it will return a token as well
        as the response.
        """
        try:
            data = api.payload
            # Checking if staff exists in database by email (defined as unique).
            if Staff.objects(email=data['email']):

                # Checking if the password match with the one hashed on the db.
                if password_encrypt.compare_passwords(
                        data['password'],
                        Staff.objects(email=data['email'])[0].password):

                    # Creating access token for staff
                    access_token = create_access_token(
                        expires_delta=timedelta(days=60),
                        identity=data['email'])
                    return make_response(
                        jsonify(message='Login Successful',
                                login=True,
                                access_token=access_token), 201)

                else:
                    return make_response(
                        jsonify(message='Password is wrong!', login=False),
                        401)

            else:
                return make_response(
                    jsonify(message='Staff does not exist', login=False), 401)

        except Exception as e:
            return make_response(
                jsonify(message='An error has occurred',
                        error=str(e),
                        login=False), 406)
Beispiel #9
0
	def build_staff(self):

		staff_data = self.db.cursor.execute('''SELECT * from staff
											ORDER BY firstname ASC''').fetchall()
		staff_list = []
		for staff in staff_data:
			s = Staff(staff)

			if s.name == 'Michael Atheros':
				staff_list = [s] + staff_list
			else:
				staff_list.append(s)

		return staff_list
    def post(self):
        """
        Function to add new staffs on the

        :return: Response based on success of add.
        """
        # Assigning API payload to variable
        data = api.payload

        # Encrypting plain password from request.
        data['password'] = password_encrypt.hash_password(data['password'])

        # Adding new register to database
        Staff(name=data['name'],
              email=data['email'],
              password=data['password'],
              isStaff=True).save()

        return make_response(jsonify(message='Successfully Registered'), 201)
 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()
	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_allocate_to_new_staff_space(self):
		livingspace = LivingSpace('Focus')
		staff = Staff("Neritus", "Otieno", "0784334123")
		with self.assertRaises(TypeError):
			result = livingspace.allocate_to(staff)