def test_empty_result(mocker, app): """Don't call ipa.batch when there are no results""" ipa = mocker.Mock() ipa.group_find.return_value = {"result": []} with app.test_request_context("/?page_size=10"): result = paginated_find(ipa, Group) ipa.group_find.assert_called_once_with(pkey_only=True) ipa.batch.assert_not_called() assert len(result.items) == 0
def group(ipa, groupname): group = Group(group_or_404(ipa, groupname)) sponsor_form = AddGroupMemberForm(groupname=groupname) remove_form = RemoveGroupMemberForm(groupname=groupname) members = paginated_find(ipa, User, in_group=groupname, default_page_size=48) batch_methods = [{ "method": "user_find", "params": [[], { "uid": sponsorname, 'all': True }] } for sponsorname in group.sponsors] # Don't call remote batch method with an empty list if batch_methods: sponsors = [ User(u['result'][0]) for u in ipa.batch(a_methods=batch_methods)['results'] ] else: sponsors = [] # We can safely assume g.current_user exists after @with_ipa current_user_is_sponsor = g.current_user.username in group.sponsors return render_template( 'group.html', group=group, members=members, sponsors=sponsors, sponsor_form=sponsor_form, remove_form=remove_form, current_user_is_sponsor=current_user_is_sponsor, )
def groups(ipa): groups = paginated_find(ipa, Group, fasgroup=True) return render_template('groups.html', groups=groups)