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"
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"
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)
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)
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)
def test_invalid_image_raises_error(self): task = RemoveImage() with pytest.raises(ValueError): task.run(image=None)
def test_empty_image_raises_error(self): task = RemoveImage() with pytest.raises(ValueError): task.run()
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"
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"