def makeCachedRevision(self, revision=None, product=None,
                        package=None, private=False):
     # A factory method for RevisionCache objects.
     if revision is None:
         revision = self.factory.makeRevision()
     cached = RevisionCache(revision)
     cached.product = product
     if package is not None:
         cached.distroseries = package.distroseries
         cached.sourcepackagename = package.sourcepackagename
     cached.private = private
     return revision
 def test_only_recent_revisions_counted(self):
     # If the revision cache has revisions for the project, but they are
     # over 30 days old, we don't count them.
     product = self.factory.makeProduct()
     date_generator = time_counter(datetime.now(pytz.UTC) -
                                   timedelta(days=33),
                                   delta=timedelta(days=2))
     store = Store.of(product)
     for i in range(4):
         revision = self.factory.makeRevision(
             revision_date=date_generator.next())
         cache = RevisionCache(revision)
         cache.product = product
         store.add(cache)
     self.assertEqual([(product.name, 2, 2, revision.revision_date)],
                      self.getProductsWithInfo())
 def test_only_recent_revisions_counted(self):
     # If the revision cache has revisions for the project, but they are
     # over 30 days old, we don't count them.
     product = self.factory.makeProduct()
     date_generator = time_counter(
         datetime.now(pytz.UTC) - timedelta(days=33),
         delta=timedelta(days=2))
     store = Store.of(product)
     for i in range(4):
         revision = self.factory.makeRevision(
             revision_date=date_generator.next())
         cache = RevisionCache(revision)
         cache.product = product
         store.add(cache)
     self.assertEqual(
         [(product.name, 2, 2, revision.revision_date)],
         self.getProductsWithInfo())
Exemplo n.º 4
0
 def test_pruning_limit(self):
     # The prune will only remove at most the parameter rows.
     date_generator = time_counter(datetime.now(pytz.UTC) -
                                   timedelta(days=33),
                                   delta=timedelta(days=2))
     for i in range(4):
         revision = self.factory.makeRevision(
             revision_date=date_generator.next())
         cache = RevisionCache(revision)
         self.store.add(cache)
     RevisionSet.pruneRevisionCache(1)
     self.assertEqual(3, len(self._getRevisionCache()))
Exemplo n.º 5
0
 def test_old_revisions_removed(self):
     # Revisions older than 30 days are removed.
     date_generator = time_counter(datetime.now(pytz.UTC) -
                                   timedelta(days=33),
                                   delta=timedelta(days=2))
     for i in range(4):
         revision = self.factory.makeRevision(
             revision_date=date_generator.next())
         cache = RevisionCache(revision)
         self.store.add(cache)
     RevisionSet.pruneRevisionCache(5)
     self.assertEqual(2, len(self._getRevisionCache()))
Exemplo n.º 6
0
 def makeCachedRevision(self,
                        revision=None,
                        product=None,
                        package=None,
                        private=False):
     # A factory method for RevisionCache objects.
     if revision is None:
         revision = self.factory.makeRevision()
     cached = RevisionCache(revision)
     cached.product = product
     if package is not None:
         cached.distroseries = package.distroseries
         cached.sourcepackagename = package.sourcepackagename
     cached.private = private
     return revision