##// END OF EJS Templates
Moving example-embed-short.py.
Moving example-embed-short.py.

File last commit:

r15400:5b647d67
r16062:a79228b4
Show More
test_sessionmanager.py
83 lines | 4.2 KiB | text/x-python | PythonLexer
Zachary Sailer
session manager restructuring...
r13035 """Tests for the session manager."""
from unittest import TestCase
Thomas Kluyver
Fix sessionmanager test
r13097 from tornado import web
Zachary Sailer
session manager restructuring...
r13035 from ..sessionmanager import SessionManager
class TestSessionManager(TestCase):
def test_get_session(self):
sm = SessionManager()
MinRK
review pass on Sessions API
r13101 session_id = sm.new_session_id()
MinRK
remove websocket url...
r15400 sm.save_session(session_id=session_id, name='test.ipynb', path='/path/to/', kernel_id='5678')
MinRK
review pass on Sessions API
r13101 model = sm.get_session(session_id=session_id)
MinRK
remove websocket url...
r15400 expected = {'id':session_id, 'notebook':{'name':u'test.ipynb', 'path': u'/path/to/'}, 'kernel':{'id':u'5678'}}
Zachary Sailer
session manager restructuring...
r13035 self.assertEqual(model, expected)
def test_bad_get_session(self):
# Should raise error if a bad key is passed to the database.
sm = SessionManager()
MinRK
review pass on Sessions API
r13101 session_id = sm.new_session_id()
MinRK
remove websocket url...
r15400 sm.save_session(session_id=session_id, name='test.ipynb', path='/path/to/', kernel_id='5678')
MinRK
review pass on Sessions API
r13101 self.assertRaises(TypeError, sm.get_session, bad_id=session_id) # Bad keyword
Zachary Sailer
session manager restructuring...
r13035
def test_list_sessions(self):
sm = SessionManager()
MinRK
review pass on Sessions API
r13101 session_id1 = sm.new_session_id()
session_id2 = sm.new_session_id()
session_id3 = sm.new_session_id()
MinRK
remove websocket url...
r15400 sm.save_session(session_id=session_id1, name='test1.ipynb', path='/path/to/1/', kernel_id='5678')
sm.save_session(session_id=session_id2, name='test2.ipynb', path='/path/to/2/', kernel_id='5678')
sm.save_session(session_id=session_id3, name='test3.ipynb', path='/path/to/3/', kernel_id='5678')
Zachary Sailer
session manager restructuring...
r13035 sessions = sm.list_sessions()
Zachary Sailer
changes after session manager code review
r13057 expected = [{'id':session_id1, 'notebook':{'name':u'test1.ipynb',
MinRK
remove websocket url...
r15400 'path': u'/path/to/1/'}, 'kernel':{'id':u'5678'}},
Zachary Sailer
changes after session manager code review
r13057 {'id':session_id2, 'notebook': {'name':u'test2.ipynb',
MinRK
remove websocket url...
r15400 'path': u'/path/to/2/'}, 'kernel':{'id':u'5678'}},
Zachary Sailer
changes after session manager code review
r13057 {'id':session_id3, 'notebook':{'name':u'test3.ipynb',
MinRK
remove websocket url...
r15400 'path': u'/path/to/3/'}, 'kernel':{'id':u'5678'}}]
Zachary Sailer
session manager restructuring...
r13035 self.assertEqual(sessions, expected)
def test_update_session(self):
sm = SessionManager()
MinRK
review pass on Sessions API
r13101 session_id = sm.new_session_id()
MinRK
remove websocket url...
r15400 sm.save_session(session_id=session_id, name='test.ipynb', path='/path/to/', kernel_id=None)
Zachary Sailer
changes after session manager code review
r13057 sm.update_session(session_id, kernel_id='5678')
Zachary Sailer
session manager restructuring...
r13035 sm.update_session(session_id, name='new_name.ipynb')
MinRK
review pass on Sessions API
r13101 model = sm.get_session(session_id=session_id)
MinRK
remove websocket url...
r15400 expected = {'id':session_id, 'notebook':{'name':u'new_name.ipynb', 'path': u'/path/to/'}, 'kernel':{'id':u'5678'}}
Zachary Sailer
session manager restructuring...
r13035 self.assertEqual(model, expected)
def test_bad_update_session(self):
# try to update a session with a bad keyword ~ raise error
sm = SessionManager()
MinRK
review pass on Sessions API
r13101 session_id = sm.new_session_id()
MinRK
remove websocket url...
r15400 sm.save_session(session_id=session_id, name='test.ipynb', path='/path/to/', kernel_id='5678')
MinRK
review pass on Sessions API
r13101 self.assertRaises(TypeError, sm.update_session, session_id=session_id, bad_kw='test.ipynb') # Bad keyword
Zachary Sailer
session manager restructuring...
r13035
def test_delete_session(self):
sm = SessionManager()
MinRK
review pass on Sessions API
r13101 session_id1 = sm.new_session_id()
session_id2 = sm.new_session_id()
session_id3 = sm.new_session_id()
MinRK
remove websocket url...
r15400 sm.save_session(session_id=session_id1, name='test1.ipynb', path='/path/to/1/', kernel_id='5678')
sm.save_session(session_id=session_id2, name='test2.ipynb', path='/path/to/2/', kernel_id='5678')
sm.save_session(session_id=session_id3, name='test3.ipynb', path='/path/to/3/', kernel_id='5678')
Zachary Sailer
session manager restructuring...
r13035 sm.delete_session(session_id2)
sessions = sm.list_sessions()
Zachary Sailer
changes after session manager code review
r13057 expected = [{'id':session_id1, 'notebook':{'name':u'test1.ipynb',
MinRK
remove websocket url...
r15400 'path': u'/path/to/1/'}, 'kernel':{'id':u'5678'}},
Zachary Sailer
changes after session manager code review
r13057 {'id':session_id3, 'notebook':{'name':u'test3.ipynb',
MinRK
remove websocket url...
r15400 'path': u'/path/to/3/'}, 'kernel':{'id':u'5678'}}]
Zachary Sailer
session manager restructuring...
r13035 self.assertEqual(sessions, expected)
def test_bad_delete_session(self):
# try to delete a session that doesn't exist ~ raise error
sm = SessionManager()
MinRK
review pass on Sessions API
r13101 session_id = sm.new_session_id()
MinRK
remove websocket url...
r15400 sm.save_session(session_id=session_id, name='test.ipynb', path='/path/to/', kernel_id='5678')
MinRK
review pass on Sessions API
r13101 self.assertRaises(TypeError, sm.delete_session, bad_kwarg='23424') # Bad keyword
self.assertRaises(web.HTTPError, sm.delete_session, session_id='23424') # nonexistant
Zachary Sailer
session manager restructuring...
r13035