]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph-volume tests validate the new utils for prompts
authorAlfredo Deza <adeza@redhat.com>
Mon, 16 Jul 2018 13:23:14 +0000 (09:23 -0400)
committerAlfredo Deza <adeza@redhat.com>
Fri, 27 Jul 2018 21:48:01 +0000 (17:48 -0400)
Signed-off-by: Alfredo Deza <adeza@redhat.com>
(cherry picked from commit 2d988337a96fe6cc8fffb37e4641c86cd47e1139)

src/ceph-volume/ceph_volume/tests/util/test_util.py

index c165b57c8f9c538f8c88ae23f6f670d69c7c6092..da78336a714b3d8e74ede41d68caeaafc31efcfb 100644 (file)
@@ -16,3 +16,70 @@ class TestStrToInt(object):
         with pytest.raises(RuntimeError) as error:
             util.str_to_int("1.4GB")
         assert str(error.value) == "Unable to convert to integer: '1.4GB'"
+
+
+def true_responses(upper_casing=False):
+    if upper_casing:
+        return ['Y', 'YES', '']
+    return ['y', 'yes', '']
+
+
+def false_responses(upper_casing=False):
+    if upper_casing:
+        return ['N', 'NO']
+    return ['n', 'no']
+
+
+def invalid_responses():
+    return [9, 0.1, 'h', [], {}, None]
+
+
+class TestStrToBool(object):
+
+    @pytest.mark.parametrize('response', true_responses())
+    def test_trueish(self, response):
+        assert util.str_to_bool(response) is True
+
+    @pytest.mark.parametrize('response', false_responses())
+    def test_falseish(self, response):
+        assert util.str_to_bool(response) is False
+
+    @pytest.mark.parametrize('response', true_responses(True))
+    def test_trueish_upper(self, response):
+        assert util.str_to_bool(response) is True
+
+    @pytest.mark.parametrize('response', false_responses(True))
+    def test_falseish_upper(self, response):
+        assert util.str_to_bool(response) is False
+
+    @pytest.mark.parametrize('response', invalid_responses())
+    def test_invalid(self, response):
+        with pytest.raises(ValueError):
+            util.str_to_bool(response)
+
+
+class TestPromptBool(object):
+
+    @pytest.mark.parametrize('response', true_responses())
+    def test_trueish(self, response):
+        fake_input = lambda x: response
+        qx = 'what the what?'
+        assert util.prompt_bool(qx, _raw_input=fake_input) is True
+
+    @pytest.mark.parametrize('response', false_responses())
+    def test_falseish(self, response):
+        fake_input = lambda x: response
+        qx = 'what the what?'
+        assert util.prompt_bool(qx, _raw_input=fake_input) is False
+
+    def test_try_again_true(self):
+        responses = ['g', 'h', 'y']
+        fake_input = lambda x: responses.pop(0)
+        qx = 'what the what?'
+        assert util.prompt_bool(qx, _raw_input=fake_input) is True
+
+    def test_try_again_false(self):
+        responses = ['g', 'h', 'n']
+        fake_input = lambda x: responses.pop(0)
+        qx = 'what the what?'
+        assert util.prompt_bool(qx, _raw_input=fake_input) is False