Browse Source

Add QubesNoSuchPropertyError exception, expect it on invalid property

It inherits from AttributeError, so standard handling should just work.
Marek Marczykowski-Górecki 7 years ago
parent
commit
de2f23b9fe
2 changed files with 15 additions and 0 deletions
  1. 5 0
      qubesadmin/exc.py
  2. 10 0
      qubesadmin/tests/vm/properties.py

+ 5 - 0
qubesadmin/exc.py

@@ -91,6 +91,11 @@ class QubesPropertyValueError(QubesValueError):
     '''
 
 
+class QubesNoSuchPropertyError(QubesException, AttributeError):
+    '''Requested property does not exist
+    '''
+
+
 class QubesNotImplementedError(QubesException, NotImplementedError):
     '''Thrown at user when some feature is not implemented'''
 

+ 10 - 0
qubesadmin/tests/vm/properties.py

@@ -105,6 +105,16 @@ class TC_00_Properties(qubesadmin.tests.vm.VMTestCase):
         self.assertEqual(self.vm.property_is_default('prop1'), True)
         self.assertAllCalled()
 
+    def test_012_get_invalid(self):
+        self.app.expected_calls[
+            ('test-vm', 'admin.vm.property.Get', 'invalid', None)] = \
+            b'2\x00QubesNoSuchPropertyError\x00\x00Invalid property ' \
+            b'\'invalid\' on test-vm\x00'
+        with self.assertRaises(qubesadmin.exc.QubesNoSuchPropertyError):
+            self.vm.invalid
+        self.assertFalse(hasattr(self.vm, 'invalid'))
+        self.assertAllCalled()
+
     def test_020_set_str(self):
         self.app.expected_calls[
             ('test-vm', 'admin.vm.property.Set', 'prop1', b'value')] = \