Drop support for db upgrade from before 1.0

- define jupyterhub oauth client during token app
This commit is contained in:
Min RK
2021-03-11 11:30:21 +01:00
parent 0b56fd9e62
commit 900c2f1ed3
3 changed files with 28 additions and 29 deletions

View File

@@ -214,6 +214,8 @@ class NewToken(Application):
hub = JupyterHub(parent=self) hub = JupyterHub(parent=self)
hub.load_config_file(hub.config_file) hub.load_config_file(hub.config_file)
hub.init_db() hub.init_db()
hub.init_hub()
hub.init_oauth()
def init_users(): def init_users():
loop = asyncio.new_event_loop() loop = asyncio.new_event_loop()

View File

@@ -62,36 +62,33 @@ def populate_db(url):
db.commit() db.commit()
# create some oauth objects # create some oauth objects
if jupyterhub.version_info >= (0, 8): client = orm.OAuthClient(identifier='oauth-client')
# create oauth client db.add(client)
client = orm.OAuthClient(identifier='oauth-client') db.commit()
db.add(client) code = orm.OAuthCode(client_id=client.identifier)
db.commit() db.add(code)
code = orm.OAuthCode(client_id=client.identifier) db.commit()
db.add(code) if jupyterhub.version_info < (2, 0):
db.commit() Token = orm.OAuthAccessToken
if jupyterhub.version_info < (2, 0): else:
Token = orm.OAuthAccessToken Token = orm.APIToken
else: access_token = Token(
Token = orm.APIToken client_id=client.identifier,
access_token = Token( user_id=user.id,
client_id=client.identifier, grant_type=orm.GrantType.authorization_code,
user_id=user.id, )
grant_type=orm.GrantType.authorization_code, db.add(access_token)
) db.commit()
db.add(access_token)
db.commit()
# set some timestamps added in 0.9 # set some timestamps added in 0.9
if jupyterhub.version_info >= (0, 9): assert user.created
assert user.created assert admin.created
assert admin.created # set last_activity
# set last_activity user.last_activity = datetime.utcnow()
user.last_activity = datetime.utcnow() spawner = user.orm_spawners['']
spawner = user.orm_spawners[''] spawner.started = datetime.utcnow()
spawner.started = datetime.utcnow() spawner.last_activity = datetime.utcnow()
spawner.last_activity = datetime.utcnow() db.commit()
db.commit()
if __name__ == '__main__': if __name__ == '__main__':

View File

@@ -36,7 +36,7 @@ def generate_old_db(env_dir, hub_version, db_url):
check_call([env_py, populate_db, db_url]) check_call([env_py, populate_db, db_url])
@pytest.mark.parametrize('hub_version', ['0.7.2', '0.8.1', '0.9.4']) @pytest.mark.parametrize('hub_version', ['1.0.0', "1.2.2", "1.3.0"])
async def test_upgrade(tmpdir, hub_version): async def test_upgrade(tmpdir, hub_version):
db_url = os.getenv('JUPYTERHUB_TEST_DB_URL') db_url = os.getenv('JUPYTERHUB_TEST_DB_URL')
if db_url: if db_url: