From dfa13cb2c53a33d7da6c6bcaa62a148f1daf6327 Mon Sep 17 00:00:00 2001 From: Min RK Date: Thu, 28 Jul 2016 16:27:32 +0200 Subject: [PATCH] avoid creating duplicate users in test_api now that we check! --- jupyterhub/tests/test_api.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/jupyterhub/tests/test_api.py b/jupyterhub/tests/test_api.py index 8b08fabf..493f46d1 100644 --- a/jupyterhub/tests/test_api.py +++ b/jupyterhub/tests/test_api.py @@ -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 = orm.User(**kwargs) - db.add(orm_user) + 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)