def expand_scopes(scope_str, user, group=None, share_with=None):
    """utility to expand scopes used in parametrized tests

    Turns "read:users!user=USER,shares!group=SHARE_WITH"
    into
        [
            "read:users!user=username",
            "shares!group=groupname",
        ]
    """
    scopes = []
    replacements = {}

    def _get_name(str_or_obj):
        """Allow a string name or an object with a name attribute

        string names are used for tests where something doesn't exist
        """
        if isinstance(str_or_obj, str):
            return str_or_obj
        else:
            return str_or_obj.name

    username = _get_name(user)
    replacements["USER"] = username
    replacements["SERVER"] = username + "/"
    if group:
        replacements["GROUP"] = _get_name(group)
    if share_with:
        replacements["SHARE_WITH"] = _get_name(share_with)
    for scope in scope_str.split(","):
        for a, b in replacements.items():
            scope = scope.replace(a, b)
        scopes.append(scope)
    return scopes
utility to expand scopes used in parametrized tests

Turns "read:users!user=USER,shares!group=SHARE_WITH"
into
[
"read:users!user=username",
"shares!group=groupname",
]
jupyterhub/tests/test_shares.py