def test_repository_is_replaced(self, monkeypatch): task = PullImage(repository="original") api = MagicMock() monkeypatch.setattr("docker.APIClient", api) task.run(repository="test") assert api.return_value.pull.call_args[1]["repository"] == "test"
def test_repository_run_value_is_used(self, monkeypatch): task = PullImage() api = MagicMock() monkeypatch.setattr("prefect.tasks.docker.containers.docker.APIClient", api) task.run(repository="test") assert api.return_value.pull.call_args[1]["repository"] == "test"
def test_returns_pull_value_with_stream_logs(self, monkeypatch, caplog): task = PullImage() api = MagicMock() expected_docker_output = [ { "status": "Pulling" }, { "status": "Digest" }, { "status": "Test" }, ] expected_result = ( "{'status': 'Pulling'}\n{'status': 'Digest'}\n{'status': 'Test'}") api.return_value.pull = MagicMock(return_value=expected_docker_output) monkeypatch.setattr("docker.APIClient", api) with caplog.at_level(logging.DEBUG, logger=task.logger.name): result = task.run(repository="original", stream_logs=True) assert result == expected_result
def test_returns_pull_value(self, monkeypatch, caplog): task = PullImage(repository="original") api = MagicMock() expected_docker_output = "A real output from docker's api" api.return_value.pull = MagicMock(return_value=expected_docker_output) monkeypatch.setattr("docker.APIClient", api) with caplog.at_level(logging.DEBUG, logger=task.logger.name): result = task.run(repository="test") assert result == expected_docker_output
def test_invalid_repository_raises_error(self): task = PullImage() with pytest.raises(ValueError): task.run(repository=None)
def test_empty_repository_raises_error(self): task = PullImage() with pytest.raises(ValueError): task.run()