示例#1
0
 def completed_builds(self):
     """See `ILiveFS`."""
     filter_term = (Not(LiveFSBuild.status.is_in(self._pending_states)))
     order_by = (NullsLast(
         Desc(Greatest(LiveFSBuild.date_started,
                       LiveFSBuild.date_finished))), Desc(LiveFSBuild.id))
     return self._getBuilds(filter_term, order_by)
示例#2
0
 def dependent_landings(self):
     """See `IGitRef`."""
     return Store.of(self).find(
         BranchMergeProposal,
         BranchMergeProposal.prerequisite_git_repository == self.repository,
         BranchMergeProposal.prerequisite_git_path == self.path,
         Not(BranchMergeProposal.queue_status.is_in(
             BRANCH_MERGE_PROPOSAL_FINAL_STATES)))
示例#3
0
 def landing_candidates(self):
     """See `IGitRef`."""
     return Store.of(self).find(
         BranchMergeProposal,
         BranchMergeProposal.target_git_repository == self.repository,
         BranchMergeProposal.target_git_path == self.path,
         Not(BranchMergeProposal.queue_status.is_in(
             BRANCH_MERGE_PROPOSAL_FINAL_STATES)))
示例#4
0
 def testCreate(self):
     """L{TagAPI.create} creates new L{Tag}s using the provided data."""
     values = [(u'username/tag', u'A description')]
     self.tags.create(values)
     systemTags = self.system.tags.keys()
     tag = self.store.find(Tag, Not(Tag.path.is_in(systemTags))).one()
     self.assertEqual(u'username/tag', tag.path)
     self.assertEqual(u'tag', tag.name)
     self.assertIdentical(self.user.namespace, tag.namespace)
示例#5
0
 def testCreateWithoutData(self):
     """
     L{NamespaceAPI.create} returns an empty C{list} if no L{Namespace}
     data is available.
     """
     result = self.namespaces.create([])
     self.assertEqual([], result)
     ignored = (self.system.namespaces.keys() +
                [u'username', u'username/private'])
     result = self.store.find(Namespace, Not(Namespace.path.is_in(ignored)))
     self.assertIdentical(None, result.one())
示例#6
0
 def getTermByToken(self, token):
     """See `IVocabularyTokenized`."""
     if "/" in token:
         try:
             distribution_name, distro_series_name, snappy_series_name = (
                 token.split("/", 2))
         except ValueError:
             raise LookupError(token)
     else:
         distribution_name = None
         distro_series_name = None
         snappy_series_name = token
     entry = IStore(self._table).using(*self._origin).find(
         self._table,
         Not(IsDistinctFrom(Distribution.name, distribution_name)),
         Not(IsDistinctFrom(DistroSeries.name, distro_series_name)),
         SnappySeries.name == snappy_series_name,
         *self._clauses).one()
     if entry is None:
         raise LookupError(token)
     return self.toTerm(entry)
示例#7
0
 def testDelete(self):
     """L{TagValueAPI.delete} deletes L{TagValue}s."""
     objectID = uuid4()
     namespace = createNamespace(self.user, u'name')
     createNamespacePermission(namespace)
     tag = createTag(self.user, namespace, u'tag')
     createTagPermission(tag)
     createTagValue(self.user.id, tag.id, objectID, None)
     self.tagValues.delete([(objectID, u'name/tag')])
     values = self.store.find(TagValue, TagValue.tagID == Tag.id,
                              Not(Tag.path.is_in(self.system.tags)))
     self.assertEqual([], list(values))
     self.assertIn(objectID, getDirtyObjects().values(DirtyObject.objectID))
示例#8
0
 def testCreateWithExistingNamespacePath(self):
     """
     L{TagAPI.create} can be used to create L{Tag}s with the same path as
     an existing L{Namespace}.
     """
     createNamespace(self.user, u'username/name', self.user.namespace.id)
     values = [(u'username/name', u'A description')]
     self.tags.create(values)
     systemTags = self.system.tags.keys()
     tag = self.store.find(Tag, Not(Tag.path.is_in(systemTags))).one()
     self.assertEqual(u'username/name', tag.path)
     self.assertEqual(u'name', tag.name)
     self.assertIdentical(self.user.namespace, tag.namespace)
示例#9
0
 def getProductsWithInfo(num_products=None):
     """See `IBranchCloud`."""
     distinct_revision_author = Func("distinct",
                                     RevisionCache.revision_author_id)
     commits = Alias(Count(RevisionCache.revision_id))
     epoch = datetime.now(pytz.UTC) - timedelta(days=30)
     # It doesn't matter if this query is even a whole day out of date, so
     # use the slave store.
     result = ISlaveStore(RevisionCache).find(
         (Product.name, commits, Count(distinct_revision_author),
          Max(RevisionCache.revision_date)),
         RevisionCache.product == Product.id, Not(RevisionCache.private),
         RevisionCache.revision_date >= epoch)
     result = result.group_by(Product.name)
     result = result.order_by(Desc(commits))
     if num_products:
         result.config(limit=num_products)
     return result
    def iterReady(cls):
        """Iterate through all ready PackageCopyJobs.

        Even though it's slower, we repeat the query each time in order that
        very long queues of mass syncs can be pre-empted by other jobs.
        """
        seen = set()
        while True:
            jobs = IStore(PackageCopyJob).find(
                PackageCopyJob, PackageCopyJob.job_type == cls.class_job_type,
                PackageCopyJob.job == Job.id, Job.id.is_in(Job.ready_jobs),
                Not(Job.id.is_in(seen)))
            jobs.order_by(PackageCopyJob.copy_policy)
            job = jobs.first()
            if job is None:
                break
            seen.add(job.job_id)
            yield cls(job)
