本文整理汇总了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())
示例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)
示例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())
示例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)