本文整理汇总了Python中lp.services.database.interfaces.IMasterStore类的典型用法代码示例。如果您正苦于以下问题:Python IMasterStore类的具体用法?Python IMasterStore怎么用?Python IMasterStore使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IMasterStore类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_store_disconnected_after_request_handled_logs_oops
def test_store_disconnected_after_request_handled_logs_oops(self):
# Bug #504291 was that a Store was being left in a disconnected
# state after a request, causing subsequent requests handled by that
# thread to fail. We detect this state in endRequest and log an
# OOPS to help track down the trigger.
request = LaunchpadTestRequest()
publication = WebServicePublication(None)
dbadapter.set_request_started()
# Disconnect a store
store = IMasterStore(EmailAddress)
store._connection._state = STATE_DISCONNECTED
# Invoke the endRequest hook.
publication.endRequest(request, None)
self.assertEqual(1, len(self.oopses))
oops = self.oopses[0]
# Ensure the OOPS mentions the correct exception
self.assertStartsWith(oops['value'], "Bug #504291")
# Ensure the store has been rolled back and in a usable state.
self.assertEqual(store._connection._state, STATE_RECONNECT)
store.find(EmailAddress).first() # Confirms Store is working.
示例2: test_headers
def test_headers(self):
client = LibrarianClient()
# Upload a file so we can retrieve it.
sample_data = 'blah'
file_alias_id = client.addFile(
'sample', len(sample_data), StringIO(sample_data),
contentType='text/plain')
url = client.getURLForAlias(file_alias_id)
# Change the date_created to a known value that doesn't match
# the disk timestamp. The timestamp on disk cannot be trusted.
file_alias = IMasterStore(LibraryFileAlias).get(
LibraryFileAlias, file_alias_id)
file_alias.date_created = datetime(
2001, 01, 30, 13, 45, 59, tzinfo=pytz.utc)
# Commit so the file is available from the Librarian.
self.commit()
# Fetch the file via HTTP, recording the interesting headers
result = urlopen(url)
last_modified_header = result.info()['Last-Modified']
cache_control_header = result.info()['Cache-Control']
# URLs point to the same content for ever, so we have a hardcoded
# 1 year max-age cache policy.
self.failUnlessEqual(cache_control_header, 'max-age=31536000, public')
# And we should have a correct Last-Modified header too.
self.failUnlessEqual(
last_modified_header, 'Tue, 30 Jan 2001 13:45:59 GMT')
示例3: test_BranchJobPruner
def test_BranchJobPruner(self):
# Garbo should remove jobs completed over 30 days ago.
switch_dbuser('testadmin')
store = IMasterStore(Job)
db_branch = self.factory.makeAnyBranch()
db_branch.branch_format = BranchFormat.BZR_BRANCH_5
db_branch.repository_format = RepositoryFormat.BZR_KNIT_1
Store.of(db_branch).flush()
branch_job = BranchUpgradeJob.create(
db_branch, self.factory.makePerson())
branch_job.job.date_finished = THIRTY_DAYS_AGO
self.assertEqual(
store.find(
BranchJob,
BranchJob.branch == db_branch.id).count(),
1)
self.runDaily()
switch_dbuser('testadmin')
self.assertEqual(
store.find(
BranchJob,
BranchJob.branch == db_branch.id).count(),
0)
示例4: test_CodeImportEventPruner
def test_CodeImportEventPruner(self):
now = datetime.now(UTC)
store = IMasterStore(CodeImportResult)
switch_dbuser('testadmin')
machine = self.factory.makeCodeImportMachine()
requester = self.factory.makePerson()
# Create 6 code import events for this machine, 3 on each side of 30
# days. Use the event set to the extra event data rows get created
# too.
event_set = getUtility(ICodeImportEventSet)
for age in (35, 33, 31, 29, 27, 15):
event_set.newOnline(
machine, user=requester, message='Hello',
_date_created=(now - timedelta(days=age)))
transaction.commit()
# Run the garbage collector
self.runDaily()
# Only the three most recent results are left.
events = list(machine.events)
self.assertEqual(3, len(events))
# We now have no CodeImportEvents older than 30 days
self.failUnless(
store.find(
Min(CodeImportEvent.date_created)).one().replace(tzinfo=UTC)
>= now - timedelta(days=30))
示例5: _test_AnswerContactPruner
def _test_AnswerContactPruner(self, status, interval, expected_count=0):
# Garbo should remove answer contacts for accounts with given 'status'
# which was set more than 'interval' days ago.
switch_dbuser('testadmin')
store = IMasterStore(AnswerContact)
person = self.factory.makePerson()
person.addLanguage(getUtility(ILanguageSet)['en'])
question = self.factory.makeQuestion()
with person_logged_in(question.owner):
question.target.addAnswerContact(person, person)
Store.of(question).flush()
self.assertEqual(
store.find(
AnswerContact,
AnswerContact.person == person.id).count(),
1)
account = person.account
account.status = status
# We flush because a trigger sets the date_status_set and we need to
# modify it ourselves.
Store.of(account).flush()
if interval is not None:
account.date_status_set = interval
self.runDaily()
switch_dbuser('testadmin')
self.assertEqual(
store.find(
AnswerContact,
AnswerContact.person == person.id).count(),
expected_count)
示例6: iterReady
def iterReady(cls):
"""See `IJobSource`."""
store = IMasterStore(QuestionJob)
jobs = store.find(
QuestionJob,
And(QuestionJob.job_type == cls.class_job_type,
QuestionJob.job_id.is_in(Job.ready_jobs)))
return (cls(job) for job in jobs)
示例7: new
def new(cls, job_type, status=BuildStatus.NEEDSBUILD, date_created=None,
builder=None, archive=None):
"""See `IBuildFarmJobSource`."""
build_farm_job = BuildFarmJob(
job_type, status, date_created, builder, archive)
store = IMasterStore(BuildFarmJob)
store.add(build_farm_job)
return build_farm_job
示例8: getRecentBuilds
def getRecentBuilds(cls, requester, recipe, distroseries, _now=None):
if _now is None:
_now = datetime.now(pytz.UTC)
store = IMasterStore(SourcePackageRecipeBuild)
old_threshold = _now - timedelta(days=1)
return store.find(cls, cls.distroseries_id == distroseries.id,
cls.requester_id == requester.id, cls.recipe_id == recipe.id,
cls.date_created > old_threshold)
示例9: iterReady
def iterReady(cls):
"""Iterate through all ready ProductJobs."""
store = IMasterStore(ProductJob)
jobs = store.find(
ProductJob,
And(ProductJob.job_type == cls.class_job_type,
ProductJob.job_id.is_in(Job.ready_jobs)))
return (cls(job) for job in jobs)
示例10: removeAssociation
def removeAssociation(self, server_url, handle):
"""See `OpenIDStore`."""
store = IMasterStore(self.Association)
assoc = store.get(self.Association, (
server_url.decode('UTF-8'), handle.decode('ASCII')))
if assoc is None:
return False
store.remove(assoc)
return True
示例11: new
def new(self, distribution, root_dir, base_url, copy_base_url):
"""Make and return a new `PublisherConfig`."""
store = IMasterStore(PublisherConfig)
pubconf = PublisherConfig()
pubconf.distribution = distribution
pubconf.root_dir = root_dir
pubconf.base_url = base_url
pubconf.copy_base_url = copy_base_url
store.add(pubconf)
return pubconf
示例12: test_useNonce
def test_useNonce(self):
timestamp = time.time()
# The nonce can only be used once.
self.assertEqual(self.store.useNonce("server-url", timestamp, "salt"), True)
storm_store = IMasterStore(self.store.Nonce)
new_nonce = storm_store.get(self.store.Nonce, (u"server-url", timestamp, u"salt"))
self.assertIsNot(None, new_nonce)
self.assertEqual(self.store.useNonce("server-url", timestamp, "salt"), False)
self.assertEqual(self.store.useNonce("server-url", timestamp, "salt"), False)
示例13: _getOldestLiveRequest
def _getOldestLiveRequest(self):
"""Return the oldest live request on the master store.
Due to replication lag, the master store is always a little
ahead of the slave store that exports come from.
"""
master_store = IMasterStore(POExportRequest)
sorted_by_id = master_store.find(POExportRequest).order_by(
POExportRequest.id)
return sorted_by_id.first()
示例14: newPackagesetUploader
def newPackagesetUploader(
self, archive, person, packageset, explicit=False):
"""See `IArchivePermissionSet`."""
packageset = self._nameToPackageset(packageset)
store = IMasterStore(ArchivePermission)
# First see whether we have a matching permission in the database
# already.
query = '''
SELECT ap.id
FROM archivepermission ap, teamparticipation tp
WHERE
ap.person = tp.team AND tp.person = ?
AND ap.packageset = ? AND ap.archive = ?
'''
query = SQL(query, (person.id, packageset.id, archive.id))
permissions = list(
store.find(
ArchivePermission, ArchivePermission.id.is_in(query)))
if len(permissions) > 0:
# Found permissions in the database, does the 'explicit' flag
# have the requested value?
conflicting = [permission for permission in permissions
if permission.explicit != explicit]
if len(conflicting) > 0:
# At least one permission with conflicting 'explicit' flag
# value exists already.
cperm = conflicting[0]
raise ValueError(
"Permission for package set '%s' already exists for %s "
"but with a different 'explicit' flag value (%s)." %
(packageset.name, cperm.person.name, cperm.explicit))
else:
# No conflicts, does the requested permission exist already?
existing = [permission for permission in permissions
if (permission.explicit == explicit and
permission.person == person and
permission.packageset == packageset)]
assert len(existing) <= 1, (
"Too many permissions for %s and %s" %
(person.name, packageset.name))
if len(existing) == 1:
# The existing permission matches, just return it.
return existing[0]
# The requested permission does not exist yet. Insert it into the
# database.
permission = ArchivePermission(
archive=archive,
person=person, packageset=packageset,
permission=ArchivePermissionType.UPLOAD, explicit=explicit)
store.add(permission)
return permission
示例15: getMatchingDSD
def getMatchingDSD(self):
"""Find an existing `DistroSeriesDifference` for this difference."""
spn_id = self.metadata["sourcepackagename"]
parent_id = self.metadata["parent_series"]
store = IMasterStore(DistroSeriesDifference)
search = store.find(
DistroSeriesDifference,
DistroSeriesDifference.derived_series == self.derived_series,
DistroSeriesDifference.parent_series_id == parent_id,
DistroSeriesDifference.source_package_name_id == spn_id)
return search.one()