def test_email_must_be_unique(self): pw = self.bcrypt.generate_password_hash(self.test_password).decode('utf-8') u1 = User('Will Smith', '*****@*****.**', pw) u2 = User('Will Smith2', '*****@*****.**', pw) db.session.add(u1) db.session.add(u2) with self.assertRaises(IntegrityError): db.session.commit()
def test_id_not_repeated(self): pw = self.bcrypt.generate_password_hash(self.test_password).decode('utf-8') u1 = User('Will Smith', '*****@*****.**', pw) u2 = User('Johnny Depp', '*****@*****.**', pw) db.session.add(u1) db.session.add(u2) db.session.commit() q_u1 = User.query.get(u1.id) q_u2 = User.query.get(u2.id) self.assertFalse(q_u1.id == q_u2.id)
def test_email_value_null(self): pw = self.bcrypt.generate_password_hash(self.test_password).decode('utf-8') email = None u = User('Will Smith', email, pw) with self.assertRaises(IntegrityError): db.session.add(u) db.session.commit()
def test_password_hash_check(self): pw = self.bcrypt.generate_password_hash(self.test_password).decode('utf-8') u = User('Will Smith', '*****@*****.**', pw) db.session.add(u) db.session.commit() q_u = User.query.first() self.assertTrue(self.bcrypt.check_password_hash(q_u.password, self.test_password))
def test_email_value(self): pw = self.bcrypt.generate_password_hash(self.test_password).decode('utf-8') email = '*****@*****.**' u = User('Will Smith', email, pw) db.session.add(u) db.session.commit() self.assertTrue(u.email == email)
def test_username_value_null(self): pw = self.bcrypt.generate_password_hash(self.test_password).decode('utf-8') username = None u = User(username, '*****@*****.**', pw) with self.assertRaises(IntegrityError): db.session.add(u) db.session.commit()
def test_username_value(self): pw = self.bcrypt.generate_password_hash(self.test_password).decode('utf-8') username = '******' u = User(username, '*****@*****.**', pw) db.session.add(u) db.session.commit() self.assertTrue(u.username == username)
def setUp(self): self.app = create_app() self.app_context = self.app.app_context() self.app_context.push() self.bcrypt = Bcrypt(self.app) db.create_all() self.test_user = User( 'Will Smith', '*****@*****.**', self.bcrypt.generate_password_hash('testing123_$%').decode( 'utf-8')) db.session.add(self.test_user) db.session.commit() self.test_client = Client("Company X", '*****@*****.**', 'bio text goes here, bio text goes here', 1, '7176577957', self.test_user.id) db.session.add(self.test_client) db.session.commit() self.test_product = Product('Product-A', 'Product Desciption', self.test_client.id) db.session.add(self.test_product) db.session.commit() pa1 = ProductArea('Area1', self.test_product.id) pa2 = ProductArea('Area2', self.test_product.id) db.session.add(pa1) db.session.add(pa2) db.session.commit()
def test_user_clients(self): pw = self.bcrypt.generate_password_hash(self.test_password).decode('utf-8') u = User('Will Smith', '*****@*****.**', pw) db.session.add(u) db.session.commit() q_u = User.query.get(u.id) self.assertListEqual(q_u.clients, []) self.assertTrue(Client.query.filter_by(user_id=q_u.id).count() == 0)
def setUp(self): self.app = create_app() self.app_context = self.app.app_context() self.app_context.push() self.bcrypt = Bcrypt(self.app) db.create_all() self.test_user = User('Will Smith', '*****@*****.**', self.bcrypt.generate_password_hash('testing123_$%').decode('utf-8')) db.session.add(self.test_user) db.session.commit()
def signup(): if current_user.is_authenticated: return redirect(url_for('main.home')) form = SignupForm() if form.validate_on_submit(): hashed_password = bcrypt.generate_password_hash(form.password.data).decode('utf-8') user = User(form.username.data, form.email.data, hashed_password) db.session.add(user) db.session.commit() flash('An account for {} has been created! You can now login to your account'.format(form.username.data), 'success') return redirect(url_for('users.login')) return render_template('signup.html', form=form)
from datetime import datetime from feature_lab import create_app, db from flask_bcrypt import Bcrypt from feature_lab.models import User, Client, Product, ProductArea, FeatureRequest app = create_app() app.app_context().push() bcrypt = Bcrypt(app) db.drop_all() db.create_all() # create a user user = User('Rafat Assaf', '*****@*****.**', bcrypt.generate_password_hash('Testing123$')) db.session.add(user) db.session.commit() # create clients client_1 = Client('Kings Landing solutions', '*****@*****.**', 'Technical solutions across all of Westeros', '92387471989', user.id) client_2 = Client('Winterfell solutions', '*****@*****.**', 'Technical solutions across all of the world', '74897928191', user.id) db.session.add(client_1) db.session.add(client_2) db.session.commit()