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


Python Registry.commit方法代码示例

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


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

示例1: test_name_unique_across_organisations

# 需要导入模块: from cloudhands.common.connectors import Registry [as 别名]
# 或者: from cloudhands.common.connectors.Registry import commit [as 别名]
    def test_name_unique_across_organisations(self):
        session = Registry().connect(sqlite3, ":memory:").session
        session.add(Organisation(
            name="BRANSTON", uuid=uuid.uuid4().hex))
        session.commit()
        orgs = session.query(Organisation).all()

        session.add_all((
            CatalogueItem(
                name="Blog Server",
                description="WordPress server VM",
                note=None,
                logo=None,
                organisation=orgs[0]
            ),
            CatalogueItem(
                name="Blog Server",
                description="Tumblr server VM",
                note=None,
                logo=None,
                organisation=orgs[1]
            )
        ))

        self.assertRaises(
            sqlalchemy.exc.IntegrityError, session.commit)
开发者ID:cedadev,项目名称:cloudhands-common,代码行数:28,代码来源:test_schema.py

示例2: setUp

# 需要导入模块: from cloudhands.common.connectors import Registry [as 别名]
# 或者: from cloudhands.common.connectors.Registry import commit [as 别名]
 def setUp(self):
     """ Populate test database"""
     session = Registry().connect(sqlite3, ":memory:").session
     session.add_all(
         State(fsm=RegistrationState.table, name=v)
         for v in RegistrationState.values)
     session.commit()
开发者ID:cedadev,项目名称:cloudhands-common,代码行数:9,代码来源:test_registration.py

示例3: test_names_are_not_unique

# 需要导入模块: from cloudhands.common.connectors import Registry [as 别名]
# 或者: from cloudhands.common.connectors.Registry import commit [as 别名]
 def test_names_are_not_unique(self):
     session = Registry().connect(sqlite3, ":memory:").session
     session.add_all((
         Label(name="Test", description="Test description"),
         Label(name="Test", description="Test description"),
     ))
     session.commit()
     self.assertEqual(2, session.query(Label).count())
开发者ID:cedadev,项目名称:cloudhands-common,代码行数:10,代码来源:test_schema.py

示例4: test_descriptions_may_be_omitted

# 需要导入模块: from cloudhands.common.connectors import Registry [as 别名]
# 或者: from cloudhands.common.connectors.Registry import commit [as 别名]
 def test_descriptions_may_be_omitted(self):
     session = Registry().connect(sqlite3, ":memory:").session
     session.add_all((
         Label(name="One"),
         Label(name="Two"),
     ))
     session.commit()
     self.assertEqual(2, session.query(Label).count())
开发者ID:cedadev,项目名称:cloudhands-common,代码行数:10,代码来源:test_schema.py

示例5: setUp

# 需要导入模块: from cloudhands.common.connectors import Registry [as 别名]
# 或者: from cloudhands.common.connectors.Registry import commit [as 别名]
 def setUp(self):
     """ Populate test database"""
     session = Registry().connect(sqlite3, ":memory:").session
     session.add_all(
         State(fsm=AccessState.table, name=v)
         for v in AccessState.values)
     session.add(
         Group(uuid=uuid.uuid4().hex, name="TestGroup", number=7654321))
     session.commit()
开发者ID:cedadev,项目名称:cloudhands-common,代码行数:11,代码来源:test_schema.py

示例6: test_shared_names

# 需要导入模块: from cloudhands.common.connectors import Registry [as 别名]
# 或者: from cloudhands.common.connectors.Registry import commit [as 别名]
 def test_shared_names(self):
     """ State names can be shared across FSMs """
     session = Registry().connect(sqlite3, ":memory:").session
     session.add_all([
         State(fsm="subscription", name="start"),
         State(fsm="host", name="start")])
     try:
         session.commit()
     except sqlalchemy.exc.IntegrityError as e:
         self.fail(e)
开发者ID:cedadev,项目名称:cloudhands-common,代码行数:12,代码来源:test_schema.py

示例7: test_using_touches

