Skip to content

Added AssertionException if no key 'connectors' was found in director… #620

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,18 @@ def test_additional_groups_config(modify_root_config, cli_args):
assert addl_groups[1]['source'] in options['additional_groups'][1]['source'].pattern


def test_directory_users_config(tmp_config_files, modify_root_config, cli_args):

# test that if connectors is not present or misspelled, an assertion exception is thrown
directory_users = {'not_connectors': {'ldap': 'connector-ldap.yml'}}
root_config_file = modify_root_config(['directory_users'], directory_users)
args = cli_args({'config_filename': root_config_file})
config_loader = ConfigLoader(args)
connector_name = 'ldap'
with pytest.raises(AssertionException):
config_loader.get_directory_connector_options(connector_name)


def test_twostep_config(tmp_config_files, modify_ldap_config, cli_args):
(root_config_file, ldap_config_file, _) = tmp_config_files
modify_ldap_config(['two_steps_lookup'], {})
Expand Down
2 changes: 1 addition & 1 deletion tests/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
def update_dict(d, ks, u):
k, ks = ks[0], ks[1:]
v = d.get(k)
if isinstance(v, collections.Mapping):
if ks and isinstance(v, collections.Mapping):
d[k] = update_dict(v, ks, u)
else:
d[k] = u
Expand Down
3 changes: 2 additions & 1 deletion user_sync/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,8 @@ def get_directory_connector_options(self, connector_name):
"""
options = {}
connectors_config = self.get_directory_connector_configs()

if connectors_config is None:
raise AssertionException("Missing key 'connectors' in directory_users")
if connector_name != 'csv' and connector_name not in connectors_config.value:
raise AssertionException("Config file must be specified for connector type :: '{}'".format(connector_name))

Expand Down