示例#1
0
    def test_image_is_replaced(self, monkeypatch):
        task = BuildImage(path="original")

        api = MagicMock()
        monkeypatch.setattr("docker.APIClient", api)

        task.run(path="test")
        assert api.return_value.build.call_args[1]["path"] == "test"
示例#2
0
    def test_path_init_value_is_used(self, monkeypatch):
        task = BuildImage(path="test")

        api = MagicMock()
        monkeypatch.setattr("docker.APIClient", api)

        task.run()
        assert api.return_value.build.call_args[1]["path"] == "test"
示例#3
0
    def test_image_run_value_is_used(self, monkeypatch):
        task = BuildImage()

        api = MagicMock()
        monkeypatch.setattr("prefect.tasks.docker.containers.docker.APIClient",
                            api)

        task.run(path="test")
        assert api.return_value.build.call_args[1]["path"] == "test"
示例#4
0
    def test_image_cleans_docker_output(self, monkeypatch):
        task = BuildImage()

        output = [
            b'{"stream":"Step 1/2 : FROM busybox"}\r\n{"stream":"\\n"}\r\n',
            b'{"stream":" ---\\u003e db8ee88ad75f\\n"}\r\n{"stream":"Step 2/2 : CMD [\\"echo\\", \\"foo\\"]"}\r\n{"stream":"\\n"}\r\n',
            b'{"stream":" ---\\u003e Using cache\\n"}\r\n{"stream":" ---\\u003e 0be8805a7d08\\n"}\r\n{"aux":{"ID":"sha256:0be8805a7d0828bbfcd876e8aa65cf6ee1ee016117a2d3f3aa4f21835ee1c69f"}}\r\n{"stream":"Successfully built 0be8805a7d08\\n"}\r\n',
        ]
        api = MagicMock()
        api.return_value.build.return_value = output
        monkeypatch.setattr("docker.APIClient", api)

        return_value = task.run(path="test")
        assert all(isinstance(value, dict) for value in return_value)
        assert all(len(value) >= 1 for value in return_value)
        assert all(key for value in return_value for key in value)
示例#5
0
 def test_invalid_path_raises_error(self):
     task = BuildImage()
     with pytest.raises(ValueError):
         task.run(path=None)
示例#6
0
 def test_empty_path_raises_error(self):
     task = BuildImage()
     with pytest.raises(ValueError):
         task.run()