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

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

        task.run(image="test")
        assert api.return_value.remove_image.call_args[1]["image"] == "test"
示例#2
0
    def test_image_run_value_is_used(self, monkeypatch):
        task = RemoveImage()

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

        task.run(image="test")
        assert api.return_value.remove_image.call_args[1]["image"] == "test"
示例#3
0
    def test_doesnt_log_on_param_failure(self, monkeypatch, caplog):

        task = RemoveImage()

        api = MagicMock()
        monkeypatch.setattr("docker.APIClient", api)
        self.assert_doesnt_log_on_param_failure(task, caplog)
示例#4
0
    def test_logs_twice_on_success(self, monkeypatch, caplog):

        image = "test image"
        task = RemoveImage(image=image)

        api = MagicMock()
        monkeypatch.setattr("docker.APIClient", api)
        self.assert_logs_twice_on_success(task, caplog)
示例#5
0
    def test_logs_once_on_docker_api_failure(self, monkeypatch, caplog):

        task = RemoveImage(image="test")

        api = MagicMock()
        remove_mock = MagicMock(
            side_effect=docker.errors.DockerException("Docker specific error"))
        api.return_value.remove_image = remove_mock
        monkeypatch.setattr("docker.APIClient", api)
        self.assert_logs_once_on_docker_api_failure(task, caplog)
示例#6
0
 def test_invalid_image_raises_error(self):
     task = RemoveImage()
     with pytest.raises(ValueError):
         task.run(image=None)
示例#7
0
 def test_empty_image_raises_error(self):
     task = RemoveImage()
     with pytest.raises(ValueError):
         task.run()
示例#8
0
 def test_filled_initialization(self):
     task = RemoveImage(image="test", force=True, docker_server_url="test")
     assert task.image == "test"
     assert task.force is True
     assert task.docker_server_url == "test"
示例#9
0
 def test_empty_initialization(self):
     task = RemoveImage()
     assert not task.image
     assert not task.force
     assert task.docker_server_url == "unix:///var/run/docker.sock"