minor fixes to testing utils

This commit is contained in:
MinRK
2014-09-13 22:41:45 -07:00
parent a245641886
commit 970e4d2ce2
2 changed files with 10 additions and 9 deletions

View File

@@ -38,12 +38,12 @@ def db():
@fixture @fixture
def io_loop(): def io_loop():
"""Get the current IOLoop""" """Get the current IOLoop"""
ioloop.IOLoop.clear_current() loop = ioloop.IOLoop()
return ioloop.IOLoop.current() loop.make_current()
return loop
@fixture(scope='module')
@fixture
def app(request): def app(request):
app = MockHubApp() app = MockHubApp()
app.start([]) app.start([])

View File

@@ -58,12 +58,13 @@ class MockHubApp(JupyterHubApp):
self.io_loop = IOLoop.current() self.io_loop = IOLoop.current()
# put initialize in start for SQLAlchemy threading reasons # put initialize in start for SQLAlchemy threading reasons
super(MockHubApp, self).initialize(argv=argv) super(MockHubApp, self).initialize(argv=argv)
user = orm.User(name=getpass.getuser())
# add some initial users - 1 admin, 1 non-admin
admin = orm.User(name='admin', admin=True)
user = orm.User(name='user')
self.db.add(admin)
self.db.add(user) self.db.add(user)
self.db.commit() self.db.commit()
token = user.new_api_token()
self.db.add(token)
self.db.commit()
self.io_loop.add_callback(evt.set) self.io_loop.add_callback(evt.set)
super(MockHubApp, self).start() super(MockHubApp, self).start()
@@ -72,6 +73,6 @@ class MockHubApp(JupyterHubApp):
evt.wait(timeout=5) evt.wait(timeout=5)
def stop(self): def stop(self):
self.io_loop.stop() self.io_loop.add_callback(self.io_loop.stop)
self._thread.join() self._thread.join()