예제 #1
0
 def setUp(self):
     """Pre-test activities."""
     app.testing = True
     app.config['STRIPE_SECRET_KEY'] = 'foo'
     app.config['STRIPE_PUBLIC_KEY'] = 'bar'
     app.config['SITE_NAME'] = 'www.foo.com'
     app.config['STRIPE_SECRET_KEY'] = 'foo'
     app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///:memory:'
     app.config['WTF_CSRF_ENABLED'] = False
     app.config['FILE_DIRECTORY'] = os.path.abspath(
         os.path.join(os.path.split(os.path.abspath(__file__))[0], 'files'))
     with app.app_context():
         db.init_app(current_app)
         db.metadata.create_all(db.engine)
         mail.init_app(current_app)
         bcrypt.init_app(current_app)
         self.db = db
         self.app = app.test_client()
         self.purchase_uuid = str(uuid.uuid4())
         product = Product(name='Test Product',
                           file_name='test.txt',
                           price=5.01)
         purchase = Purchase(product=product,
                             email='*****@*****.**',
                             uuid=self.purchase_uuid,
                             sold_at=datetime.datetime(
                                 2014, 1, 1, 12, 12, 12))
         user = User(email='*****@*****.**',
                     password=bcrypt.generate_password_hash('password'))
         db.session.add(product)
         db.session.add(purchase)
         db.session.add(user)
         db.session.commit()
예제 #2
0
def main():
    """Main entry point for script."""
    with app.app_context():
        db.metadata.create_all(db.engine)
        if User.query.all():
            print 'A user already exists! Create another? (y/n):',
            create = raw_input()
            if create == 'n':
                return
        
        print 'Enter email address: ',
        email = raw_input()
        password = getpass()
        assert password == getpass('Password (again):')

        user = User(email=email, password=bcrypt.generate_password_hash(password))
        db.session.add(user)
        db.session.commit()
        print 'User added.'