def test_get_current_time(self): user = User(name='tester', email='*****@*****.**', password='******') db.session.add(user) db.session.commit() last_created_time = user.created_time user.name = 'another_tester' db.session.add(user) db.session.commit() assert user.created_time == last_created_time
def setUp(self): super(TestSearch, self).setUp() for i in range(25): name = 'user%d' % i email = '*****@*****.**' % name user = User(name=name, email=email, password='******') db.session.add(user) db.session.commit()
def initdb(): """Init/reset database.""" db.drop_all() db.create_all() user = User(name='demo', email='*****@*****.**', password='******', website='', location='', bio='') db.session.add(user) db.session.commit()
def test_get_current_time(self): role_user = Role(name='user') user = User( name = 'demo', email = '*****@*****.**', password = '******', role = role_user, user_detail = UserDetail( real_name = u'Demo Guy', age = 10, url = u'http://demo.example.com', location = u'Hangzhou', bio = u'Demo Guy is ... hmm ... just a demo guy.' ), ) role_admin = Role(name='admin') admin = User( name = 'admin', email = '*****@*****.**', password = '******', role = role_admin, user_detail = UserDetail( real_name = u'Admin Guy', age = 20, url = u'http://admin.example.com', location = u'Mars', bio = u'Admin Guy is ... hmm ... just a admin guy.' ), ) db.session.add(user) db.session.add(admin) db.session.commit() assert User.query.count() == 2 assert Role.query.count() == 2 assert UserDetail.query.count() == 2 last_created_time = user.created_time user.name = 'another_tester' db.session.add(user) db.session.commit() assert user.created_time == last_created_time
def search(): keywords = request.args.get('keywords', '').strip() pagination = None if keywords: page = int(request.args.get('page', 1)) pagination = User.search(keywords).paginate(page, 1) else: flash(_('Please input keyword(s)'), 'error') return render_template('search.html', pagination=pagination, keywords=keywords)
def search(): keywords = request.args.get("keywords", "").strip() pagination = None if keywords: page = int(request.args.get("page", 1)) pagination = User.search(keywords).paginate(page, 1) else: flash(_("Please input keyword(s)"), "error") return render_template("search.html", pagination=pagination, keywords=keywords)
def test_follow_unfollow(self): user1 = User(name='tester1', email='*****@*****.**', password='******') db.session.add(user1) user2 = User(name='tester2', email='*****@*****.**', password='******') db.session.add(user2) db.session.commit() user1.follow(user2) assert user1.num_following == 1 assert user1.get_following_query().first().id == user2.id assert user2.num_followers == 1 assert user2.get_followers_query().first().id == user1.id user1.unfollow(user2) assert user1.num_following == 0 assert user2.num_followers == 0
def reauth(): form = ReauthForm(next=request.args.get("next")) if request.method == "POST": user, authenticated = User.authenticate(current_user.name, form.password.data) if user and authenticated: confirm_login() current_app.logger.debug("reauth: %s" % session["_fresh"]) flash(_("Reauthenticated."), "success") return redirect("/change_password") flash(_("Password is wrong."), "error") return render_template("reauth.html", form=form)
def reauth(): form = ReauthForm(next=request.args.get('next')) if request.method == 'POST': user, authenticated = User.authenticate(current_user.name, form.password.data) if user and authenticated: confirm_login() current_app.logger.debug('reauth: %s' % session['_fresh']) flash(_('Reauthenticated.'), 'success') return redirect('/change_password') flash(_('Password is wrong.'), 'error') return render_template('reauth.html', form=form)
def signup(): form = SignupForm(next=request.args.get('next')) if form.validate_on_submit(): user = User() form.populate_obj(user) db.session.add(user) db.session.commit() if login_user(user): return redirect(form.next.data or url_for('user.index')) return render_template('signup.html', form=form)
def login(): if current_user.is_authenticated(): return jsonify(flag='success') username = request.form.get('username') password = request.form.get('password') if username and password: user, authenticated = User.authenticate(username, password) if user and authenticated: if login_user(user, remember='y'): return jsonify(flag='success') current_app.logger.debug('login(api) failed, username: %s.' % username) return jsonify(flag='fail', msg='Sorry, try again.')
def login(): form = LoginForm(login=request.args.get("login", None), next=request.args.get("next", None)) if form.validate_on_submit(): user, authenticated = User.authenticate(form.login.data, form.password.data) if user and authenticated: remember = request.form.get("remember") == "y" if login_user(user, remember=remember): flash(_("Logged in"), "success") return redirect(form.next.data or url_for("user.index")) else: flash(_("Sorry, invalid login"), "error") return render_template("login.html", form=form)
def login(): form = LoginForm(login=request.args.get('login', None), next=request.args.get('next', None)) if form.validate_on_submit(): user, authenticated = User.authenticate(form.login.data, form.password.data) if user and authenticated: remember = request.form.get('remember') == 'y' if login_user(user, remember=remember): flash(_("Logged in"), 'success') return redirect(form.next.data or url_for('user.index')) else: flash(_('Sorry, invalid login'), 'error') return render_template('login.html', form=form)
def _make_user(self): user = User(name='tester', email='*****@*****.**', password='******') db.session.add(user) db.session.commit() assert user.id is not None self.user = user