mirror of
https://github.com/jupyterhub/jupyterhub.git
synced 2025-10-14 13:33:00 +00:00
unify mocking of tornado_settings
ensures that everywhere we access settings, it's the same dict and not a copy
This commit is contained in:
@@ -130,7 +130,7 @@ def mockservice_url(request, app):
|
||||
@fixture
|
||||
def no_patience(app):
|
||||
"""Set slow-spawning timeouts to zero"""
|
||||
with mock.patch.dict(app.tornado_application.settings,
|
||||
with mock.patch.dict(app.tornado_settings,
|
||||
{'slow_spawn_timeout': 0,
|
||||
'slow_stop_timeout': 0}):
|
||||
yield
|
||||
@@ -139,7 +139,7 @@ def no_patience(app):
|
||||
@fixture
|
||||
def slow_spawn(app):
|
||||
"""Fixture enabling SlowSpawner"""
|
||||
with mock.patch.dict(app.users.settings,
|
||||
with mock.patch.dict(app.tornado_settings,
|
||||
{'spawner_class': mocking.SlowSpawner}):
|
||||
yield
|
||||
|
||||
@@ -147,7 +147,7 @@ def slow_spawn(app):
|
||||
@fixture
|
||||
def never_spawn(app):
|
||||
"""Fixture enabling NeverSpawner"""
|
||||
with mock.patch.dict(app.users.settings,
|
||||
with mock.patch.dict(app.tornado_settings,
|
||||
{'spawner_class': mocking.NeverSpawner}):
|
||||
yield
|
||||
|
||||
@@ -155,7 +155,7 @@ def never_spawn(app):
|
||||
@fixture
|
||||
def bad_spawn(app):
|
||||
"""Fixture enabling BadSpawner"""
|
||||
with mock.patch.dict(app.users.settings,
|
||||
with mock.patch.dict(app.tornado_settings,
|
||||
{'spawner_class': mocking.BadSpawner}):
|
||||
yield
|
||||
|
||||
@@ -163,7 +163,7 @@ def bad_spawn(app):
|
||||
@fixture
|
||||
def slow_bad_spawn(app):
|
||||
"""Fixture enabling SlowBadSpawner"""
|
||||
with mock.patch.dict(app.users.settings,
|
||||
with mock.patch.dict(app.tornado_settings,
|
||||
{'spawner_class': mocking.SlowBadSpawner}):
|
||||
yield
|
||||
|
||||
@@ -171,6 +171,6 @@ def slow_bad_spawn(app):
|
||||
@fixture
|
||||
def admin_access(app):
|
||||
"""Grant admin-access with this fixture"""
|
||||
with mock.patch.dict(app.users.settings,
|
||||
with mock.patch.dict(app.tornado_settings,
|
||||
{'admin_access': True}):
|
||||
yield
|
||||
|
@@ -218,7 +218,7 @@ class MockHub(JupyterHub):
|
||||
"""Instantiate the tornado Application object"""
|
||||
super().init_tornado_application()
|
||||
# reconnect tornado_settings so that mocks can update the real thing
|
||||
self.tornado_settings = self.tornado_application.settings
|
||||
self.tornado_settings = self.users.settings = self.tornado_application.settings
|
||||
|
||||
@gen.coroutine
|
||||
def initialize(self, argv=None):
|
||||
|
@@ -518,7 +518,6 @@ def test_never_spawn(app, no_patience, never_spawn):
|
||||
|
||||
@mark.gen_test
|
||||
def test_bad_spawn(app, no_patience, bad_spawn):
|
||||
settings = app.tornado_application.settings
|
||||
db = app.db
|
||||
name = 'prim'
|
||||
user = add_user(db, app=app, name=name)
|
||||
@@ -529,7 +528,6 @@ def test_bad_spawn(app, no_patience, bad_spawn):
|
||||
|
||||
@mark.gen_test
|
||||
def test_slow_bad_spawn(app, no_patience, slow_bad_spawn):
|
||||
settings = app.tornado_application.settings
|
||||
db = app.db
|
||||
name = 'zaphod'
|
||||
user = add_user(db, app=app, name=name)
|
||||
@@ -545,11 +543,10 @@ def test_slow_bad_spawn(app, no_patience, slow_bad_spawn):
|
||||
@mark.gen_test
|
||||
def test_spawn_limit(app, no_patience, slow_spawn, request):
|
||||
db = app.db
|
||||
settings = app.tornado_application.settings
|
||||
settings['concurrent_spawn_limit'] = 2
|
||||
def _restore_limit():
|
||||
settings['concurrent_spawn_limit'] = 100
|
||||
request.addfinalizer(_restore_limit)
|
||||
p = mock.patch.dict(app.tornado_settings,
|
||||
{'concurrent_spawn_limit': 2})
|
||||
p.start()
|
||||
request.addfinalizer(p.stop)
|
||||
|
||||
# start two pending spawns
|
||||
names = ['ykka', 'hjarka']
|
||||
@@ -597,11 +594,10 @@ def test_spawn_limit(app, no_patience, slow_spawn, request):
|
||||
@mark.gen_test
|
||||
def test_active_server_limit(app, request):
|
||||
db = app.db
|
||||
settings = app.tornado_application.settings
|
||||
settings['active_server_limit'] = 2
|
||||
def _restore_limit():
|
||||
settings['active_server_limit'] = 0
|
||||
request.addfinalizer(_restore_limit)
|
||||
p = mock.patch.dict(app.tornado_settings,
|
||||
{'active_server_limit': 2})
|
||||
p.start()
|
||||
request.addfinalizer(p.stop)
|
||||
|
||||
# start two pending spawns
|
||||
names = ['ykka', 'hjarka']
|
||||
|
@@ -1,4 +1,6 @@
|
||||
"""Tests for named servers"""
|
||||
from unittest import mock
|
||||
|
||||
import pytest
|
||||
|
||||
from ..utils import url_path_join
|
||||
@@ -9,12 +11,9 @@ from .utils import async_requests
|
||||
|
||||
@pytest.fixture
|
||||
def named_servers(app):
|
||||
key = 'allow_named_servers'
|
||||
app.tornado_application.settings[key] = app.tornado_settings[key] = True
|
||||
try:
|
||||
yield True
|
||||
finally:
|
||||
app.tornado_application.settings[key] = app.tornado_settings[key] = False
|
||||
with mock.patch.dict(app.tornado_settings,
|
||||
{'allow_named_servers': True}):
|
||||
yield
|
||||
|
||||
|
||||
@pytest.mark.gen_test
|
||||
|
@@ -209,7 +209,7 @@ def test_spawn_form(app):
|
||||
|
||||
@pytest.mark.gen_test
|
||||
def test_spawn_form_admin_access(app, admin_access):
|
||||
with mock.patch.dict(app.users.settings, {'spawner_class': FormSpawner}):
|
||||
with mock.patch.dict(app.tornado_settings, {'spawner_class': FormSpawner}):
|
||||
base_url = ujoin(public_host(app), app.hub.base_url)
|
||||
cookies = yield app.login_user('admin')
|
||||
u = add_user(app.db, app=app, name='martha')
|
||||
@@ -232,7 +232,7 @@ def test_spawn_form_admin_access(app, admin_access):
|
||||
|
||||
@pytest.mark.gen_test
|
||||
def test_spawn_form_with_file(app):
|
||||
with mock.patch.dict(app.users.settings, {'spawner_class': FormSpawner}):
|
||||
with mock.patch.dict(app.tornado_settings, {'spawner_class': FormSpawner}):
|
||||
base_url = ujoin(public_host(app), app.hub.base_url)
|
||||
cookies = yield app.login_user('jones')
|
||||
orm_u = orm.User.find(app.db, 'jones')
|
||||
@@ -386,7 +386,7 @@ def test_auto_login(app, request):
|
||||
authenticator = Authenticator(auto_login=True)
|
||||
authenticator.login_url = lambda base_url: ujoin(base_url, 'dummy')
|
||||
|
||||
with mock.patch.dict(app.tornado_application.settings, {
|
||||
with mock.patch.dict(app.tornado_settings, {
|
||||
'authenticator': authenticator,
|
||||
}):
|
||||
r = yield async_requests.get(base_url)
|
||||
@@ -397,7 +397,7 @@ def test_auto_login_logout(app):
|
||||
name = 'burnham'
|
||||
cookies = yield app.login_user(name)
|
||||
|
||||
with mock.patch.dict(app.tornado_application.settings, {
|
||||
with mock.patch.dict(app.tornado_settings, {
|
||||
'authenticator': Authenticator(auto_login=True),
|
||||
}):
|
||||
r = yield async_requests.get(public_host(app) + app.tornado_settings['logout_url'], cookies=cookies)
|
||||
|
Reference in New Issue
Block a user