Пример #1
0
 def test_raises_invalid_config(self):
     """Test that InvalidDockerizePipConfiguration is raised."""
     client = make_fake_client()
     with pytest.raises(InvalidDockerizePipConfiguration):
         dockerized_pip(os.getcwd(),
                        client=client,
                        docker_file='docker_file',
                        docker_image='docker_image',
                        runtime='runtime')
     with pytest.raises(InvalidDockerizePipConfiguration):
         dockerized_pip(os.getcwd(),
                        client=client,
                        docker_file='docker_file',
                        docker_image='docker_image')
     with pytest.raises(InvalidDockerizePipConfiguration):
         dockerized_pip(os.getcwd(),
                        client=client,
                        docker_file='docker_file',
                        runtime='runtime')
     with pytest.raises(InvalidDockerizePipConfiguration):
         dockerized_pip(os.getcwd(),
                        client=client,
                        docker_image='docker_image',
                        runtime='runtime')
     with pytest.raises(InvalidDockerizePipConfiguration):
         dockerized_pip(os.getcwd(), client=client)
Пример #2
0
 def test_raises_value_error_missing_dockerfile(self):
     """ValueError raised when provided Dockerfile is not found."""
     client = make_fake_client()
     with pytest.raises(ValueError) as excinfo:
         dockerized_pip(os.getcwd(),
                        client=client,
                        docker_file='not-a-Dockerfile')
     assert 'docker_file' in str(excinfo.value)
Пример #3
0
    def test_with_docker_image(self):
        """Test with docker_image provided."""
        client = make_fake_client()
        image = "alpine"
        dockerized_pip(os.getcwd(), client=client, docker_image=image)

        client.api.create_container.assert_called_with(
            detach=True, image=image, command=self.command, host_config=self.host_config
        )
        client.api.inspect_container.assert_called_with(FAKE_CONTAINER_ID)
        client.api.start.assert_called_with(FAKE_CONTAINER_ID)
        client.api.logs.assert_called_with(
            FAKE_CONTAINER_ID, stderr=True, stdout=True, stream=True, tail=0
        )
Пример #4
0
    def test_with_runtime(self):
        """Test with runtime provided."""
        client = make_fake_client()
        runtime = "python3.8"
        dockerized_pip(os.getcwd(), client=client, runtime=runtime)

        client.api.create_container.assert_called_with(
            detach=True,
            image="lambci/lambda:build-" + runtime,
            command=self.command,
            host_config=self.host_config,
        )
        client.api.inspect_container.assert_called_with(FAKE_CONTAINER_ID)
        client.api.start.assert_called_with(FAKE_CONTAINER_ID)
        client.api.logs.assert_called_with(
            FAKE_CONTAINER_ID, stderr=True, stdout=True, stream=True, tail=0
        )
Пример #5
0
    def test_with_docker_file(self):
        """Test with docker_file provided."""
        client = make_fake_client()
        with TempDirectory() as tmp_dir:
            docker_file = tmp_dir.write("Dockerfile", b"")
            dockerized_pip(os.getcwd(), client=client, docker_file=docker_file)

            client.api.build.assert_called_with(
                path=tmp_dir.path, dockerfile="Dockerfile", forcerm=True
            )
            client.api.create_container.assert_called_with(
                detach=True,
                image=FAKE_IMAGE_ID,
                command=self.command,
                host_config=self.host_config,
            )
            client.api.inspect_container.assert_called_with(FAKE_CONTAINER_ID)
            client.api.start.assert_called_with(FAKE_CONTAINER_ID)
            client.api.logs.assert_called_with(
                FAKE_CONTAINER_ID, stderr=True, stdout=True, stream=True, tail=0
            )
Пример #6
0
 def test_raises_value_error_runtime(self):
     """ValueError raised if runtime provided is not supported."""
     client = make_fake_client()
     with pytest.raises(ValueError) as excinfo:
         dockerized_pip(os.getcwd(), client=client, runtime='node')
     assert 'node' in str(excinfo.value)