def test_image_and_repository_init_value_is_used(self, monkeypatch): task = TagImage(image="test", repository="test") api = MagicMock() monkeypatch.setattr("docker.APIClient", api) task.run() assert api.return_value.tag.call_args[1]["image"] == "test" assert api.return_value.tag.call_args[1]["repository"] == "test"
def test_image_and_repository_is_replaced(self, monkeypatch): task = TagImage(image="original", repository="original") api = MagicMock() monkeypatch.setattr("prefect.tasks.docker.containers.docker.APIClient", api) task.run(image="test", repository="test") assert api.return_value.tag.call_args[1]["image"] == "test" assert api.return_value.tag.call_args[1]["repository"] == "test"
def test_returns_tag_value(self, monkeypatch, caplog): image = "an image thats going to get tagged" task = TagImage(image=image) expected_docker_output = image api = MagicMock() api.return_value.tag = MagicMock(return_value=expected_docker_output) monkeypatch.setattr("docker.APIClient", api) with caplog.at_level(logging.DEBUG, logger=task.logger.name): actual = task.run(image=image, repository="test") assert actual == expected_docker_output
def test_empty_initialization(self): task = TagImage() assert not task.image assert not task.repository assert not task.tag assert not task.force assert task.docker_server_url == "unix:///var/run/docker.sock"
def test_doesnt_log_on_param_failure(self, monkeypatch, caplog): task = TagImage() api = MagicMock() monkeypatch.setattr("docker.APIClient", api) self.assert_doesnt_log_on_param_failure(task, caplog)
def test_logs_once_on_docker_api_failure(self, monkeypatch, caplog): task = TagImage(image="test", repository="test") api = MagicMock() tag_mock = MagicMock( side_effect=docker.errors.DockerException("Docker specific error")) api.return_value.tag = tag_mock monkeypatch.setattr("docker.APIClient", api) self.assert_logs_once_on_docker_api_failure(task, caplog)
def test_logs_twice_on_success(self, monkeypatch, caplog): task = TagImage(image="test", repository="test") api = MagicMock() monkeypatch.setattr("docker.APIClient", api) tag = "test tag" image = "test image" repository = "test repo" self.assert_logs_twice_on_success(task, caplog)
def test_filled_initialization(self): task = TagImage( image="test", repository="test", tag="test", force=True, docker_server_url="test", ) assert task.image == "test" assert task.repository == "test" assert task.tag == "test" assert task.force is True assert task.docker_server_url == "test"
def test_invalid_image_raises_error(self): task = TagImage() with pytest.raises(ValueError): task.run(image=None)
def test_empty_image_raises_error(self): task = TagImage() with pytest.raises(ValueError): task.run()