示例#11
0
 def testDeleteRemovesTagValues(self):
     """
     L{TagValueAPI.delete} removes L{TagValue}s associated with the deleted
     L{Tag}s.
     """
     objectID = uuid4()
     namespace = createNamespace(self.user, u'name')
     createNamespacePermission(namespace)
     tag1 = createTag(self.user, namespace, u'tag1')
     tag2 = createTag(self.user, namespace, u'tag2')
     createTagPermission(tag1)
     createTagPermission(tag2)
     value = createTagValue(self.user.id, tag1.id, objectID, 42)
     createTagValue(self.user.id, tag2.id, objectID, 17)
     self.tagValues.delete([(objectID, u'name/tag2')])
     values = self.store.find(TagValue, TagValue.tagID == Tag.id,
                              Not(Tag.path.is_in(self.system.tags)))
     self.assertEqual([value], list(values))
     self.assertIn(objectID, getDirtyObjects().values(DirtyObject.objectID))
示例#12
0
 def testDeleteOnlyConsidersSpecifiedObjectIDs(self):
     """
     L{TagValueAPI.delete} only removes the values for the specified object
     IDs.
     """
     objectID1 = uuid4()
     objectID2 = uuid4()
     namespace = createNamespace(self.user, u'name')
     createNamespacePermission(namespace)
     tag = createTag(self.user, namespace, u'tag')
     createTagPermission(tag)
     createTagValue(self.user.id, tag.id, objectID1, 42)
     value = createTagValue(self.user.id, tag.id, objectID2, 17)
     self.tagValues.delete([(objectID1, u'name/tag')])
     values = self.store.find(TagValue, TagValue.tagID == Tag.id,
                              Not(Tag.path.is_in(self.system.tags)))
     self.assertEqual([value], list(values))
     self.assertIn(objectID1,
                   getDirtyObjects().values(DirtyObject.objectID))
示例#13
0
 def testDeleteRemovesTagValuesWhenPassedAGenerator(self):
     """
     L{TagValueAPI.delete} removes L{TagValue}s associated with the
     deleted L{Tag}s when it is passed a generator (as opposed to a
     C{list}).
     """
     objectID = uuid4()
     namespace = createNamespace(self.user, u'name')
     createNamespacePermission(namespace)
     tag1 = createTag(self.user, namespace, u'tag1')
     tag2 = createTag(self.user, namespace, u'tag2')
     createTagPermission(tag1)
     createTagPermission(tag2)
     value = createTagValue(self.user.id, tag1.id, objectID, 42)
     createTagValue(self.user.id, tag2.id, objectID, 17)
     values = ((objectID, name) for name in [u'name/tag2'])
     self.tagValues.delete(values)
     values = self.store.find(TagValue, TagValue.tagID == Tag.id,
                              Not(Tag.path.is_in(self.system.tags)))
     self.assertEqual([value], list(values))
     self.assertIn(objectID, getDirtyObjects().values(DirtyObject.objectID))
示例#14
0
    def testCreate(self):
        """L{User.create} creates new L{User}s based on the provided data."""
        users = [(u'fred', u'fred-secret', u'Fred', u'*****@*****.**'),
                 (u'joe', u'joe-secret', u'Joe', u'*****@*****.**')]
        self.users.create(users)
        result = self.store.find(
            User,
            Not(
                Or(User.username == u'fluiddb',
                   User.username == u'fluidinfo.com',
                   User.username == u'anon')))
        result.order_by(User.username)
        [user1, user2] = list(result)
        self.assertEqual(u'fred', user1.username)
        self.assertEqual(hashPassword(u'fred-secret', user1.passwordHash),
                         user1.passwordHash)
        self.assertEqual(u'Fred', user1.fullname)
        self.assertEqual(u'*****@*****.**', user1.email)

        self.assertEqual(u'joe', user2.username)
        self.assertEqual(hashPassword(u'joe-secret', user2.passwordHash),
                         user2.passwordHash)
        self.assertEqual(u'Joe', user2.fullname)
        self.assertEqual(u'*****@*****.**', user2.email)
def get_stacked_branches():
    """Iterate over all branches that, according to the db, are stacked."""
    # Avoiding circular import.
    from lp.code.model.branch import Branch
    return ISlaveStore(Branch).find(Branch, Not(Branch.stacked_on == None))