当前位置: 首页>>代码示例>>Python>>正文


Python Group.get_or_create方法代码示例

本文整理汇总了Python中grouper.models.group.Group.get_or_create方法的典型用法代码示例。如果您正苦于以下问题:Python Group.get_or_create方法的具体用法?Python Group.get_or_create怎么用?Python Group.get_or_create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在grouper.models.group.Group的用法示例。


在下文中一共展示了Group.get_or_create方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: run

# 需要导入模块: from grouper.models.group import Group [as 别名]
# 或者: from grouper.models.group.Group import get_or_create [as 别名]
 def run(self, session, **kwargs):
     if kwargs.get('group'):
         Group.get_or_create(session, groupname=groupname)
         session.commit()
     elif kwargs.get('key') == 'valuewith=':
         User.get_or_create(session, username=other_username)
         session.commit()
     else:
         User.get_or_create(session, username=username)
         session.commit()
开发者ID:santoshankr,项目名称:grouper,代码行数:12,代码来源:test_grouper_ctl.py

示例2: groups

# 需要导入模块: from grouper.models.group import Group [as 别名]
# 或者: from grouper.models.group.Group import get_or_create [as 别名]
def groups(session):
    groups = {
        groupname: Group.get_or_create(session, groupname=groupname)[0]
        for groupname in ("team-sre", "tech-ops", "team-infra", "all-teams", "serving-team",
                          "security-team", "auditors", "sad-team", "audited-team", "user-admins",
                          "group-admins")
    }
    session.commit()
    return groups
开发者ID:santoshankr,项目名称:grouper,代码行数:11,代码来源:fixtures.py

示例3: test_group_disable

# 需要导入模块: from grouper.models.group import Group [as 别名]
# 或者: from grouper.models.group.Group import get_or_create [as 别名]
def test_group_disable(session, groups, http_client, base_url):  # noqa: F811
    # create global audit
    fe_url = url(base_url, "/audits/create")
    ends_at = date.today() + timedelta(days=7)
    resp = yield http_client.fetch(
        fe_url,
        method="POST",
        headers={"X-Grouper-User": "[email protected]"},
        body=urlencode({"ends_at": ends_at.strftime("%m/%d/%Y")}),
    )
    assert resp.code == 200

    serving_team, just_created = Group.get_or_create(session, groupname="serving-team")
    assert not just_created
    assert serving_team.audit
    assert not serving_team.audit.complete

    # disable with insufficient permissions
    fe_url = url(base_url, "/groups/serving-team/disable")
    with pytest.raises(HTTPError):
        resp = yield http_client.fetch(
            fe_url,
            method="POST",
            headers={"X-Grouper-User": "[email protected]"},
            body=urlencode({"name": "serving-team"}),
        )

    # disable
    fe_url = url(base_url, "/groups/serving-team/disable")
    resp = yield http_client.fetch(
        fe_url,
        method="POST",
        headers={"X-Grouper-User": "[email protected]"},
        body=urlencode({"name": "serving-team"}),
    )
    assert resp.code == 200

    serving_team, just_created = Group.get_or_create(session, groupname="serving-team")
    assert not just_created
    assert serving_team.audit
    assert serving_team.audit.complete, "disabling group should complete any outstanding audit"
开发者ID:dropbox,项目名称:grouper,代码行数:43,代码来源:groups_test.py

示例4: groups

# 需要导入模块: from grouper.models.group import Group [as 别名]
# 或者: from grouper.models.group.Group import get_or_create [as 别名]
def groups(session):
    groups = {
        groupname: Group.get_or_create(session, groupname=groupname)[0]
        for groupname in (
            "team-sre",
            "tech-ops",
            "team-infra",
            "all-teams",
            "serving-team",
            "security-team",
            "auditors",
            "sad-team",
            "audited-team",
            "user-admins",
            "group-admins",
            "permission-admins",
        )
    }
    groups_with_emails = ("team-sre", "serving-team", "security-team")
    for group in groups_with_emails:
        groups[group].email_address = "{}@a.co".format(group)
    session.commit()
    return groups
开发者ID:dropbox,项目名称:grouper,代码行数:25,代码来源:fixtures.py

示例5: test_auditor_promotion

# 需要导入模块: from grouper.models.group import Group [as 别名]
# 或者: from grouper.models.group.Group import get_or_create [as 别名]
def test_auditor_promotion(mock_nnp, mock_gagn, session, graph, permissions, users):  # noqa: F811
    """Test automatic promotion of non-auditor approvers

    We set up our own group/user/permission for testing instead of
    using the `standard_graph` fixture---retrofitting it to work for
    us and also not break existing tests is too cumbersome.

    So here are our groups:

    very-special-auditors:
      * user14

    group-1:
      * user11 (o)
      * user12
      * user13 (np-o)
      * user14 (o, a)

    group-2:
      * user13 (np-o)
      * user21 (o)
      * user22

    group-3:
      * user22 (o)
      * user12 (o)

    group-4:
      * user21 (np-o)
      * user41
      * user42 (o)
      * user43 (np-o)

    o: owner, np-o: no-permission owner, a: auditor

    group-1 and group-2 have the permission that we will enable
    auditing. group-4 will be a subgroup of group-1 and thus will
    inherit the audited permission from group-1.

    The expected outcome is: user11, user13, user21, user42, and
    user43 will be added to the auditors group.

    """
    settings = BackgroundSettings()
    set_global_settings(settings)

    #
    # set up our test part of the graph
    #

    # create groups
    AUDITED_GROUP = "audited"
    AUDITORS_GROUP = mock_gagn.return_value = "very-special-auditors"
    PERMISSION_NAME = "test-permission"
    all_groups = {
        groupname: Group.get_or_create(session, groupname=groupname)[0]
        for groupname in ("group-1", "group-2", "group-3", "group-4", AUDITORS_GROUP)
    }
    # create users
    users.update(
        {
            username + "@a.co": User.get_or_create(session, username=username + "@a.co")[0]
            for username in (
                "user11",
                "user12",
                "user13",
                "user14",
                "user21",
                "user22",
                "user23",
                "user41",
                "user42",
                "user43",
            )
        }
    )
    # create permissions
    permissions.update(
        {
            permission: get_or_create_permission(
                session, permission, description="{} permission".format(permission)
            )[0]
            for permission in [PERMISSION_NAME]
        }
    )
    # add users to groups
    for (groupname, username, role) in (
        ("group-1", "user11", "owner"),
        ("group-1", "user12", "member"),
        ("group-1", "user13", "np-owner"),
        ("group-1", "user14", "owner"),
        ("group-2", "user13", "np-owner"),
        ("group-2", "user21", "owner"),
        ("group-2", "user22", "member"),
        ("group-3", "user12", "owner"),
        ("group-3", "user22", "owner"),
        ("group-4", "user21", "np-owner"),
        ("group-4", "user41", "member"),
        ("group-4", "user42", "owner"),
        ("group-4", "user43", "np-owner"),
#.........这里部分代码省略.........
开发者ID:dropbox,项目名称:grouper,代码行数:103,代码来源:audit_test.py


注:本文中的grouper.models.group.Group.get_or_create方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。