Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix iteration over the sessions in /reconnectsparkmagic #660

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion sparkmagic/sparkmagic/serverextension/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,13 @@ def _get_argument_or_raise(self, data, key):
except KeyError:
raise MissingArgumentError(key)

def _get_list_sessions(self):
sessions = self.session_manager.list_sessions()
return [session for session in sessions.result]

@gen.coroutine
def _get_kernel_manager(self, path, kernel_name):
sessions = self.session_manager.list_sessions()
sessions = self._get_list_sessions()

kernel_id = None
for session in sessions:
Expand Down
3 changes: 2 additions & 1 deletion sparkmagic/sparkmagic/tests/test_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def setUp(self):
self.kernel_manager.get_kernel = MagicMock(return_value=self.individual_kernel_manager)

# Mock session manager
self.session_list = [self.create_session_dict(self.path, self.kernel_id)]
self.session_list = MagicMock(return_value=[self.create_session_dict(self.path, self.kernel_id)])
self.session_manager = MagicMock()
self.session_manager.list_sessions = MagicMock(return_value=self.session_list)
self.session_manager.create_session = MagicMock(return_value=self.create_session_dict(self.path, self.kernel_id))
Expand All @@ -68,6 +68,7 @@ def setUp(self):
# Create mocked reconnect_handler
ReconnectHandler.__bases__ = (SimpleObject,)
self.reconnect_handler = ReconnectHandler()
self.reconnect_handler._get_list_sessions = self.session_list
self.reconnect_handler.spark_events = self.spark_events
self.reconnect_handler.session_manager = self.session_manager
self.reconnect_handler.kernel_manager = self.kernel_manager
Expand Down