# 需要导入模块: from cloudhands.common.connectors import Registry [as 别名]
# 或者: from cloudhands.common.connectors.Registry import commit [as 别名]
    def test_using_touches(self):
        then = datetime.datetime.utcnow() - datetime.timedelta(seconds=1)
        session = Registry().connect(sqlite3, ":memory:").session

        user = User(handle=None, uuid=uuid.uuid4().hex)

        reg = Registration(
            uuid=uuid.uuid4().hex,
            model=cloudhands.common.__version__)

        preconfirm = session.query(RegistrationState).filter(
            RegistrationState.name == "pre_registration_inetorgperson").one()
        reg.changes.append(
            Touch(artifact=reg, actor=user, state=preconfirm, at=then))
        session.add(reg)
        session.commit()

        self.assertIs(reg.changes[0].state, preconfirm)
        self.assertIs(session.query(Touch).first().state, preconfirm)
        self.assertEqual(session.query(Touch).count(), 1)

        now = datetime.datetime.utcnow()
        self.assertTrue(now > then)
        valid = session.query(RegistrationState).filter(
            RegistrationState.name == "valid").one()
        act = Touch(artifact=reg, actor=user, state=valid, at=now)
        reg.changes.append(act)
        hash = BcryptedPassword(value="a" * 60, touch=act, provider=None)
        session.add(hash)
        session.commit()

        self.assertIs(reg.changes[1].state, valid)
        self.assertIs(
            session.query(Touch).order_by(Touch.at)[-1].state, valid)
        self.assertEqual(session.query(Touch).count(), 2)

        self.assertEqual(
            session.query(Touch).filter(Touch.at < now).first(),
            reg.changes[0])
        self.assertIs(
            session.query(Touch).filter(
                Touch.at > then).first(),
            reg.changes[1])

        reg.changes.sort(key=operator.attrgetter("at"), reverse=True)

        self.assertEqual(
            session.query(Touch).filter(
                Touch.at < now).first(),
            reg.changes[1])
        self.assertIs(
            session.query(Touch).filter(
                Touch.at > then).first(),
            reg.changes[0])
开发者ID:cedadev,项目名称:cloudhands-common,代码行数:56,代码来源:test_registration.py

示例8: test_using_touches

# 需要导入模块: from cloudhands.common.connectors import Registry [as 别名]
# 或者: from cloudhands.common.connectors.Registry import commit [as 别名]
    def test_using_touches(self):
        then = datetime.datetime.utcnow() - datetime.timedelta(seconds=1)
        session = Registry().connect(sqlite3, ":memory:").session

        user = User(handle=None, uuid=uuid.uuid4().hex)
        org = session.query(Organisation).one()

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

        self.assertIs(mship.changes[0].state, invite)
        self.assertIs(session.query(Touch).first().state, invite)
        self.assertEqual(session.query(Touch).count(), 1)

        now = datetime.datetime.utcnow()
        self.assertTrue(now > then)
        active = session.query(MembershipState).filter(
            MembershipState.name == "active").one()
        mship.changes.append(
            Touch(artifact=mship, actor=user, state=active, at=now))
        session.commit()

        self.assertIs(mship.changes[1].state, active)
        self.assertIs(
            session.query(Touch).order_by(Touch.at)[-1].state, active)
        self.assertEqual(session.query(Touch).count(), 2)

        self.assertEqual(
            session.query(Touch).filter(Touch.at < now).first(),
            mship.changes[0])
        self.assertIs(
            session.query(Touch).filter(
                Touch.at > then).first(),
            mship.changes[1])

        mship.changes.sort(key=operator.attrgetter("at"), reverse=True)

        self.assertEqual(
            session.query(Touch).filter(
                Touch.at < now).first(),
            mship.changes[1])
        self.assertIs(
            session.query(Touch).filter(
                Touch.at > then).first(),
            mship.changes[0])
开发者ID:cedadev,项目名称:cloudhands-common,代码行数:56,代码来源:test_schema.py

示例9: test_organisation_field

# 需要导入模块: from cloudhands.common.connectors import Registry [as 别名]
# 或者: from cloudhands.common.connectors.Registry import commit [as 别名]
 def test_organisation_field(self):
     session = Registry().connect(sqlite3, ":memory:").session
     org = session.query(Organisation).one()
     mship = Membership(
         uuid=uuid.uuid4().hex,
         model=cloudhands.common.__version__,
         organisation=org,
         role="user")
     session.add(mship)
     session.commit()
     self.assertIs(mship, session.query(Membership).first())
     self.assertIs(org, mship.organisation)
开发者ID:cedadev,项目名称:cloudhands-common,代码行数:14,代码来源:test_schema.py

示例10: RegistrationLifecycleTests

# 需要导入模块: from cloudhands.common.connectors import Registry [as 别名]
# 或者: from cloudhands.common.connectors.Registry import commit [as 别名]
class RegistrationLifecycleTests(unittest.TestCase):

    def setUp(self):
        self.session = Registry().connect(sqlite3, ":memory:").session
        initialise(self.session)
        self.reg = Registration(
            uuid=uuid.uuid4().hex,
            model=cloudhands.common.__version__)
        self.session.add(self.reg)
        self.session.commit()

    def tearDown(self):
        Registry().disconnect(sqlite3, ":memory:")
开发者ID:cedadev,项目名称:cloudhands-web,代码行数:15,代码来源:test_registration.py

示例11: test_reallocate_ip

