本文整理汇总了Python中lp.services.database.interfaces.IStore.flush方法的典型用法代码示例。如果您正苦于以下问题:Python IStore.flush方法的具体用法?Python IStore.flush怎么用?Python IStore.flush使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lp.services.database.interfaces.IStore
的用法示例。
在下文中一共展示了IStore.flush方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_string
# 需要导入模块: from lp.services.database.interfaces import IStore [as 别名]
# 或者: from lp.services.database.interfaces.IStore import flush [as 别名]
def test_get_string(self):
# Test NameBlacklistSet.get() with string id.
name_blacklist = self.name_blacklist_set.create(u'foo', u'bar')
store = IStore(name_blacklist)
store.flush()
retrieved = self.name_blacklist_set.get(str(name_blacklist.id))
self.assertEqual(name_blacklist, retrieved)
示例2: runMListSync
# 需要导入模块: from lp.services.database.interfaces import IStore [as 别名]
# 或者: from lp.services.database.interfaces.IStore import flush [as 别名]
def runMListSync(self, source_dir):
"""Run mlist-sync.py."""
store = IStore(self.team)
store.flush()
commit()
store.invalidate()
proc = Popen(
('scripts/mlist-sync.py', '--hostname',
self.host_name, source_dir),
stdout=PIPE, stderr=PIPE,
cwd=config.root,
env=dict(LPCONFIG=DatabaseFunctionalLayer.appserver_config_name))
stdout, stderr = proc.communicate()
return proc.returncode, stderr
示例3: TestNameBlacklist
# 需要导入模块: from lp.services.database.interfaces import IStore [as 别名]
# 或者: from lp.services.database.interfaces.IStore import flush [as 别名]
class TestNameBlacklist(TestCaseWithFactory):
layer = ZopelessDatabaseLayer
def setUp(self):
super(TestNameBlacklist, self).setUp()
self.name_blacklist_set = getUtility(INameBlacklistSet)
self.caret_foo_exp = self.name_blacklist_set.create(u'^foo')
self.foo_exp = self.name_blacklist_set.create(u'foo')
self.verbose_exp = self.name_blacklist_set.create(u'v e r b o s e')
team = self.factory.makeTeam()
self.admin_exp = self.name_blacklist_set.create(u'fnord', admin=team)
self.store = IStore(self.foo_exp)
self.store.flush()
def name_blacklist_match(self, name, user_id=None):
'''Return the result of the name_blacklist_match stored procedure.'''
user_id = user_id or 0
result = self.store.execute(
"SELECT name_blacklist_match(%s, %s)", (name, user_id))
return result.get_one()[0]
def is_blacklisted_name(self, name, user_id=None):
'''Call the is_blacklisted_name stored procedure and return the result
'''
user_id = user_id or 0
result = self.store.execute(
"SELECT is_blacklisted_name(%s, %s)", (name, user_id))
blacklisted = result.get_one()[0]
self.failIf(blacklisted is None, 'is_blacklisted_name returned NULL')
return bool(blacklisted)
def test_name_blacklist_match(self):
# A name that is not blacklisted returns NULL/None
self.failUnless(self.name_blacklist_match(u"bar") is None)
# A name that is blacklisted returns the id of the row in the
# NameBlacklist table that matched. Rows are tried in order, and the
# first match is returned.
self.assertEqual(
self.name_blacklist_match(u"foobar"),
self.caret_foo_exp.id)
self.assertEqual(
self.name_blacklist_match(u"barfoo"),
self.foo_exp.id)
def test_name_blacklist_match_admin_does_not_match(self):
# A user in the expresssion's admin team is exempt from the
# backlisted name restriction.
user = self.admin_exp.admin.teamowner
self.assertEqual(
None, self.name_blacklist_match(u"fnord", user.id))
def test_name_blacklist_match_launchpad_admin_can_change(self):
# A Launchpad admin is exempt from any backlisted name restriction
# that has an admin.
user = self.factory.makePerson()
admins = getUtility(ILaunchpadCelebrities).admin
admins.addMember(user, user)
self.assertEqual(
None, self.name_blacklist_match(u"fnord", user.id))
def test_name_blacklist_match_launchpad_admin_cannot_change(self):
# A Launchpad admin cannot override backlisted names without admins.
user = self.factory.makePerson()
admins = getUtility(ILaunchpadCelebrities).admin
admins.addMember(user, user)
self.assertEqual(
self.foo_exp.id, self.name_blacklist_match(u"barfoo", user.id))
def test_name_blacklist_match_cache(self):
# If the blacklist is changed in the DB, these changes are noticed.
# This test is needed because the stored procedure keeps a cache
# of the compiled regular expressions.
self.assertEqual(
self.name_blacklist_match(u"foobar"),
self.caret_foo_exp.id)
self.caret_foo_exp.regexp = u'nomatch'
self.assertEqual(
self.name_blacklist_match(u"foobar"),
self.foo_exp.id)
self.foo_exp.regexp = u'nomatch2'
self.failUnless(self.name_blacklist_match(u"foobar") is None)
def test_is_blacklisted_name(self):
# is_blacklisted_name() is just a wrapper around name_blacklist_match
# that is friendlier to use in a boolean context.
self.failUnless(self.is_blacklisted_name(u"bar") is False)
self.failUnless(self.is_blacklisted_name(u"foo") is True)
self.caret_foo_exp.regexp = u'bar'
self.foo_exp.regexp = u'bar2'
self.failUnless(self.is_blacklisted_name(u"foo") is False)
def test_is_blacklisted_name_admin_false(self):
# Users in the expression's admin team are will return False.
user = self.admin_exp.admin.teamowner
self.assertFalse(self.is_blacklisted_name(u"fnord", user.id))
def test_case_insensitive(self):
self.failUnless(self.is_blacklisted_name(u"Foo") is True)
#.........这里部分代码省略.........
示例4: setUp
# 需要导入模块: from lp.services.database.interfaces import IStore [as 别名]
# 或者: from lp.services.database.interfaces.IStore import flush [as 别名]
def setUp(self):
"""Set up some native x86 builds for the test archive."""
super(TestBuildPackageJob, self).setUp()
# The builds will be set up as follows:
#
# j: 3 gedit p: hppa v:False e:0:01:00 *** s: 1001
# j: 4 gedit p: 386 v:False e:0:02:00 *** s: 1002
# j: 5 firefox p: hppa v:False e:0:03:00 *** s: 1003
# j: 6 firefox p: 386 v:False e:0:04:00 *** s: 1004
# j: 7 cobblers p: hppa v:False e:0:05:00 *** s: 1005
# j: 8 cobblers p: 386 v:False e:0:06:00 *** s: 1006
# j: 9 thunderpants p: hppa v:False e:0:07:00 *** s: 1007
# j:10 thunderpants p: 386 v:False e:0:08:00 *** s: 1008
# j:11 apg p: hppa v:False e:0:09:00 *** s: 1009
# j:12 apg p: 386 v:False e:0:10:00 *** s: 1010
# j:13 vim p: hppa v:False e:0:11:00 *** s: 1011
# j:14 vim p: 386 v:False e:0:12:00 *** s: 1012
# j:15 gcc p: hppa v:False e:0:13:00 *** s: 1013
# j:16 gcc p: 386 v:False e:0:14:00 *** s: 1014
# j:17 bison p: hppa v:False e:0:15:00 *** s: 1015
# j:18 bison p: 386 v:False e:0:16:00 *** s: 1016
# j:19 flex p: hppa v:False e:0:17:00 *** s: 1017
# j:20 flex p: 386 v:False e:0:18:00 *** s: 1018
# j:21 postgres p: hppa v:False e:0:19:00 *** s: 1019
# j:22 postgres p: 386 v:False e:0:20:00 *** s: 1020
#
# j=job, p=processor, v=virtualized, e=estimated_duration, s=score
# First mark all builds in the sample data as already built.
store = IStore(BinaryPackageBuild)
sample_data = store.find(BinaryPackageBuild)
for build in sample_data:
build.buildstate = BuildStatus.FULLYBUILT
store.flush()
# We test builds that target a primary archive.
self.non_ppa = self.factory.makeArchive(
name="primary", purpose=ArchivePurpose.PRIMARY)
self.non_ppa.require_virtualized = False
self.builds = []
sourcenames = [
"gedit",
"firefox",
"cobblers",
"thunderpants",
"apg",
"vim",
"gcc",
"bison",
"flex",
"postgres",
]
for sourcename in sourcenames:
self.builds.extend(
self.publisher.getPubSource(
sourcename=sourcename,
status=PackagePublishingStatus.PUBLISHED,
archive=self.non_ppa,
architecturehintlist='any').createMissingBuilds())
# We want the builds to have a lot of variety when it comes to score
# and estimated duration etc. so that the queries under test get
# exercised properly.
score = 1000
duration = 0
for build in self.builds:
score += 1
duration += 60
bq = build.buildqueue_record
bq.lastscore = score
removeSecurityProxy(bq).estimated_duration = timedelta(
seconds=duration)
示例5: TestOopsReferences
# 需要导入模块: from lp.services.database.interfaces import IStore [as 别名]
# 或者: from lp.services.database.interfaces.IStore import flush [as 别名]
class TestOopsReferences(TestCaseWithFactory):
layer = DatabaseFunctionalLayer
def setUp(self):
super(TestOopsReferences, self).setUp()
self.store = IStore(Message)
def test_oops_in_messagechunk(self):
oopsid = "OOPS-abcdef1234"
MessageSet().fromText('foo', "foo %s bar" % oopsid)
self.store.flush()
now = datetime.now(tz=utc)
day = timedelta(days=1)
self.failUnlessEqual(
set([oopsid]),
referenced_oops(now - day, now, "product=1", {}))
self.failUnlessEqual(
set(),
referenced_oops(now + day, now + day, "product=1", {}))
def test_oops_in_messagesubject(self):
oopsid = "OOPS-abcdef1234"
self.factory.makeEmailMessage()
MessageSet().fromText("Crash with %s" % oopsid, "body")
self.store.flush()
now = datetime.now(tz=utc)
day = timedelta(days=1)
self.failUnlessEqual(
set([oopsid]),
referenced_oops(now - day, now, "product=1", {}))
self.failUnlessEqual(
set(),
referenced_oops(now + day, now + day, "product=1", {}))
def test_oops_in_bug_title(self):
oopsid = "OOPS-abcdef1234"
bug = self.factory.makeBug()
with person_logged_in(bug.owner):
bug.title = "Crash with %s" % oopsid
self.store.flush()
now = datetime.now(tz=utc)
day = timedelta(days=1)
self.failUnlessEqual(
set([oopsid]),
referenced_oops(now - day, now, "product=1", {}))
self.failUnlessEqual(
set(),
referenced_oops(now + day, now + day, "product=1", {}))
def test_oops_in_bug_description(self):
oopsid = "OOPS-abcdef1234"
bug = self.factory.makeBug()
with person_logged_in(bug.owner):
bug.description = "Crash with %s" % oopsid
self.store.flush()
now = datetime.now(tz=utc)
day = timedelta(days=1)
self.failUnlessEqual(
set([oopsid]),
referenced_oops(now - day, now, "product=1", {}))
self.failUnlessEqual(
set(),
referenced_oops(now + day, now + day, "product=1", {}))
def test_oops_in_question_title(self):
oopsid = "OOPS-abcdef1234"
question = self.factory.makeQuestion(title="Crash with %s" % oopsid)
self.store.flush()
now = datetime.now(tz=utc)
day = timedelta(days=1)
self.failUnlessEqual(
set([oopsid]),
referenced_oops(now - day, now, "product=%(product)s",
{'product': question.product.id}))
self.failUnlessEqual(
set([]),
referenced_oops(now + day, now + day, "product=%(product)s",
{'product': question.product.id}))
def test_oops_in_question_wrong_context(self):
oopsid = "OOPS-abcdef1234"
question = self.factory.makeQuestion(title="Crash with %s" % oopsid)
self.store.flush()
now = datetime.now(tz=utc)
day = timedelta(days=1)
self.store.flush()
self.failUnlessEqual(
set(),
referenced_oops(now - day, now, "product=%(product)s",
{'product': question.product.id + 1}))
def test_oops_in_question_description(self):
oopsid = "OOPS-abcdef1234"
question = self.factory.makeQuestion(
description="Crash with %s" % oopsid)
self.store.flush()
now = datetime.now(tz=utc)
day = timedelta(days=1)
self.failUnlessEqual(
#.........这里部分代码省略.........