def get(self, request, format=None): """ Identity mapping API --- # YAML type: name: required: true type: string url: required: false type: url created_at: required: true type: string format: date-time parameters: - name: wants description: attributes returned required: false type: string paramType: query - name: [attribute] description: the attribute to query against required: true type: string paramType: query responseMessages: - code: 200 message: success """ params = request.query_params users = [] retrieved_fields = [] key_names = PluginManager.get_all_needs() wants = params.getlist('wants', ['user_id']) for key_name in [key_name for key_name in key_names if key_name in params]: keys = params.getlist(key_name) users.extend([{key_name: key_value} for key_value in keys]) retrieved_fields.append(key_name) providers = select_providers(PluginManager.get_all_providers(), wants, [key_name]) providers = sort_by_dependencies(providers, [key_name]) for provider in providers: load_by = provider.can_load(retrieved_fields) if load_by: logger.info('Using {} with {}'.format(provider, retrieved_fields)) users = merge_users( users, provider.load(**{load_by: [user[load_by] for user in users if load_by in user]})) retrieved_fields.extend(provider.get_provides()) # filter out unwanted attributes and use None for missing ones default_user_dict = {key: None for key in wants} users = [merge_dicts(default_user_dict, {key: value for key, value in user.iteritems() if key in wants}) for user in users] return Response(users)
def test_select_providers(self, providers, wants, given, expected): actual = select_providers(providers, wants, given) self.assertSetEqual(actual, expected)