From 6f0d9e2795350c17d55ce4f8fae8dd31e2d2dee4 Mon Sep 17 00:00:00 2001 From: John Mulligan Date: Tue, 24 Mar 2026 17:49:41 -0400 Subject: [PATCH] mgr/smb: add unit tests for InvalidObjectTypeFieldError handling Add unit tests to check for InvalidObjectTypeFieldError being raised correctly. InvalidObjectTypeFieldError was added in the previous commit. Signed-off-by: John Mulligan --- src/pybind/mgr/smb/tests/test_resourcelib.py | 49 ++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/src/pybind/mgr/smb/tests/test_resourcelib.py b/src/pybind/mgr/smb/tests/test_resourcelib.py index 0878fa767a44..c6e0ce695097 100644 --- a/src/pybind/mgr/smb/tests/test_resourcelib.py +++ b/src/pybind/mgr/smb/tests/test_resourcelib.py @@ -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) -- 2.47.3