avoid creating duplicate users in test_api

now that we check!
This commit is contained in:
Min RK
2016-07-28 16:27:32 +02:00
parent fd3b959771
commit dfa13cb2c5

View File

@@ -42,8 +42,13 @@ def find_user(db, name):
return db.query(orm.User).filter(orm.User.name==name).first()
def add_user(db, app=None, **kwargs):
orm_user = find_user(db, name=kwargs.get('name'))
if orm_user is None:
orm_user = orm.User(**kwargs)
db.add(orm_user)
else:
for attr, value in kwargs.items():
setattr(orm_user, attr, value)
db.commit()
if app:
user = app.users[orm_user.id] = User(orm_user, app.tornado_settings)