API: minor fixes & db update
This commit is contained in:
parent
844457b33c
commit
b6056e6125
@ -27,7 +27,7 @@ app.register_blueprint(users_blueprint, url_prefix='/api')
|
||||
app.register_blueprint(auth_blueprint, url_prefix='/api')
|
||||
|
||||
if app.debug:
|
||||
logging.getLogger('sqlalchemy').setLevel(logging.INFO)
|
||||
logging.getLogger('sqlalchemy').setLevel(logging.WARNING)
|
||||
logging.getLogger('sqlalchemy'
|
||||
).handlers = logging.getLogger('werkzeug').handlers
|
||||
logging.getLogger('sqlalchemy.orm').setLevel(logging.WARNING)
|
||||
|
@ -39,7 +39,8 @@ class TestAuthBlueprint(BaseTestCase):
|
||||
)
|
||||
data = json.loads(response.data.decode())
|
||||
self.assertTrue(data['status'] == 'error')
|
||||
self.assertTrue(data['message'] == 'Sorry. That user already exists.')
|
||||
self.assertTrue(
|
||||
data['message'] == 'Sorry. That user already exists.')
|
||||
self.assertTrue(response.content_type == 'application/json')
|
||||
self.assertEqual(response.status_code, 400)
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
import json
|
||||
|
||||
from mpwo_api.tests.base import BaseTestCase
|
||||
from mpwo_api.users.models import User
|
||||
from mpwo_api.tests.utils import add_user
|
||||
from mpwo_api.users.models import User
|
||||
|
||||
|
||||
class TestUserService(BaseTestCase):
|
||||
|
@ -1,5 +1,5 @@
|
||||
from mpwo_api.users.models import User
|
||||
from mpwo_api import db
|
||||
from mpwo_api.users.models import User
|
||||
|
||||
|
||||
def add_user(username, email, password):
|
||||
|
@ -1,7 +1,7 @@
|
||||
from flask import Blueprint, jsonify, request
|
||||
from sqlalchemy import exc, or_
|
||||
|
||||
from mpwo_api import bcrypt, db
|
||||
from mpwo_api import appLog, bcrypt, db
|
||||
|
||||
from .models import User
|
||||
|
||||
@ -51,6 +51,7 @@ def register_user():
|
||||
# handler errors
|
||||
except (exc.IntegrityError, exc.OperationalError, ValueError) as e:
|
||||
db.session.rollback()
|
||||
appLog.error(e)
|
||||
response_object = {
|
||||
'status': 'error',
|
||||
'message': 'Invalid payload.'
|
||||
@ -91,6 +92,7 @@ def login_user():
|
||||
# handler errors
|
||||
except (exc.IntegrityError, exc.OperationalError, ValueError) as e:
|
||||
db.session.rollback()
|
||||
appLog.error(e)
|
||||
response_object = {
|
||||
'status': 'error',
|
||||
'message': 'Try again'
|
||||
|
@ -13,6 +13,7 @@ class User(db.Model):
|
||||
email = db.Column(db.String(120), unique=True, nullable=False)
|
||||
password = db.Column(db.String(255), nullable=False)
|
||||
created_at = db.Column(db.DateTime, nullable=False)
|
||||
admin = db.Column(db.Boolean, default=False, nullable=False)
|
||||
|
||||
def __repr__(self):
|
||||
return '<User %r>' % self.username
|
||||
|
@ -16,16 +16,9 @@ def recreate_db():
|
||||
@app.cli.command()
|
||||
def seed_db():
|
||||
"""Seeds the database."""
|
||||
db.session.add(User(
|
||||
username='test',
|
||||
email='test@test.com',
|
||||
password='test'
|
||||
))
|
||||
db.session.add(User(
|
||||
username='test2',
|
||||
email='test2@test.com',
|
||||
password='test2'
|
||||
))
|
||||
admin = User(username='admin', email='admin@example.com', password='admin')
|
||||
admin.admin = True
|
||||
db.session.add(admin)
|
||||
db.session.commit()
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user