當前位置: 首頁>>代碼示例>>Python>>正文


Python Registry.flush方法代碼示例

本文整理匯總了Python中cloudhands.common.connectors.Registry.flush方法的典型用法代碼示例。如果您正苦於以下問題:Python Registry.flush方法的具體用法?Python Registry.flush怎麽用?Python Registry.flush使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在cloudhands.common.connectors.Registry的用法示例。


在下文中一共展示了Registry.flush方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_directory_attaches_to_membership

# 需要導入模塊: from cloudhands.common.connectors import Registry [as 別名]
# 或者: from cloudhands.common.connectors.Registry import flush [as 別名]
    def test_directory_attaches_to_membership(self):
        session = Registry().connect(sqlite3, ":memory:").session
        session.flush()
        archive = session.query(Archive).filter(
            Archive.name == "NITS").first()
        org = session.query(Organisation).one()
        subs = Subscription(
            uuid=uuid.uuid4().hex,
            model=cloudhands.common.__version__,
            organisation=org, provider=archive)
        user = User(handle=None, uuid=uuid.uuid4().hex)
        session.add_all((subs, user))
        session.commit()

        mship = Membership(
            uuid=uuid.uuid4().hex,
            model=cloudhands.common.__version__,
            organisation=org,
            role="user")
        now = datetime.datetime.utcnow()
        invite = session.query(MembershipState).filter(
            MembershipState.name == "created").one()
        mship.changes.append(
            Touch(artifact=mship, actor=user, state=invite, at=now))
        session.add(mship)
        session.commit()

        # illustrates user onboarding - membership gets decorated with
        # directory resources
        now = datetime.datetime.utcnow()
        for subs in org.subscriptions:
            if isinstance(subs.provider, Archive):
                d = Directory(
                    description="CEDA data archive",
                    mount_path="/{mount}/panfs/ceda")  # anticipates templating
                latest = mship.changes[-1]
                act = Touch(
                    artifact=mship, actor=user, state=latest.state, at=now)
                d.touch = act
                mship.changes.append(act)
                session.add(d)
                session.commit()

        # Check we can get at the resources from the membership
        self.assertIs(
            d,
            session.query(Resource).join(Touch).join(Membership).filter(
                Membership.id == mship.id).one())
開發者ID:cedadev,項目名稱:cloudhands-common,代碼行數:50,代碼來源:test_schema.py

示例2: test_ldapattribute_attaches_to_membership

# 需要導入模塊: from cloudhands.common.connectors import Registry [as 別名]
# 或者: from cloudhands.common.connectors.Registry import flush [as 別名]
    def test_ldapattribute_attaches_to_membership(self):

        def find_mships_without_attributes(session):
            return [
                mship for mship in session.query(Membership).join(Touch).join(
                State, State.name == "accepted").all()
                if not any(isinstance(r, LDAPAttribute)
                    for c in mship.changes for r in c.resources)]
                
        session = Registry().connect(sqlite3, ":memory:").session
        session.flush()
        user = session.query(User).one()
        org = session.query(Organisation).one()
        mship = Membership(
            uuid=uuid.uuid4().hex,
            model=cloudhands.common.__version__,
            organisation=org,
            role="user")
        accepted = session.query(MembershipState).filter(
            MembershipState.name == "accepted").one()
        now = datetime.datetime.utcnow()
        session.add(Touch(artifact=mship, actor=user, state=accepted, at=now))
        session.commit()

        remaining = find_mships_without_attributes(session)
        self.assertEqual(1, len(remaining))

        now = datetime.datetime.utcnow()
        act = Touch(artifact=mship, actor=user, state=accepted, at=now)
        resource = LDAPAttribute(
            dn="cn={},ou=jasmin,ou=Groups,o=hpc,dc=rl,dc=ac,dc=uk".format(org.name),
            key="memberUid", value=user.uuid, verb="add", touch=act)
        session.add(resource)
        session.commit()

        # Check we can get at the resources from the membership
        self.assertEqual(
            (mship, resource),
            session.query(Membership, LDAPAttribute).join(Touch).join(LDAPAttribute).filter(
                Membership.id == mship.id).one())

        remaining = find_mships_without_attributes(session)
        self.assertFalse(remaining, remaining)
開發者ID:cedadev,項目名稱:cloudhands-common,代碼行數:45,代碼來源:test_schema.py

示例3: test_group_is_parent_of_access

# 需要導入模塊: from cloudhands.common.connectors import Registry [as 別名]
# 或者: from cloudhands.common.connectors.Registry import flush [as 別名]
    def test_group_is_parent_of_access(self):
        session = Registry().connect(sqlite3, ":memory:").session
        session.flush()
        grp = session.query(Group).one()
        user = User(handle=None, uuid=uuid.uuid4().hex)
        session.add(user)
        session.commit()

        access = Access(
            uuid=uuid.uuid4().hex,
            model=cloudhands.common.__version__,
            group=grp,
            role="user")
        now = datetime.datetime.utcnow()
        created = session.query(AccessState).filter(
            AccessState.name == "created").one()
        act = Touch(artifact=access, actor=user, state=created, at=now)
        session.add(act)
        session.commit()

        # illustrates user onboarding - access gets decorated with
        # posix resource(s)
        latest = access.changes[-1]
        now = datetime.datetime.utcnow()
        gid = PosixGId(value=grp.number)
        act = Touch(
            artifact=access, actor=user, state=latest.state, at=now)
        gid.touch = act
        session.add(gid)
        session.commit()
    
        # Check we can get at the resource from the access
        self.assertIs(
            gid,
            session.query(Resource).join(Touch).join(Access).filter(
                Access.id == access.id).one())
開發者ID:cedadev,項目名稱:cloudhands-common,代碼行數:38,代碼來源:test_schema.py

示例4: open

# 需要導入模塊: from cloudhands.common.connectors import Registry [as 別名]
# 或者: from cloudhands.common.connectors.Registry import flush [as 別名]
        Organisation.name == args["organisation"]).first()
    if org is None:
        channel.send("No org named {}".format(args["organisation"]))
        channel.send(None)
    else:
        channel.send(("organisation", org.uuid, org.name))

        with open(args["path"], 'r') as input_:
            objs = rson.loads(input_.read())
            for obj in objs:
                try:
                    session.add(
                        CatalogueItem(
                            name=obj["name"].strip(),
                            description=obj["description"].strip(),
                            note=obj["note"].strip(),
                            logo="headless",
                            organisation=org,
                            natrouted=obj["natrouted"],
                            uuid=obj["uuid"],
                        ))
                    session.commit()
                    channel.send((obj["uuid"], obj["name"].strip()))
                except Exception as e:
                    channel.send(str(e))
                    session.rollback()
                finally:
                    session.flush()

    channel.send(None)
開發者ID:cedadev,項目名稱:cloudhands-ops,代碼行數:32,代碼來源:catalogadmin.py


注:本文中的cloudhands.common.connectors.Registry.flush方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。