def pytest_generate_tests(metafunc): """ zipper auth_modes and auth_prov together and drop the nonsensical combos """ # TODO use supportability and provider type+version parametrization argnames = ['auth_mode', 'prov_key', 'user_type', 'auth_user'] argvalues = [] idlist = [] if 'auth_providers' not in auth_data: metafunc.parametrize(argnames, [ pytest.param( None, None, None, None, marks=pytest.mark.uncollect("auth providers data missing"))]) return # Holy nested loops, batman # go through each mode, then each auth type, and find auth providers matching that type # go through each user type for the given mode+auth_type (from param_maps above) # for each user type, find users in the yaml matching user_type an on the given auth provider # add parametrization for matching set of mode, auth_provider key, user_type, and user_dict # set id, use the username from userdict instead of an auto-generated "auth_user[\d]" ID for mode in test_param_maps.keys(): for auth_type in test_param_maps.get(mode, {}): eligible_providers = {key: prov_dict for key, prov_dict in iteritems(auth_data.auth_providers) if prov_dict.type == auth_type} for user_type in test_param_maps[mode][auth_type]['user_types']: for key, prov_dict in eligible_providers.items(): for user_dict in [u for u in auth_user_data(key, user_type) or []]: if user_type in prov_dict.get('user_types', []): argvalues.append((mode, key, user_type, user_dict)) idlist.append('-'.join([mode, key, user_type, user_dict.username])) metafunc.parametrize(argnames, argvalues, ids=idlist)
def ipa_user(temp_pod_appliance, ipa_auth_provider): """return a simple user object, see if it exists and delete it on teardown""" # Replace spaces with dashes in UPN type usernames for login compatibility appliance = temp_pod_appliance try: user_data = auth_user_data(ipa_auth_provider.key, 'uid')[0] except IndexError: pytest.fail("No auth users found") user = appliance.collections.users.simple_user( user_data.username, credentials[user_data.password].password, fullname=user_data.fullname or user_data.username) yield user appliance.server.login_admin()