Repository: simphony/simphony-remote

Issue:
HomeHandler should not 'finish' in View and Stop but raise
Let view and stop raise and then the HomeHandler.post will handle the logging.

https://github.com/simphony/simphony-remote/blob/98ee374756694ef1855a9d38d78d3561ec6cc54e/remoteappmanager/handlers/home_handler.py#L155

https://github.com/simphony/simphony-remote/blob/98ee374756694ef1855a9d38d78d3561ec6cc54e/remoteappmanager/handlers/home_handler.py#L132

Discussion:

Patch:
diff --git a/remoteappmanager/handlers/home_handler.py b/remoteappmanager/handlers/home_handler.py
index c21824b..7d5ce97 100644
--- a/remoteappmanager/handlers/home_handler.py
+++ b/remoteappmanager/handlers/home_handler.py
@@ -131,8 +131,10 @@ class HomeHandler(BaseHandler):
         container_manager = self.application.container_manager
         container = yield container_manager.container_from_url_id(url_id)
         if not container:
-            self.finish("Unable to view the application")
-            return
+            self.log.warning("Could not find container for url_id {}".format(
+                url_id
+            ))
+            raise ValueError("Unable to view container for specified url_id")
 
         # make sure the container is actually running and working
         yield self._wait_for_container_ready(container)
@@ -158,8 +160,10 @@ class HomeHandler(BaseHandler):
 
         container = yield container_manager.container_from_url_id(url_id)
         if not container:
-            self.finish("Unable to view the application")
-            return
+            self.log.warning("Could not find container for url_id {}".format(
+                url_id
+            ))
+            raise ValueError("Unable to view container for specified url_id")
 
         urlpath = url_path_join(
             self.application.command_line_config.base_urlpath,


Test patch:
diff --git a/tests/handlers/test_home_handler.py b/tests/handlers/test_home_handler.py
index 596b8db..7a49d7f 100644
--- a/tests/handlers/test_home_handler.py
+++ b/tests/handlers/test_home_handler.py
@@ -184,3 +184,34 @@ class TestHomeHandler(TempMixin, utils.AsyncHTTPTestCase):
 
             self.assertTrue(self._app.reverse_proxy.register.called)
             self.assertTrue(redirect.called)
+
+    def test_container_manager_does_not_return_container(self):
+        self._app.container_manager.container_from_url_id = \
+            utils.mock_coro_factory(None)
+        res = self.fetch(
+            "/user/username/",
+            method="POST",
+            headers={
+                "Cookie": "jupyter-hub-token-username=foo"
+            },
+            body=urllib.parse.urlencode({
+                'action': 'view',
+                'url_id': '12345'
+            })
+        )
+
+        self.assertIn("ValueError", str(res.body))
+
+        res = self.fetch(
+            "/user/username/",
+            method="POST",
+            headers={
+                "Cookie": "jupyter-hub-token-username=foo"
+            },
+            body=urllib.parse.urlencode({
+                'action': 'stop',
+                'url_id': '12345'
+            })
+        )
+
+        self.assertIn("ValueError", str(res.body))