|
| 1 | +# Copyright 2025 Red Hat, Inc. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | +""" |
| 15 | +Test 'long_running_operation'. |
| 16 | +""" |
| 17 | + |
| 18 | +# isort: STDLIB |
| 19 | +import unittest |
| 20 | + |
| 21 | +# isort: THIRDPARTY |
| 22 | +import dbus |
| 23 | + |
| 24 | +# isort: FIRSTPARTY |
| 25 | +from dbus_python_client_gen import DPClientInvocationError |
| 26 | + |
| 27 | +# isort: LOCAL |
| 28 | +from stratis_cli._actions._utils import long_running_operation |
| 29 | + |
| 30 | + |
| 31 | +class LongRunningOperationTestCase(unittest.TestCase): |
| 32 | + """ |
| 33 | + Test long_running_operation error paths that don't show up in the sim |
| 34 | + engine. |
| 35 | + """ |
| 36 | + |
| 37 | + def test_raise_dbus_exception(self): |
| 38 | + """ |
| 39 | + Should succeed because it catches the distinguishing NoReply D-Bus |
| 40 | + error. |
| 41 | + """ |
| 42 | + |
| 43 | + def raises_error(_): |
| 44 | + raise DPClientInvocationError( |
| 45 | + "fake", "intf", None |
| 46 | + ) from dbus.exceptions.DBusException( |
| 47 | + name="org.freedesktop.DBus.Error.NoReply" |
| 48 | + ) |
| 49 | + |
| 50 | + self.assertIsNone(long_running_operation(raises_error)(None)) |
| 51 | + |
| 52 | + def test_no_dbus_exception(self): |
| 53 | + """ |
| 54 | + Should raise an exception that was previously raised. |
| 55 | + """ |
| 56 | + |
| 57 | + def raises_error(_): |
| 58 | + raise DPClientInvocationError("fake", "intf", None) |
| 59 | + |
| 60 | + with self.assertRaises(DPClientInvocationError): |
| 61 | + long_running_operation(raises_error)(None) |
0 commit comments