def test_staff(): from models import Staff Staff(first_name='Tony', last_name='Stark', email='*****@*****.**', password='******', gender='M', full_access=True).save() Staff(first_name='Pepper', last_name='Potts', email='*****@*****.**', password='******', gender='F').save() Staff(first_name='Morgan', last_name='Stark', email='*****@*****.**', password='******', gender='F', accessible_courses=[]).save() # TODO add a nonempty `accessible_couress` test case pass clean_up()
def seed_staff(): """ Adds client staff to the database. """ # Create seeds for staff. staff = [ Staff( id=1, username='******', avatar_url=( 'https://github.com/appcypher/experiments/blob/master/images/' 'staff-1.jpg?raw=true')), Staff( id=2, username='******', avatar_url=( 'https://github.com/appcypher/experiments/blob/master/images/' 'staff-2.jpg?raw=true')), Staff( id=3, username='******', avatar_url=( 'https://github.com/appcypher/experiments/blob/master/images/' 'staff-3.jpg?raw=true')), ] # Save to the database. db.session.add_all(staff) db.session.commit()
def fillup_db(): DB['rooms'].append(Room(42, 1, 'closed', 1000)) DB['rooms'].append(Room(7, 1, 'available', 50)) DB['rooms'].append(Room(69, 7, 'available', 9000)) DB['rooms'].append(Room(11, 3, 'closed', 10)) DB['tenants'].append(Tenant('Neo', 'zz0101', 33, 'M', { "city": "Zeon", "street": "Street 255" }, 42)) DB['tenants'].append(Tenant('Janis', 'bb2222', 40, 'W', { "city": "Los Angeles", "street": "Beverly Hills, 90210" }, 7)) DB['tenants'].append(Tenant('Sherlock', 'cc3333', 51, 'M', { "city": "London", "street": "Bakerstreet, 221B" }, 11)) DB['staff'].append(Staff('Taylor', 'aa1111', 'waiter', 100)) DB['staff'].append(Staff('Hannibal', 'et0000', 'cook', 1000)) DB['staff'].append(Staff('Hilton', 'ad1234', 'Administrator', 9000))
def multiple_valid_staff_models(initialize_db): """ A fixture for creating a multiple valid staff. Args: initialize_db (None): initializes the database and drops tables when test function finishes. """ staff = [ Staff(username='******', avatar_url='').save(), Staff(username='******', avatar_url='').save(), Staff(username='******', avatar_url='').save(), ] return staff
def setUp(self): print('\r') # drop all tables in the database db.session.remove() db.drop_all() # crete all tables in the database db.create_all() # adding users user = User(email='*****@*****.**', encrypted_password=encrypt('password'), name='staff') staff = Staff(user) db.session.add(staff) user = User(email='*****@*****.**', encrypted_password=encrypt('password'), name='john_doe') student = Student(user, 'U1722') db.session.add(student) # adding quizzes qz = Quiz(1, 'quiz', True, '2020-03-21', '2020-03-22') db.session.add(qz) # adding quizattempts qa = initializeQuizAttempt(2, 1, 100) db.session.add(qa) db.session.commit()
def setUp(self): print('\r') # drop all tables in the database db.session.remove() db.drop_all() # crete all tables in the database db.create_all() # adding users user = User(email='*****@*****.**', encrypted_password=encrypt('password'), name='john_doe') staff = Staff(user) db.session.add(staff) # adding courses course = Course(index='cz3003') db.session.add(course) # adding quizzes quiz = Quiz( staff_id=1, name="Quiz Test", is_fast=True, date_start='2020-03-01', date_end='2020-03-31', ) db.session.add(quiz) db.session.commit()
def setUp(self): print('\r') # drop all tables in the database db.session.remove() db.drop_all() # crete all tables in the database db.create_all() # adding users user_1 = User('*****@*****.**', encrypt('password'), 'student_1') student_1 = Student(user_1, 'U00000000A') db.session.add(student_1) user_2 = User('*****@*****.**', encrypt('password'), 'student_2') student_2 = Student(user_2, 'U00000000B') db.session.add(student_2) user_3 = User('*****@*****.**', encrypt('password'), 'teacher_1') staff_1 = Staff(user_3) db.session.add(staff_1) # adding topics topic = Topic(name='seng') db.session.add(topic) # adding lessons lesson = Lesson(1, 1, 'lesson_1', 'content') db.session.add(lesson) # adding quizzes quiz = Quiz(3, 'quiz_1', True, '2020-03-30', '2020-03-31') db.session.add(quiz) db.session.commit()
def save(self): """ Save registration forms data into User and Staff. If any save operation fails, the others will be rolled back. @return: User instance """ data = self.cleaned_data try: user = User(username=data['username']) user.email = data['email'] user.set_password(data['password']) user.first_name = data['firstname'] user.last_name = data['lastname'] user.is_active = True user.save() if data['team']: try: g = get_object_or_404(Group, pk=data['team']) user.groups.add(g) except: pass try: staff = Staff(user=user) staff.gender = data['gender'] staff.role = data['role'] staff.save() return user except Exception, e: logger.error('RegisterForm.save():%s' % e) user.delete() raise e except Exception, e: logger.error('RegisterForm.save():%s' % e) raise e
def register(): """Registers the user.""" if g.customer: return redirect(url_for('timeline')) error = None if request.method == 'POST': if g.owner: if not request.form['theUsername']: error = 'You have to enter a username' elif not request.form['password']: error = 'You have to enter a password' elif request.form['password'] != request.form['password2']: error = 'The two passwords do not match' elif get_staff_id(request.form['theUsername']) is not None: error = 'The username is already taken' else: db.session.add(Staff(request.form['theUsername'], generate_password_hash(request.form['password']))) db.session.commit() flash('You were successfully registered and can login now') return redirect(url_for('login')) else: if not request.form['theUsername']: error = 'You have to enter a username' elif not request.form['password']: error = 'You have to enter a password' elif request.form['password'] != request.form['password2']: error = 'The two passwords do not match' elif get_customer_id(request.form['theUsername']) is not None: error = 'The username is already taken' else: db.session.add(Customer(request.form['theUsername'], generate_password_hash(request.form['password']))) db.session.commit() flash('You were successfully registered and can login now') return redirect(url_for('login')) return render_template('register.html', error=error)
def setUp(self): print('\r') # drop all tables in the database db.session.remove() db.drop_all() # crete all tables in the database db.create_all() # adding topics topic = Topic(name='seng') db.session.add(topic) # adding lessons lesson = Lesson(topic_id=1, id=1, name='se', content='test') db.session.add(lesson) # adding users user = User('*****@*****.**', encrypt('password'), 'staff_name') staff = Staff(user) db.session.add(staff) # adding quizzes quiz = Quiz(1, 'quiz_name', True, '2020-03-21', '2020-03-22') db.session.add(quiz) db.session.commit()
def new_staff(): if request.method == "GET": if Staff.query.filter(Staff.username.like(session.get("logged_in")), Staff.admin.like(1)).scalar() is None: flash("You do not have permission to access that page.") return redirect(url_for("default")) return render_template("new_staff.html") elif request.method == "POST": if not re.match(r"[^@]+@[^@]+\.[^@]+", request.form["email"]): flash("Please enter a valid email address.") return redirect(url_for('new_staff')) elif Staff.query.filter_by( username=request.form["username"]).scalar() is not None: flash("There's already a staff member with that username.") return redirect(url_for('new_staff')) elif Staff.query.filter_by( email=request.form["email"]).scalar() is not None: flash("There's already a staff member with that email.") return redirect(url_for('new_staff')) newStaff = Staff(firstname=request.form["firstname"], lastname=request.form["lastname"], username=request.form["username"], password=request.form["password"], email=request.form["email"], admin=False) db.session.add(newStaff) try: db.session.commit() flash("{}'s profile was successfully created.".format( request.form["firstname"])) return redirect(url_for('new_staff')) except exc.SQLAlchemyError: flash("There was a problem adding the staff member.") return redirect(url_for('new_staff'))
def setUp(self): print('\r') # drop all tables in the database db.session.remove() db.drop_all() # crete all tables in the database db.create_all() # adding courses course = Course(index='cz3003') db.session.add(course) # adding users user = User(email='*****@*****.**', encrypted_password=encrypt('password'), name='staff') staff = Staff(user) db.session.add(staff) # adding quizzes qz = Quiz(1, 'quiz', True, '2020-03-21', '2020-03-22') db.session.add(qz) # adding RsQuizCourseAssign rs = initializeRsQuizCourseAssign(1, 'cz3003') db.session.add(rs) db.session.commit()
def staffer_account(): if request.method=="POST": s = Staff(username=request.form["username"], password=request.form["password"]) db.session.add(s) db.session.commit() flash("The new staff account is created!") return redirect(url_for("owner")) session['logged_in'] = True return render_template("staffer_account.html")
def valid_staff_model(initialize_db): """ A fixture for creating a valid staff model. Args: initialize_db (None): initializes the database and drops tables when test function finishes. """ return Staff(username='******', avatar_url='').save()
def newstaff(): if request.method == 'POST': new_staff = Staff(username=request.form['username'], password=request.form['password']) db.session.add(new_staff) db.session.commit() flash('New staff account created successfully!') return redirect(url_for('owner')) session['logged_in'] = True return render_template('create_new_account.html')
def create_rab(): if db.session.query(Roles).filter_by( id_role=current_user.id_role).first().name != "Менеджер": return 'What are you doing here?' if request.method == 'GET': return render_template('create_rab.html', role=db.session.query(Roles).filter_by( id_role=current_user.id_role).first().name) if request.method == 'POST': cipher = Salsa20.new(key=secret) fio = request.form['fio'] created = time.strftime('%d/%m/%Y', time.localtime()) # использовать дату dob = request.form['dob'] if request.form['role'] == 'Стажер': role = 1 id_position = 0 elif request.form['role'] == 'Продавец-консультант': role = 1 id_position = 1 elif request.form['role'] == 'Менеджер': role = 2 id_position = 2 email = request.form['email'] phone = request.form['phone'] company = request.form['company'] hash_password = generate_password_hash(request.form['password']) hash_address = request.form['address'] hash_card = str(cipher.nonce + cipher.encrypt(bytes(request.form['card'], 'utf-8'))) amount = request.form['amount'] new_Client = Clients(email=email, fio=fio, created=created, dob=dob, id_role=role) db.session.add(new_Client) db.session.commit() new_Contactdetailsclients = Contactdetailsclients( id_clients=new_Client.id_clients, phone=phone, company=company) new_Secretdate = Secretdate(id_clients=new_Client.id_clients, hash_password=hash_password, hash_address=hash_address) new_Card = Card(id_clients=new_Client.id_clients, hash_card=hash_card, amount=amount) new_Staff = Staff(id_staff=new_Client.id_clients, id_position=id_position) db.session.add(new_Contactdetailsclients) db.session.add(new_Secretdate) db.session.add(new_Card) db.session.add(new_Staff) db.session.commit() return redirect('/login')
def _processstaffrows(self, rows): staffs = [] entries = rows.entry for entry in entries: staff = Staff() staff.staffid = processstr(entry, 'staffid') staff.staffname = processstr(entry, 'staffname') staff.staffrole = processstr(entry, 'staffrole') staff.staffdescription = processstr(entry, 'staffdescription') staff.staffemail = processstr(entry, 'staffemail') staffs.append(staff) return staffs
def post(self): data = data_valid_for('POST') logging.debug(data) staff_already_exist = list( filter(lambda t: data['passport_id'] == t.passport_id, DB['staff'])) if not staff_already_exist: DB['staff'].append(Staff(**data)) new_passport_id = str(DB['staff'][-1].passport_id) location = {"Location": f'/api/v0.1/staff/{new_passport_id}'} return {"message": "staff was added successfully"}, 201, location msg = f"staff with passport_id {data['passport_id']} already exists" return {"message": msg}, 400
def initdb_command(): """Creates the database tables.""" db.drop_all() db.create_all() owner = Staff(firstname="Katie", lastname="Pucci", username="******", password="******", email="*****@*****.**", admin=True) db.session.add(owner) db.session.commit() print('Initialized the database.')
def put(self, bank_id, branch_id): """API Endpoint for adding staff to a branch instance """ args = _staff_create_parser.parse_args() bank = Bank.query.get_or_404(bank_id) branch = BankBranch.query.filter_by(bank=bank, id=branch_id).first_or_404() user = User.query.get_or_404(args['user_id']) staff = Staff(branch=branch, user=user, role=args['role']) user.staff = staff db.session.add(staff) db.session.commit() return json_serialize(staff)
def post(self, request): user = User.objects.create_user(username=request.POST['username'], email=request.POST['email'], password=request.POST['password']) obj = Staff() obj.firstname = request.POST['username'] obj.email = request.POST['email'] obj.password = request.POST['password'] obj.user = user obj.save() return HttpResponse() StaffLoginView
def get_context(self, id=None): form_cls = model_form(Staff) if id: query = Staff.select() staff = get_object_or_404(query, Staff.id == id) if request.method == 'POST': form = form_cls(request.form, intial=staff.bio) else: form = form_cls(obj=staff) else: staff = Staff() form = form_cls(request.form) context = {'staff': staff, 'form': form, 'create': id is None} return context
def setUp(self): print('\r') # drop all tables in the database db.session.remove() db.drop_all() # crete all tables in the database db.create_all() # adding users user = User(email='*****@*****.**', encrypted_password=encrypt('password'), name='john_doe') staff = Staff(user) db.session.add(staff) db.session.commit()
def manage(): error = None if "owner_id" not in session: abort(401) if request.method == "POST": error = validate_staff_input(request.form) if error == None: staff = Staff(request.form["username"], generate_password_hash(request.form["password"])) db.session.add(staff) db.session.commit() flash("Added new staff " + staff.username + " successfully!") reqs = EventRequest.query.order_by(EventRequest.start_datetime.asc()).all() owner = Owner.query.filter_by(owner_id=session["owner_id"]).first() staffings = {} staff = Staff.query.all() return render_template("manage.html", requests=reqs, staff=staff, staffings=staffings, user_name=owner.username, error=error)
def setUp(self): print('\r') # drop all tables in the database db.session.remove() db.drop_all() # crete all tables in the database db.create_all() # adding users user = User(email='*****@*****.**', encrypted_password=encrypt('password'), name='john_doe') student = Student(user, 'U1722') db.session.add(student) user = User(email='*****@*****.**', encrypted_password=encrypt('password'), name='staff') staff = Staff(user) db.session.add(staff) # adding topics topic = Topic(name='seng') db.session.add(topic) # adding lessons lesson = Lesson(topic_id='1', id='3', name='se', content='test') db.session.add(lesson) # adding questions qn = Question('1', '3', 'easy') db.session.add(qn) # adding quizzes qz = Quiz(2, 'quiz', True, '2020-03-21', '2020-03-22' ) # staff id is 2 here, as it uses the fk of users table db.session.add(qz) # adding courses course = Course(index='cz3003') db.session.add(course) db.session.commit()
def setUp(self): print('\r') # drop all tables in the database db.session.remove() db.drop_all() # crete all tables in the database db.create_all() # addingusers user = User(email='*****@*****.**', encrypted_password=encrypt('password'), name='john_doe') staff = Staff(user) db.session.add(staff) # adding courses course = Course(index='cz3003') db.session.add(course) # adding quizzes quiz = Quiz( staff_id=1, name="Quiz Test", is_fast=True, date_start='2020-03-01', date_end='2020-03-31', ) db.session.add(quiz) # adding topics topic = Topic(name='seng') db.session.add(topic) # adding lessons lesson = Lesson(topic_id='1', id='3', name='se', content='test') db.session.add(lesson) # adding questions qn = Question('1', '3', 'easy') db.session.add(qn) db.session.commit()
def add_staff(): if session['id'] is None or session['id'] != 'owner': abort(401) if request.form['name'] and request.form['password']: sameID = get_user_id(request.form['name']) if sameID is not None: fullStaff = Staff.query.filter_by(staff_id=sameID).first() if check_password_hash(fullStaff.pw_hash, request.form['password']): flash('Staff member with same name and password already exist') return redirect(url_for('owner_page')) newStaff = Staff(request.form['name'], generate_password_hash(request.form['password'])) db.session.add(newStaff) db.session.commit() flash('New Staff account successfully created') else: flash('Both name and password fields must be filled') return redirect(url_for('owner_page'))
def test_staffUpdate(self): # create a new Staff object and add it to the database user = User(email='*****@*****.**', encrypted_password=encrypt('password'), name='staff') stf = Staff(user=user) db.session.add(stf) db.session.commit() # update value of Staff object stf.name = 'Justin' staffUpdate() # fetch updated Staff object from the database stf = Staff.query.filter_by(email='*****@*****.**').first() # check if value of Staff object has been updated print('--- check if value of Staff object has been updated') self.assertEqual('Justin', stf.name)
def test_staffRead(self): # create a new Staff object and add it to the database user = User(email='*****@*****.**', encrypted_password=encrypt('password'), name='staff') stf = Staff(user=user) db.session.add(stf) db.session.commit() # check that the record retrieved is correct (using col='email') print( '--- check that the record retrieved is correct (using col=\'email\')' ) self.assertTrue(staffRead('email', '*****@*****.**')) # check that the record retrieved is correct (using col='id') print( '--- check that the record retrieved is correct (using col=\'id\')' ) self.assertTrue(staffRead('id', 1))
def adduser(): if session["logged_in_name"] != "admin": flash("You are not authorized to perform this action.") return redirect(url_for('main')) username = request.form['username'] password = request.form['password'] f_name = request.form['f_name'] l_name = request.form['l_name'] phone = request.form['phone'] phone = re.sub(r"\D", "", phone) # Remove non-digit characters email = request.form['emailaddress'] if not f_name or not l_name or not phone or not username or not password or not email: flash('All fields are required. Please try again.') return redirect(url_for('admin')) else: try: if len(phone) != 10: flash('Phone number must include area code. Please try again.') return redirect(url_for('admin')) int(phone) # Confirms that phone is an integer except: flash('Phone number must include area code. Please try again.') return redirect(url_for('admin')) if Staff.query.filter( or_(Staff.username == username, Staff.emailaddress == email)).all(): flash('Username or email address is already used.') return redirect(url_for('admin')) staff = Staff(username=username, password=password, f_name=f_name, l_name=l_name, phonenumber=phone, emailaddress=email) db.session.add(staff) db.session.commit() flash('New entry was successfully posted!') return redirect(url_for('admin'))