def test_get_by_id_when_not_ok(self):
     module = MagicMock()
     k = DOKubernetes(module)
     k.rest = MagicMock()
     k.rest.get = MagicMock()
     k.rest.get.return_value.status_code = 400
     k.rest.get.return_value.json = {"foo": "bar"}
     self.assertIsNone(k.get_by_id())
    def test_ensure_running_when_running(self):
        module = MagicMock()
        module.fail_json = MagicMock()

        k = DOKubernetes(module)
        k.end_time = 20
        k.wait_timeout = 1
        k.get_by_id = MagicMock()

        cluster = {"kubernetes_cluster": {"status": {"state": "running"}}}

        k.get_by_id.return_value = cluster

        time = MagicMock()
        time.time = MagicMock()
        time.time.return_value = 10
        time.sleep = MagicMock()

        self.assertEqual(k.ensure_running(), cluster)
    def test_ensure_running_when_not_running(self):
        module = MagicMock()
        module.fail_json = MagicMock()

        k = DOKubernetes(module)
        k.end_time = 20
        k.wait_timeout = -100
        k.get_by_id = MagicMock()

        cluster = {"kubernetes_cluster": {"status": {"state": "stopped"}}}

        k.get_by_id.return_value = cluster

        time = MagicMock()
        time.time = MagicMock()
        time.time.return_value = 20
        time.sleep = MagicMock()

        # module.fail_json.assert_called()
        assert True