Пример #1
0
    def test_container_id_is_replaced(self, monkeypatch):
        task = RemoveContainer(container_id="original")

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

        task.run(container_id="test")
        assert api.return_value.remove_container.call_args[1]["container"] == "test"
Пример #2
0
    def test_doesnt_log_on_param_failure(self, monkeypatch, caplog):

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

        self.assert_doesnt_log_on_param_failure(task, caplog)
Пример #3
0
    def test_logs_twice_on_success(self, monkeypatch, caplog):

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

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

        self.assert_logs_twice_on_success(task, caplog)
Пример #4
0
    def test_logs_once_on_docker_api_failure(self, monkeypatch, caplog):

        task = RemoveContainer(container_id="original")

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

        self.assert_logs_once_on_docker_api_failure(task, caplog)
Пример #5
0
 def test_invalid_container_id_raises_error(self):
     task = RemoveContainer()
     with pytest.raises(ValueError):
         task.run(container_id=None)
Пример #6
0
 def test_empty_container_id_raises_error(self):
     task = RemoveContainer()
     with pytest.raises(ValueError):
         task.run()
Пример #7
0
 def test_filled_initialization(self):
     task = RemoveContainer(container_id="test", docker_server_url="test")
     assert task.container_id == "test"
     assert task.docker_server_url == "test"
Пример #8
0
 def test_empty_initialization(self):
     task = RemoveContainer()
     assert not task.container_id
     assert task.docker_server_url == "unix:///var/run/docker.sock"