Example #1
0
    def test_container_creation(self):
        creation = {'image': self.testimage}
        container = DockerContainer(self.cli, self.testcontainer, creation)
        with pytest.raises(RuntimeError):
            container.start()

        assert str(container) == "No id yet"

        build_instructions = {
            'fileobj': BytesIO(test_dockerfile.encode('utf-8')),
            'rm': True,
            'tag': self.testimage,
        }

        container = DockerContainer(self.cli, self.testcontainer, {}, {},
                                    build_instructions)
        container.start()

        container.start()
        time.sleep(0.01)
        assert container.is_started()

        assert str(container)

        # delete container and it should work again afterwards...

        container.stop(timeout=0)
        container.remove(v=True)

        assert not container.get_container()
        container.start()

        assert container.get_container()

        # make sure, that containers with subset of the name are not found
        sub_name_container = DockerContainer(self.cli,
                                             self.testcontainer[2:-2])
        assert not sub_name_container.get_container()

        container.start(restart=True, timeout=0)
        time.sleep(0.01)
        assert container.is_started()
Example #2
0
 def test_container_non_existent(self):
     container = DockerContainer(self.cli, 'test', {})
     with pytest.raises(RuntimeError):
         container.start()