Пример #1
0
    def test_items(self):
        manager = self._app.container_manager
        manager.image = mock_coro_factory(Image())
        manager.find_containers = mock_coro_factory([
            DockerContainer(user="******",
                            mapping_id="whatever",
                            url_id="12345",
                            name="container",
                            image_name="image")
        ])

        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': ['12345', '12345'],
                'total': 2,
                'offset': 0,
                'items': {
                    '12345': {
                        'image_name': 'image',
                        'name': 'container',
                        'mapping_id': 'whatever'
                    }
                }
            })
Пример #2
0
    def test_delete_failure_reverse_proxy(self):
        self._app.container_manager.find_container = mock_coro_factory(
            DockerContainer(user="******")
        )
        self._app.reverse_proxy.unregister.side_effect = Exception("BOOM!")

        self.delete("/user/johndoe/api/v1/containers/found/",
                    httpstatus.NO_CONTENT)
Пример #3
0
    def test_delete_failure_stop_container(self):
        manager = self._app.container_manager
        manager.find_container = mock_coro_factory(
            DockerContainer(user="******")
        )
        manager.stop_and_remove_container = mock_coro_factory(
            side_effect=Exception("BOOM!"))

        self.delete("/user/johndoe/api/v1/containers/found/",
                    httpstatus.NO_CONTENT)
Пример #4
0
    def test_delete(self):
        self._app.container_manager.find_container = mock_coro_factory(
            DockerContainer(user="******"))

        self.delete("/user/johndoe/api/v1/containers/found/",
                    httpstatus.NO_CONTENT)
        self.assertTrue(self._app.reverse_proxy.unregister.called)

        self._app.container_manager.find_container = \
            mock_coro_factory(return_value=None)
        self.delete("/user/johndoe/api/v1/containers/notfound/",
                    httpstatus.NOT_FOUND)
Пример #5
0
    def test_retrieve(self):
        self._app.container_manager.find_container = mock_coro_factory(
            DockerContainer(user="******",
                            mapping_id="whatever",
                            name="container",
                            image_name="image"))
        _, data = self.get("/user/johndoe/api/v1/containers/found/",
                           httpstatus.OK)

        self.assertEqual(data["image_name"], "image")
        self.assertEqual(data["name"], "container")

        self._app.container_manager.find_container = \
            mock_coro_factory(return_value=None)
        self.get("/user/johndoe/api/v1/containers/notfound/",
                 httpstatus.NOT_FOUND)
Пример #6
0
    def test_create(self):
        with patch(
                "remoteappmanager"
                ".webapi"
                ".container"
                ".wait_for_http_server_2xx",
                new_callable=mock_coro_new_callable()):

            manager = self._app.container_manager
            manager.start_container = mock_coro_factory(
                DockerContainer(url_id="3456"))
            self.post(
                "/user/johndoe/api/v1/containers/",
                dict(mapping_id="cbaee2e8ef414f9fb0f1c97416b8aa6c",
                     configurables={"resolution": {
                         "resolution": "1024x768"
                     }}), httpstatus.CREATED)
Пример #7
0
    def test_post_start(self):
        with patch(
                "remoteappmanager"
                ".webapi"
                ".container"
                ".wait_for_http_server_2xx",
                new_callable=mock_coro_factory):
            self._app.container_manager.find_containers = \
                mock_coro_factory(return_value=[DockerContainer()])

            self.assertFalse(self._app.reverse_proxy.register.called)
            self.post(
                "/user/johndoe/api/v1/containers/", {
                    "mapping_id": "cbaee2e8ef414f9fb0f1c97416b8aa6c",
                    "configurables": {
                        "resolution": {
                            "resolution": "1024x768"
                        }
                    }
                })

            self.assertTrue(self._app.reverse_proxy.register.called)