Skip to content

Commit

Permalink
chore: improve error message on invalid setting names for GetUserSett…
Browse files Browse the repository at this point in the history
…ings
  • Loading branch information
Erik Cederstrand committed Sep 5, 2023
1 parent 5937a48 commit d3bd51a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions exchangelib/autodiscover/protocol.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from ..properties import UserResponse
from ..protocol import BaseProtocol
from ..services import GetUserSettings
from ..transport import get_autodiscover_authtype
Expand Down Expand Up @@ -45,6 +46,11 @@ def get_user_settings(self, user, settings=None):
"external_ews_url",
"ews_supported_schemas",
]
for setting in settings:
if setting not in UserResponse.SETTINGS_MAP:
raise ValueError(
f"Setting {setting!r} is invalid. Valid options are: {sorted(UserResponse.SETTINGS_MAP.keys())}"
)
return GetUserSettings(protocol=self).get(users=[user], settings=settings)

def dummy_xml(self):
Expand Down
8 changes: 8 additions & 0 deletions tests/test_autodiscover.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,14 @@ def test_get_user_settings(self, m):
ad.discover()
p = autodiscover_cache[ad._cache_key]

# Test invalid settings
with self.assertRaises(ValueError) as e:
p.get_user_settings(user=None, settings=["XXX"])
self.assertIn(
"Setting 'XXX' is invalid. Valid options are:",
e.exception.args[0],
)

# Test invalid email
invalid_email = get_random_email()
r = p.get_user_settings(user=invalid_email)
Expand Down

0 comments on commit d3bd51a

Please sign in to comment.