示例#1
0
    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"
示例#2
0
    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"
示例#3
0
    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
示例#4
0
    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)
示例#5
0
    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)
示例#6
0
 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"
示例#7
0
    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)
示例#8
0
 def test_invalid_repository_raises_error(self):
     task = PushImage()
     with pytest.raises(ValueError):
         task.run(repository=None)
示例#9
0
 def test_empty_repository_raises_error(self):
     task = PushImage()
     with pytest.raises(ValueError):
         task.run()
示例#10
0
 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"