Repository: simphony/simphony-remote

Issue:
Investigate why the REST layer returns an application that is no longer present
Related to #221, the root issue is that the applications list is returning an entry that is not available.
While PR #223 fixes the issue client side, the entry should not be there to begin with in the initial response.


Discussion:

Patch:
diff --git a/remoteappmanager/restresources/application.py b/remoteappmanager/restresources/application.py
index 78ebec9..72de8fe 100644
--- a/remoteappmanager/restresources/application.py
+++ b/remoteappmanager/restresources/application.py
@@ -60,4 +60,11 @@ class Application(Resource):
         container, if active, as values."""
         apps = self.application.db.get_apps_for_user(self.current_user.account)
 
-        return [mapping_id for mapping_id, _, _ in apps]
+        container_manager = self.application.container_manager
+
+        result = []
+        for mapping_id, app, policy in apps:
+            if (yield container_manager.image(app.image)) is not None:
+                result.append(mapping_id)
+
+        return result


Test patch:
diff --git a/remoteappmanager/restresources/tests/test_application.py b/remoteappmanager/restresources/tests/test_application.py
index 971074c..daabb5b 100644
--- a/remoteappmanager/restresources/tests/test_application.py
+++ b/remoteappmanager/restresources/tests/test_application.py
@@ -30,6 +30,7 @@ class TestApplication(AsyncHTTPTestCase):
 
         application_mock_2 = Mock()
         application_mock_2.image = "hello2"
+
         app.db.get_apps_for_user = Mock(return_value=[
             ("one", application_mock_1, Mock()),
             ("two", application_mock_2, Mock()),
@@ -56,6 +57,16 @@ class TestApplication(AsyncHTTPTestCase):
             self.assertEqual(escape.json_decode(res.body),
                              {"items": ["one", "two"]})
 
+            # Check if nothing is returned if no images are present
+            self._app.container_manager.image = mock_coro_factory(
+                return_value=None)
+
+            res = self.fetch("/api/v1/applications/")
+
+            self.assertEqual(res.code, httpstatus.OK)
+            self.assertEqual(escape.json_decode(res.body),
+                             {"items": []})
+
     def test_retrieve(self):
         def prepare_side_effect(*args, **kwargs):
             user = Mock()