From 1c489d9bfd856af2562d6c4666c149b899dfe69f Mon Sep 17 00:00:00 2001 From: Leticia Portella Date: Wed, 13 Feb 2019 16:48:52 +0000 Subject: [PATCH 1/2] Remove duplication creation of user --- nativeauthenticator/nativeauthenticator.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/nativeauthenticator/nativeauthenticator.py b/nativeauthenticator/nativeauthenticator.py index f4ad9b5..1356e49 100644 --- a/nativeauthenticator/nativeauthenticator.py +++ b/nativeauthenticator/nativeauthenticator.py @@ -2,7 +2,6 @@ import os from datetime import datetime from jupyterhub.auth import Authenticator -from jupyterhub.orm import User from sqlalchemy import inspect from tornado import gen @@ -151,11 +150,10 @@ def get_or_create_user(self, username, pw, **kwargs): try: user_info = UserInfo(**infos) - user = User(name=username) except AssertionError: return - self.db.add_all([user_info, user]) + self.db.add(user_info) self.db.commit() return user_info From 8fbed01377987c688f103918340b09634da9791a Mon Sep 17 00:00:00 2001 From: Leticia Portella Date: Wed, 13 Feb 2019 17:14:38 +0000 Subject: [PATCH 2/2] Remove User interaction from tests --- nativeauthenticator/tests/test_authenticator.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/nativeauthenticator/tests/test_authenticator.py b/nativeauthenticator/tests/test_authenticator.py index 5475409..c3b1da2 100644 --- a/nativeauthenticator/tests/test_authenticator.py +++ b/nativeauthenticator/tests/test_authenticator.py @@ -1,6 +1,5 @@ import pytest import time -from jupyterhub.orm import User from jupyterhub.tests.mocking import MockHub from nativeauthenticator import NativeAuthenticator @@ -42,9 +41,7 @@ async def test_create_user(is_admin, open_signup, expected_authorization, auth.get_or_create_user('johnsnow', 'password') user_info = UserInfo.find(app.db, 'johnsnow') - user = User.find(app.db, 'johnsnow') assert user_info.username == 'johnsnow' - assert user.name == 'johnsnow' assert user_info.is_authorized == expected_authorization @@ -163,7 +160,7 @@ async def test_delete_user(tmpcwd, app): auth = NativeAuthenticator(db=app.db) auth.get_or_create_user('johnsnow', 'password') - user = User.find(app.db, 'johnsnow') + user = type('User', (), {'name': 'johnsnow'}) auth.delete_user(user) user_info = UserInfo.find(app.db, 'johnsnow')