From 795ebef682dbd50226f73f3eea0c1071e88851c8 Mon Sep 17 00:00:00 2001 From: Stefano Borini Date: Wed, 31 May 2017 16:44:52 +0100 Subject: [PATCH 1/3] Skip containers that are not found while checking container.items --- remoteappmanager/webapi/container.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/remoteappmanager/webapi/container.py b/remoteappmanager/webapi/container.py index d4d903b5a..49b226c0f 100644 --- a/remoteappmanager/webapi/container.py +++ b/remoteappmanager/webapi/container.py @@ -163,6 +163,9 @@ def items(self, items_response, **kwargs): user_name=self.current_user.name, mapping_id=accounting.id) + if container is None: + continue + rest_container = Container(identifier=container.url_id) rest_container.fill(container) running_containers.append(rest_container) From 9c1b91b4d86f8302f67eff3fc271d26afeb61e7e Mon Sep 17 00:00:00 2001 From: Stefano Borini Date: Fri, 2 Jun 2017 15:57:15 +0100 Subject: [PATCH 2/3] Added test for coverage --- .../webapi/tests/test_container.py | 37 +++++++++++++++---- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/remoteappmanager/webapi/tests/test_container.py b/remoteappmanager/webapi/tests/test_container.py index fecfa3644..9293cb5db 100644 --- a/remoteappmanager/webapi/tests/test_container.py +++ b/remoteappmanager/webapi/tests/test_container.py @@ -25,8 +25,7 @@ def get_app(self): def test_items(self): manager = self._app.container_manager manager.image = mock_coro_factory(Image()) - manager.find_containers = mock_coro_factory( - [ + manager.find_containers = mock_coro_factory([ DockerContainer(user="johndoe", mapping_id="whatever", url_id="12345", @@ -48,12 +47,34 @@ def test_items(self): 'total': 2, 'offset': 0, 'items': { - '12345': { - 'image_name': 'image', - 'name': 'container', - 'mapping_id': 'whatever' - } - }}) + '12345': { + 'image_name': 'image', + 'name': 'container', + 'mapping_id': 'whatever' + } + }}) + + def test_items_with_none_container(self): + manager = self._app.container_manager + manager.image = mock_coro_factory(Image()) + manager.find_container = mock_coro_factory(None) + + code, data = self.get("/user/johndoe/api/v1/containers/", + httpstatus.OK) + + # We get two because we have two mapping ids, hence the find_containers + # gets called once per each mapping id. + # This is a kind of unusual case, because we only get one item + # in the items list, due to the nature of the test. + self.assertEqual( + data, + { + 'identifiers': [], + 'total': 0, + 'offset': 0, + 'items': {} + } + ) def test_create(self): with patch("remoteappmanager" From c6a237b819c432118417e58e4d1c9334d07324d7 Mon Sep 17 00:00:00 2001 From: Stefano Borini Date: Fri, 2 Jun 2017 17:19:58 +0100 Subject: [PATCH 3/3] Removed comment and restarted build --- remoteappmanager/webapi/tests/test_container.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/remoteappmanager/webapi/tests/test_container.py b/remoteappmanager/webapi/tests/test_container.py index 9293cb5db..203357c1f 100644 --- a/remoteappmanager/webapi/tests/test_container.py +++ b/remoteappmanager/webapi/tests/test_container.py @@ -62,10 +62,6 @@ def test_items_with_none_container(self): code, data = self.get("/user/johndoe/api/v1/containers/", httpstatus.OK) - # We get two because we have two mapping ids, hence the find_containers - # gets called once per each mapping id. - # This is a kind of unusual case, because we only get one item - # in the items list, due to the nature of the test. self.assertEqual( data, {