def add_admin(username, password): with app.app_context(): user = User() user.username = username user.password = generate_password_hash(password, method="sha256") user.admin_user = True user.insert()
def test_successful_login(self): user = User() user.username = test_user2['username'] user.set_hash(test_user2['password']) user.admin_user = True user.insert() self.driver.get(self.url) self.driver.find_element_by_id("username").send_keys( test_user2['username']) self.driver.find_element_by_id("password").send_keys( test_user2['password']) self.driver.find_element_by_id("submit").click() time.sleep(3) self.assertEqual(self.driver.current_url, 'http://localhost:8943/mock_app/')
def user_add(): """ **Adds a User** adds a user to database. """ context = base_context() if request.method == "POST": username = request.form["name"] password = request.form["password"] admin_user = request.form.get("admin_user") if admin_user == "True": admin_user = True else: admin_user = False has_user = db.session.query( exists().where(User.username == username)).scalar() if has_user is False: new_user = User() new_user.username = username new_user.admin_user = admin_user new_user.set_hash(password) for key in request.form: if key.startswith('role_'): roleid = key.split('_')[1] role = Role.query.get(roleid) new_user.roles.append(role) new_user.insert() return redirect(url_for('admin.user_add')) context['roles'] = Role.query.all() return render_template("admin/add.html", **context)