예제 #1
0
    def test_init(self):
        """``dockerpty.pty`` RunOperation init requires the docker client and container"""
        fake_client = MagicMock()
        fake_container = MagicMock()

        run_operation = pty.RunOperation(fake_client, fake_container)

        self.assertTrue(isinstance(run_operation, pty.RunOperation))
예제 #2
0
    def test_sockets(self):
        """``dockerpty.pty`` RunOperation 'sockets' returns a map object"""
        fake_client = MagicMock()
        fake_container = MagicMock()
        run_operation = pty.RunOperation(fake_client, fake_container)

        answer = run_operation.sockets()

        self.assertTrue(isinstance(answer, map))
예제 #3
0
    def test_israw(self):
        """``dockerpty.pty`` RunOperation 'israw' returns a boolean"""
        fake_client = MagicMock()
        fake_container = MagicMock()
        run_operation = pty.RunOperation(fake_client, fake_container)
        run_operation.info = lambda: {"Config": {"Tty": True}}

        answer = run_operation.israw()

        self.assertTrue(isinstance(answer, bool))
예제 #4
0
    def test_start_starts(self):
        """``dockerpty.pty`` RunOperation 'start' runs the container if needed"""
        fake_client = MagicMock()
        fake_container = MagicMock()
        run_operation = pty.RunOperation(fake_client, fake_container)
        run_operation.info = lambda: {'State': {'Running': False}}
        run_operation.sockets = lambda: (1, 2, 3)

        pumps = run_operation.start()

        self.assertTrue(fake_client.start.called)
예제 #5
0
    def test_start(self):
        """``dockerpty.pty`` RunOperation 'start' returns a list of io.Pumps"""
        fake_client = MagicMock()
        fake_container = MagicMock()
        run_operation = pty.RunOperation(fake_client, fake_container)

        pumps = run_operation.start()
        all_pumps = all([x for x in pumps if isinstance(x, io.Pump)])

        self.assertTrue(all_pumps)
        self.assertTrue(len(pumps) > 0)
예제 #6
0
    def test_resize(self):
        """``dockerpty.pty`` RunOperation 'resize' resizes the container's PTY"""
        fake_client = MagicMock()
        fake_container = MagicMock()
        run_operation = pty.RunOperation(fake_client, fake_container)

        run_operation.resize(height=3, width=5)
        _, the_kwargs = fake_client.resize.call_args
        expected_kwargs = {'height': 3, 'width': 5}

        self.assertEqual(the_kwargs, expected_kwargs)
예제 #7
0
    def test_info(self):
        """```dockerpty.pty`` RunOperation 'info' inspects the container"""
        fake_client = MagicMock()
        fake_container = MagicMock()
        run_operation = pty.RunOperation(fake_client, fake_container)

        run_operation.info()
        the_args, _ = fake_client.inspect_container.call_args
        expected_args = (fake_container, )

        self.assertTrue(fake_client.inspect_container.called)
        self.assertEqual(the_args, expected_args)
예제 #8
0
    def test_sockets_missing(self):
        """``dockerpty.pty`` RunOperation 'sockets' uses an io.Demuxer if the container has no TTY"""
        fake_client = MagicMock()
        fake_container = MagicMock()
        run_operation = pty.RunOperation(fake_client, fake_container)
        run_operation.info = lambda: {
            'Config': {
                'Tty': False,
                'AttachStdin': False,
                'AttachStdout': False,
                'AttachStderr': False
            }
        }

        output = list(run_operation.sockets())
        expected = [None, None, None]

        self.assertEqual(output, expected)
예제 #9
0
    def test_sockets_demuxer(self):
        """``dockerpty.pty`` RunOperation 'sockets' uses an io.Demuxer if the container has no TTY"""
        fake_client = MagicMock()
        fake_container = MagicMock()
        run_operation = pty.RunOperation(fake_client, fake_container)
        run_operation.info = lambda: {
            'Config': {
                'Tty': False,
                'AttachStdin': MagicMock(),
                'AttachStdout': MagicMock(),
                'AttachStderr': MagicMock()
            }
        }

        things = list(run_operation.sockets())
        demuxers = [x for x in things if isinstance(x, io.Demuxer)]

        self.assertTrue(all(demuxers))
        self.assertEqual(len(demuxers), 3)  # 1 for each stream