示例#1
0
    def test_container_id_is_replaced(self, monkeypatch):
        task = StopContainer(container_id="original")

        api = MagicMock()
        monkeypatch.setattr("docker.APIClient", api)

        task.run(container_id="test")
        assert api.return_value.stop.call_args[1]["container"] == "test"
示例#2
0
    def test_container_id_run_value_is_used(self, monkeypatch):
        task = StopContainer()

        api = MagicMock()
        monkeypatch.setattr("prefect.tasks.docker.containers.docker.APIClient",
                            api)

        task.run(container_id="test")
        assert api.return_value.stop.call_args[1]["container"] == "test"
示例#3
0
    def test_doesnt_log_on_param_failure(self, monkeypatch, caplog):

        task = StopContainer()
        api = MagicMock()
        monkeypatch.setattr("docker.APIClient", api)

        self.assert_doesnt_log_on_param_failure(task, caplog)
示例#4
0
    def test_logs_twice_on_success(self, monkeypatch, caplog):

        task = StopContainer(container_id="test")
        api = MagicMock()

        monkeypatch.setattr("docker.APIClient", api)

        self.assert_logs_twice_on_success(task, caplog)
示例#5
0
    def test_logs_once_on_docker_api_failure(self, monkeypatch, caplog):

        task = StopContainer(container_id="original")

        api = MagicMock()
        stop_container_mock = MagicMock(
            side_effect=docker.errors.DockerException(
                "A docker specific exception"))
        api.return_value.stop = stop_container_mock
        monkeypatch.setattr("docker.APIClient", api)

        self.assert_logs_once_on_docker_api_failure(task, caplog)
示例#6
0
 def test_invalid_container_id_raises_error(self):
     task = StopContainer()
     with pytest.raises(ValueError):
         task.run(container_id=None)
示例#7
0
 def test_empty_container_id_raises_error(self):
     task = StopContainer()
     with pytest.raises(ValueError):
         task.run()
示例#8
0
 def test_filled_initialization(self):
     task = StopContainer(container_id="test", docker_server_url="test")
     assert task.container_id == "test"
     assert task.docker_server_url == "test"
示例#9
0
 def test_empty_initialization(self):
     task = StopContainer()
     assert not task.container_id
     assert task.docker_server_url == "unix:///var/run/docker.sock"