def setUp(self): self.db_fd, app.config['DATABASE'] = tempfile.mkstemp() app.config.update( TESTING=True, SQLALCHEMY_DATABASE_URI='sqlite:////%s' % app.config['DATABASE'], SECRET_KEY = os.urandom(24) ) # create db and populate db.create_all() user = User(username='******') user.password = pwd_context.encrypt('doe') db.session.add(user) db.session.commit() # create product store now = dt.now().strftime('%a %b %d %H:%M:%S %Y') store.set('last-update', now) for i in range(5): pid = 's%d' % i store.lpush('user:%s:products' % user.id, pid) store.hset('products:%s' % pid, 'version', 1) # create a test app every test case can use. self.test_app = app.test_client()
def new_user(): if not request.get_json(): return err.make_error(400, "Missing json body") data, errors = user_schema.load(request.json) if errors: return err.make_error(400, "Invalid json body") user = User(username=data.get('username')) user.password = data.get('password') db.session.add(user) db.session.commit() return make_response(jsonify({'id': user.id}), 201)
def new_user(): if not request.get_json(): return err.make_error(400, "Missing json body") data, errors = user_schema.load(request.json) if errors: return err.make_error(400, "Invalid json body") user = User(username = data.get('username')) user.password = data.get('password') db.session.add(user) db.session.commit() return make_response(jsonify({'id': user.id}), 201)
def setUp(self): self.db_fd, app.config['DATABASE'] = tempfile.mkstemp() app.config.update(TESTING=True, SQLALCHEMY_DATABASE_URI='sqlite:////%s' % app.config['DATABASE'], SECRET_KEY=os.urandom(24)) # create db and populate db.create_all() user = User(username='******') user.password = pwd_context.encrypt('doe') db.session.add(user) db.session.commit() # create product store now = dt.now().strftime('%a %b %d %H:%M:%S %Y') store.set('last-update', now) for i in range(5): pid = 's%d' % i store.lpush('user:%s:products' % user.id, pid) store.hset('products:%s' % pid, 'version', 1) # create a test app every test case can use. self.test_app = app.test_client()
def add_user_to_db(self, username, password): user = User(username=username) user.password = pwd_context.encrypt(password) db.session.add(user) db.session.commit()