]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/smb: add unit tests for InvalidObjectTypeFieldError handling 68010/head
authorJohn Mulligan <jmulligan@redhat.com>
Tue, 24 Mar 2026 21:49:41 +0000 (17:49 -0400)
committerJohn Mulligan <jmulligan@redhat.com>
Wed, 25 Mar 2026 21:05:55 +0000 (17:05 -0400)
Add unit tests to check for InvalidObjectTypeFieldError being raised
correctly. InvalidObjectTypeFieldError was added in the previous commit.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
src/pybind/mgr/smb/tests/test_resourcelib.py

index 0878fa767a44a522f645f57d5bb580fe8ca86306..c6e0ce695097936a7d759ae3d9f3569cc6b0506f 100644 (file)
@@ -271,6 +271,7 @@ class BigBiz:
     address: List[str]
     ceo: Worker
     units: Optional[List[Unit]] = None
+    departments: Optional[Dict[str, str]] = None
 
 
 @smb.resourcelib.resource('smallbiz')
@@ -449,6 +450,54 @@ def test_explicit_none_in_data():
         'address': ['1 MegaLo Drive', 'Mango', 'TX', '22020'],
         'ceo': {'name': 'D. B. Bawes', 'age': 61},
         'units': None,
+        'departments': {
+            'marketing': 'Tells stuff',
+            'sales': 'Sells stuff',
+        },
     }
     obj = BigBiz._resource_config.object_from_simplified(data)
     assert obj.units is None
+
+
+def test_invalid_str_in_list_field():
+    data = {
+        'resource_type': 'smallbiz',
+        'name': 'Le Shoppe',
+        'address': '12 Fashion Way, Urbia  WA  01209',
+        'people': [
+            {'name': 'Madelyn', 'age': 39},
+            {'age': 39},
+        ],
+    }
+    with pytest.raises(smb.resourcelib.InvalidObjectTypeFieldError):
+        smb.resourcelib.load(data)
+
+
+def test_invalid_dict_in_list_field():
+    data = {
+        'resource_type': 'smallbiz',
+        'name': 'Le Shoppe',
+        'address': {'nope': 'wrong'},
+        'people': [
+            {'name': 'Madelyn', 'age': 39},
+            {'age': 39},
+        ],
+    }
+    with pytest.raises(smb.resourcelib.InvalidObjectTypeFieldError):
+        smb.resourcelib.load(data)
+
+
+def test_invalid_list_in_dict_field():
+    data = {
+        'resource_type': 'bigbiz',
+        'name': 'MegaLoMart',
+        'address': ['1 MegaLo Drive', 'Mango', 'TX', '22020'],
+        'ceo': {'name': 'D. B. Bawes', 'age': 61},
+        'units': None,
+        'departments': [
+            {'marketing': 'Tells stuff'},
+            {'sales': 'Sells stuff'},
+        ],
+    }
+    with pytest.raises(smb.resourcelib.InvalidObjectTypeFieldError):
+        smb.resourcelib.load(data)