def seed_db(): """ Seed the database """ db.session.add(User(username="******", email="*****@*****.**")) db.session.add(User(username="******", email='*****@*****.**')) db.session.commit()
def test_add_user_duplicate_email(self): user = User(username='******', email='*****@*****.**', password='******') db.session.add(user) db.session.commit() duplicate_user = User(username='******', email='*****@*****.**', password='******') db.session.add(duplicate_user) self.assertRaises(IntegrityError, db.session.commit)
def seed_db(): """Seeds the database.""" db.session.add( User(username='******', email='*****@*****.**', password='******')) db.session.add( User(username='******', email='*****@*****.**', password='******')) db.session.commit()
def test_encode_auth_token(self): user = add_user(username='******', email='*****@*****.**', password='******') auth_token = user.encode_auth_token(user.id) self.assertTrue(isinstance(auth_token, bytes)) self.assertEqual(User.decode_auth_token(auth_token), user.id)
def test_add_user(self): user = User(username='******', email='*****@*****.**', password='******') db.session.add(user) db.session.commit() self.assertTrue(user.id) self.assertEqual(user.username, 'justatest') self.assertEqual(user.email, '*****@*****.**') self.assertTrue(user.active) self.assertTrue(user.password)
def home(): if request.method == 'POST': username = request.form.get('username') user = User.query.filter_by(username=username).first() if not user: user = User(username=username) db.session.add(user) db.session.commit() session['id'] = user.id return redirect('/') user = current_user() if user: clients = OAuth2Client.query.filter_by(user_id=user.id).all() else: clients = [] return render_template('home.html', user=user, clients=clients)
def add_user(username, email): user = User(username=username, email=email) db.session.add(user) db.session.commit() return user