]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
pybind/mgr: add test cases for ErrorResponseHandler decorator
authorJohn Mulligan <jmulligan@redhat.com>
Mon, 23 May 2022 19:36:35 +0000 (15:36 -0400)
committerJohn Mulligan <jmulligan@redhat.com>
Tue, 23 Aug 2022 17:01:45 +0000 (13:01 -0400)
Signed-off-by: John Mulligan <jmulligan@redhat.com>
src/pybind/mgr/tests/test_object_format.py

index b09df8ce384705861636d8edbbfda914c46679fa..6a1215fac38ec3d429f9649cb56c4fc7329d6c90 100644 (file)
@@ -263,6 +263,13 @@ class DecoDemo:
     def gamma_three(self, size: int = 0) -> Dict[str, Any]:
         return {"name": "funnystuff", "size": size}
 
+    @CLICommand("z_err", perm="rw")
+    @object_format.ErrorResponseHandler()
+    def z_err(self, name: str = "default") -> Tuple[int, str, str]:
+        if "z" in name:
+            raise object_format.ErrorResponse(f"{name} bad")
+        return 0, name, ""
+
 
 @pytest.mark.parametrize(
     "prefix, args, response",
@@ -386,9 +393,29 @@ class DecoDemo:
                 "Unknown format name: toml",
             ),
         ),
+        # ---
+        (
+            "z_err",
+            {"name": "foobar"},
+            (
+                0,
+                "foobar",
+                "",
+            ),
+        ),
+        # ---
+        (
+            "z_err",
+            {"name": "zamboni"},
+            (
+                -22,
+                "",
+                "zamboni bad",
+            ),
+        ),
     ],
 )
-def test_cli_command_responder(prefix, args, response):
+def test_cli_with_decorators(prefix, args, response):
     dd = DecoDemo()
     assert CLICommand.COMMANDS[prefix].call(dd, args, None) == response