def test_repository_is_replaced(self, monkeypatch): task = PushImage(repository="original") api = MagicMock() monkeypatch.setattr("docker.APIClient", api) task.run(repository="test") assert api.return_value.push.call_args[1]["repository"] == "test"
def test_repository_run_value_is_used(self, monkeypatch): task = PushImage() api = MagicMock() monkeypatch.setattr("prefect.tasks.docker.containers.docker.APIClient", api) task.run(repository="test") assert api.return_value.push.call_args[1]["repository"] == "test"
def test_returns_push_value(self, monkeypatch, caplog): task = PushImage(repository="original") api = MagicMock() expected_docker_output = "An example push API response" api.return_value.push = 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_doesnt_log_on_param_failure(self, monkeypatch, caplog): task = PushImage() 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): repository = "test repo" task = PushImage(repository=repository) api = MagicMock() monkeypatch.setattr("docker.APIClient", api) self.assert_logs_twice_on_success(task, caplog)
def test_filled_initialization(self): task = PushImage(repository="test", tag="test", docker_server_url="test") assert task.repository == "test" assert task.tag == "test" assert task.docker_server_url == "test"
def test_logs_once_on_docker_api_failure(self, monkeypatch, caplog): repository = "test repo" task = PushImage(repository=repository) api = MagicMock() push_mock = MagicMock( side_effect=docker.errors.DockerException("Docker specific error")) api.return_value.push = push_mock monkeypatch.setattr("docker.APIClient", api) self.assert_logs_once_on_docker_api_failure(task, caplog)
def test_invalid_repository_raises_error(self): task = PushImage() with pytest.raises(ValueError): task.run(repository=None)
def test_empty_repository_raises_error(self): task = PushImage() with pytest.raises(ValueError): task.run()
def test_empty_initialization(self): task = PushImage() assert not task.repository assert not task.tag assert task.docker_server_url == "unix:///var/run/docker.sock"