Esempio n. 1
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"
Esempio n. 2
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"
Esempio n. 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"
Esempio n. 4
0
    def test_logs_twice_on_success(self, monkeypatch, caplog):
        path = "test path"
        task = BuildImage(path=path)

        api = MagicMock()
        monkeypatch.setattr("docker.APIClient", api)
        self.assert_logs_twice_on_success(task, caplog)
Esempio n. 5
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)
Esempio n. 6
0
    def test_doesnt_log_on_param_failure(self, monkeypatch, caplog):
        task = BuildImage()
        api = MagicMock()

        monkeypatch.setattr("prefect.tasks.docker.containers.docker.APIClient",
                            api)
        self.assert_doesnt_log_on_param_failure(task, caplog)
Esempio n. 7
0
 def test_empty_initialization(self):
     task = BuildImage()
     assert not task.path
     assert not task.tag
     assert not task.nocache
     assert task.rm
     assert not task.forcerm
     assert task.docker_server_url == "unix:///var/run/docker.sock"
Esempio n. 8
0
    def test_logs_once_on_docker_api_failure(self, monkeypatch, caplog):

        task = BuildImage(path="test")
        api = MagicMock()

        build_mock = MagicMock(
            side_effect=docker.errors.DockerException("Docker specific error"))

        api.return_value.build = build_mock

        monkeypatch.setattr("docker.APIClient", api)
        self.assert_logs_once_on_docker_api_failure(task, caplog)
Esempio n. 9
0
 def test_filled_initialization(self):
     task = BuildImage(
         path="test",
         tag="test",
         nocache=True,
         rm=False,
         forcerm=True,
         docker_server_url="test",
     )
     assert task.path == "test"
     assert task.tag == "test"
     assert task.nocache is True
     assert not task.rm
     assert task.forcerm is True
     assert task.docker_server_url == "test"
Esempio n. 10
0
 def test_invalid_path_raises_error(self):
     task = BuildImage()
     with pytest.raises(ValueError):
         task.run(path=None)
Esempio n. 11
0
 def test_empty_path_raises_error(self):
     task = BuildImage()
     with pytest.raises(ValueError):
         task.run()