From b6b842943da63d5f28e2d386a82c9f6aaf682d50 Mon Sep 17 00:00:00 2001 From: "Brian C. Lane" Date: Wed, 6 Nov 2019 11:57:00 -0800 Subject: [PATCH] composer-cli: Return int from handle_api_result not bool The callers, and the documentation, all expect int 0/1 to use as the exit status for the program. Not True/False, even though that works most of the time. (cherry picked from commit fad9b324f7fb42c90cc124d51c3f6ac584c4f8c1) Related: rhbz#1779301 --- src/composer/cli/utilities.py | 4 ++-- tests/composer/test_utilities.py | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/composer/cli/utilities.py b/src/composer/cli/utilities.py index 199ed095..c8c6f65b 100644 --- a/src/composer/cli/utilities.py +++ b/src/composer/cli/utilities.py @@ -73,9 +73,9 @@ def handle_api_result(result, show_json=False): # What's the rc? If status is present, use that # If not, use length of errors if "status" in result: - rc = bool(not result["status"]) + rc = int(not result["status"]) else: - rc = bool(len(result.get("errors", [])) > 0) + rc = int(len(result.get("errors", [])) > 0) # Caller should return if showing json, or status was present and False exit_now = show_json or ("status" in result and rc) diff --git a/tests/composer/test_utilities.py b/tests/composer/test_utilities.py index 7bc9c935..d2d02337 100644 --- a/tests/composer/test_utilities.py +++ b/tests/composer/test_utilities.py @@ -52,11 +52,13 @@ class CliUtilitiesTest(unittest.TestCase): """Test a result with no status and no error fields""" result = {"foo": "bar"} self.assertEqual(handle_api_result(result, show_json=False), (0, False)) + self.assertTrue(handle_api_result(result, show_json=False)[0] is 0) def test_api_result_2(self): """Test a result with errors=[{"id": INVALID_CHARS, "msg": "some error"}], and no status field""" result = {"foo": "bar", "errors": [{"id": INVALID_CHARS, "msg": "some error"}]} self.assertEqual(handle_api_result(result, show_json=False), (1, False)) + self.assertTrue(handle_api_result(result, show_json=False)[0] is 1) def test_api_result_3(self): """Test a result with status=True, and errors=[]"""