Exemplo n.º 1
0
 def test_valid_login(self):
     tester=app.test_client(self)
     db.drop_all()
     db.create_all()
     hashed_password = bcrypt.generate_password_hash("123456")#.decode('utf-8')
     user = User(username="******", email="*****@*****.**", password=hashed_password)
     db.session.add(user)
     db.session.commit()
     response=tester.post('/home',data=dict(username="******",password='******'), follow_redirects=True)
     self.assertIn(b'Change Profile',response.data)
Exemplo n.º 2
0
    def test_redirection_to_profile_from_registration(self):
        with app.test_request_context():
            tester=app.test_client(self)
            db.drop_all()
            db.create_all()
            hashed_password = bcrypt.generate_password_hash("123456")#.decode('utf-8')
            user = User(username="******", email="*****@*****.**", password=hashed_password)
            db.session.add(user)
            db.session.commit()
            login_user(user)

            tester.post('/home',data=dict(username="******",password='******'), follow_redirects=True)
            response = tester.get('/registration',content_type='html/text', follow_redirects=True)
            self.assertIn(b'Change Profile', response.data)
Exemplo n.º 3
0
 def test_redirection_to_quote_if_profile_exists(self):
     with app.test_request_context():
         tester=app.test_client(self)
         db.drop_all()
         db.create_all()
         hashed_password = bcrypt.generate_password_hash("123456")#.decode('utf-8')
         user = User(username="******", email="*****@*****.**", password=hashed_password)
         db.session.add(user)
         db.session.commit()
         login_user(user)
         profile = Profile(name="bob", address1="Sample Drive", address2="", city="Houston",state="TX", zipcode="77777", user_id=current_user.id)
         db.session.add(profile)
         db.session.commit()
         response = tester.post('/home',data=dict(username="******",password='******'), follow_redirects=True)
         self.assertIn(b'Get Your Quote', response.data)
Exemplo n.º 4
0
def registration():
    if current_user.is_authenticated:
        checkProfile = Profile.query.filter_by(user_id=current_user.id).first()
        if checkProfile != None:
            return redirect(url_for('quote'))
        else:
            return redirect(url_for('profile'))
    form = registrationForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        user = User(username=form.username.data,
                    email=form.email.data,
                    password=hashed_password)
        db.session.add(user)
        db.session.commit()
        return redirect(url_for('home'))
    return render_template('register.html', title='Register', form=form)