# 需要导入模块: from cloudhands.common.connectors import Registry [as 别名]
# 或者: from cloudhands.common.connectors.Registry import commit [as 别名]
    def test_reallocate_ip(self):
        session = Registry().connect(sqlite3, ":memory:").session
        session.autoflush = False   # http://stackoverflow.com/a/4202016
        oName = "TestOrg"
        providerName = "testcloud.io"
        handle = "Test User"
        hName = "mynode.test.org"
        ipAddr = "192.168.1.1"

        user = User(handle=handle, uuid=uuid.uuid4().hex)
        org = session.query(Organisation).one()
        provider = Provider(
            name=providerName, uuid=uuid.uuid4().hex)
        session.add_all((user, org, provider))
        session.commit()

        scheduling = session.query(HostState).filter(
            HostState.name == "scheduling").one()
        up = session.query(HostState).filter(
            HostState.name == "up").one()
        hosts = [
            Host(
                uuid=uuid.uuid4().hex,
                model=cloudhands.common.__version__,
                organisation=org,
                name=hName),
            Host(
                uuid=uuid.uuid4().hex,
                model=cloudhands.common.__version__,
                organisation=org,
                name=hName),
        ]
        now = datetime.datetime.utcnow()
        hosts[0].changes.append(
            Touch(artifact=hosts[0], actor=user, state=up, at=now))
        hosts[1].changes.append(
            Touch(artifact=hosts[1], actor=user, state=scheduling, at=now))
        session.add_all(hosts)
        session.commit()

        ip = allocate_ip(session, hosts[0], provider, ipAddr)
        self.assertIn(ip, [r for c in hosts[0].changes for r in c.resources])

        ip = allocate_ip(session, hosts[1], provider, ipAddr)
        self.assertNotIn(
            ip, [r for c in hosts[0].changes for r in c.resources])
        self.assertIn(ip, [r for c in hosts[1].changes for r in c.resources])
开发者ID:cedadev,项目名称:cloudhands-web,代码行数:49,代码来源:test_tricks.py

示例12: SubscriptionLifecycleTests

# 需要导入模块: from cloudhands.common.connectors import Registry [as 别名]
# 或者: from cloudhands.common.connectors.Registry import commit [as 别名]
class SubscriptionLifecycleTests(unittest.TestCase):

    def setUp(self):
        self.session = Registry().connect(sqlite3, ":memory:").session
        initialise(self.session)
        self.org = Organisation(
            uuid=uuid.uuid4().hex,
            name="TestOrg")
        self.providers = [
            Provider(uuid=uuid.uuid4().hex, name="JASMIN private DC"),
            Provider(uuid=uuid.uuid4().hex, name="JASMIN burst partner"),
        ]
        self.session.add_all([self.org] + self.providers)
        self.session.commit()

    def tearDown(self):
        Registry().disconnect(sqlite3, ":memory:")
开发者ID:cedadev,项目名称:cloudhands-burst,代码行数:19,代码来源:test_subscription.py

示例13: test_organisation_subscribes_to_archive

# 需要导入模块: from cloudhands.common.connectors import Registry [as 别名]
# 或者: from cloudhands.common.connectors.Registry import commit [as 别名]
    def test_organisation_subscribes_to_archive(self):
        session = Registry().connect(sqlite3, ":memory:").session
        archive = session.query(Archive).filter(
            Archive.name == "NITS").first()
        self.assertTrue(archive)
        org = session.query(Organisation).one()
        subs = Subscription(
            uuid=uuid.uuid4().hex,
            model=cloudhands.common.__version__,
            organisation=org, provider=archive)
        session.add(subs)
        session.commit()

        self.assertEqual(
            1, session.query(Subscription, Organisation, Archive).filter(
            Organisation.id == org.id).filter(
            Archive.id == archive.id).count())
        self.assertEqual(1, len(org.subscriptions))
开发者ID:cedadev,项目名称:cloudhands-common,代码行数:20,代码来源:test_schema.py

示例14: test_ldapattribute_attaches_to_membership

# 需要导入模块: from cloudhands.common.connectors import Registry [as 别名]
# 或者: from cloudhands.common.connectors.Registry import commit [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

示例15: test_time_query

# 需要导入模块: from cloudhands.common.connectors import Registry [as 别名]
# 或者: from cloudhands.common.connectors.Registry import commit [as 别名]
    def test_time_query(self):
        session = Registry().connect(sqlite3, ":memory:").session
        agent = session.query(Component).one()
        state = session.query(MembershipState).first()
        reg = Registration(
            uuid=uuid.uuid4().hex,
            model=cloudhands.common.__version__)
        start = now = datetime.datetime.now()
        then = start + datetime.timedelta(minutes=90)
        end = start + datetime.timedelta(hours=24)
        act = Touch(artifact=reg, actor=agent, state=state, at=now)
        limit = TimeInterval(end=then, touch=act) 
        session.add(limit)
        session.commit()
        self.assertEqual(session.query(TimeInterval).filter(
            TimeInterval.end > now).count(), 1)

        self.assertIs(reg,
            session.query(Registration).join(Touch).join(TimeInterval).filter(
                TimeInterval.end.between(start, end)).first())
开发者ID:cedadev,项目名称:cloudhands-common,代码行数:22,代码来源:test_schema.py


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