def test_adds_revisions(self): # A branch with revisions should add the new revisions. branch = self.factory.makeAnyBranch() revision = self.factory.makeRevision() branch.createBranchRevision(1, revision) RevisionSet.updateRevisionCacheForBranch(branch) [cached] = self._getRevisionCache() self.assertEqual(cached.revision, revision) self.assertEqual(cached.revision_author, revision.revision_author) self.assertEqual(cached.revision_date, revision.revision_date)
def test_revisions_for_public_branch_marked_public(self): # If the branch is public, then the revisions in the cache will be # marked public too. branch = self.factory.makeAnyBranch() revision = self.factory.makeRevision() branch.createBranchRevision(1, revision) RevisionSet.updateRevisionCacheForBranch(branch) [cached] = self._getRevisionCache() self.assertFalse(branch.private) self.assertFalse(cached.private)
def test_revisions_for_public_branch_marked_public(self): # If the branch is public, then the revisions in the cache will be # marked public too. branch = self.factory.makeAnyBranch() revision = self.factory.makeRevision() branch.createBranchRevision(1, revision) RevisionSet.updateRevisionCacheForBranch(branch) [cached] = self._getRevisionCache() self.assertFalse(branch.private) self.assertFalse(cached.private)
def test_adds_revisions(self): # A branch with revisions should add the new revisions. branch = self.factory.makeAnyBranch() revision = self.factory.makeRevision() branch.createBranchRevision(1, revision) RevisionSet.updateRevisionCacheForBranch(branch) [cached] = self._getRevisionCache() self.assertEqual(cached.revision, revision) self.assertEqual(cached.revision_author, revision.revision_author) self.assertEqual(cached.revision_date, revision.revision_date)
def test_revisions_for_private_branch_marked_private(self): # If the branch is private, then the revisions in the cache will be # marked private too. branch = self.factory.makeAnyBranch( information_type=InformationType.USERDATA) revision = self.factory.makeRevision() branch.createBranchRevision(1, revision) RevisionSet.updateRevisionCacheForBranch(branch) [cached] = self._getRevisionCache() self.assertTrue(branch.private) self.assertTrue(cached.private)
def test_package_branch_revisions(self): # The revision cache stores the distroseries and sourcepackagename for # package branches. branch = self.factory.makePackageBranch() revision = self.factory.makeRevision() branch.createBranchRevision(1, revision) RevisionSet.updateRevisionCacheForBranch(branch) [cached] = self._getRevisionCache() self.assertIs(None, cached.product) self.assertEqual(branch.distroseries, cached.distroseries) self.assertEqual(branch.sourcepackagename, cached.sourcepackagename)
def test_personal_branch_revisions(self): # If the branch is a personal branch, the revision cache stores NULL # for the product, distroseries and sourcepackagename. branch = self.factory.makePersonalBranch() revision = self.factory.makeRevision() branch.createBranchRevision(1, revision) RevisionSet.updateRevisionCacheForBranch(branch) [cached] = self._getRevisionCache() self.assertIs(None, cached.product) self.assertIs(None, cached.distroseries) self.assertIs(None, cached.sourcepackagename)
def test_product_branch_revisions(self): # The revision cache knows the product for revisions in product # branches. branch = self.factory.makeProductBranch() revision = self.factory.makeRevision() branch.createBranchRevision(1, revision) RevisionSet.updateRevisionCacheForBranch(branch) [cached] = self._getRevisionCache() self.assertEqual(cached.product, branch.product) self.assertIs(None, cached.distroseries) self.assertIs(None, cached.sourcepackagename)
def test_revisions_for_private_branch_marked_private(self): # If the branch is private, then the revisions in the cache will be # marked private too. branch = self.factory.makeAnyBranch( information_type=InformationType.USERDATA) revision = self.factory.makeRevision() branch.createBranchRevision(1, revision) RevisionSet.updateRevisionCacheForBranch(branch) [cached] = self._getRevisionCache() self.assertTrue(branch.private) self.assertTrue(cached.private)
def test_product_branch_revisions(self): # The revision cache knows the product for revisions in product # branches. branch = self.factory.makeProductBranch() revision = self.factory.makeRevision() branch.createBranchRevision(1, revision) RevisionSet.updateRevisionCacheForBranch(branch) [cached] = self._getRevisionCache() self.assertEqual(cached.product, branch.product) self.assertIs(None, cached.distroseries) self.assertIs(None, cached.sourcepackagename)
def test_personal_branch_revisions(self): # If the branch is a personal branch, the revision cache stores NULL # for the product, distroseries and sourcepackagename. branch = self.factory.makePersonalBranch() revision = self.factory.makeRevision() branch.createBranchRevision(1, revision) RevisionSet.updateRevisionCacheForBranch(branch) [cached] = self._getRevisionCache() self.assertIs(None, cached.product) self.assertIs(None, cached.distroseries) self.assertIs(None, cached.sourcepackagename)
def test_package_branch_revisions(self): # The revision cache stores the distroseries and sourcepackagename for # package branches. branch = self.factory.makePackageBranch() revision = self.factory.makeRevision() branch.createBranchRevision(1, revision) RevisionSet.updateRevisionCacheForBranch(branch) [cached] = self._getRevisionCache() self.assertIs(None, cached.product) self.assertEqual(branch.distroseries, cached.distroseries) self.assertEqual(branch.sourcepackagename, cached.sourcepackagename)
def test_existing_private_revisions_with_public_branch(self): # If a revision is in both public and private branches, there is a # revision cache row for both public and private. private_branch = self.factory.makeAnyBranch( information_type=InformationType.USERDATA) public_branch = self.factory.makeAnyBranch() revision = self.factory.makeRevision() private_branch.createBranchRevision(1, revision) RevisionSet.updateRevisionCacheForBranch(private_branch) public_branch.createBranchRevision(1, revision) RevisionSet.updateRevisionCacheForBranch(public_branch) [rev1, rev2] = self._getRevisionCache() # Both revisions point to the same underlying revision. self.assertEqual(rev1.revision, revision) self.assertEqual(rev2.revision, revision) # But the privacy flags are different. self.assertNotEqual(rev1.private, rev2.private)
def test_existing_private_revisions_with_public_branch(self): # If a revision is in both public and private branches, there is a # revision cache row for both public and private. private_branch = self.factory.makeAnyBranch( information_type=InformationType.USERDATA) public_branch = self.factory.makeAnyBranch() revision = self.factory.makeRevision() private_branch.createBranchRevision(1, revision) RevisionSet.updateRevisionCacheForBranch(private_branch) public_branch.createBranchRevision(1, revision) RevisionSet.updateRevisionCacheForBranch(public_branch) [rev1, rev2] = self._getRevisionCache() # Both revisions point to the same underlying revision. self.assertEqual(rev1.revision, revision) self.assertEqual(rev2.revision, revision) # But the privacy flags are different. self.assertNotEqual(rev1.private, rev2.private)
def test_old_revisions_not_added(self): # Revisions older than the 30 day epoch are not added to the cache. # Start 33 days ago. epoch = datetime.now(pytz.UTC) - timedelta(days=30) date_generator = time_counter( epoch - timedelta(days=3), delta=timedelta(days=2)) # And add 4 revisions at 33, 31, 29, and 27 days ago branch = self.factory.makeAnyBranch() self.factory.makeRevisionsForBranch( branch, count=4, date_generator=date_generator) RevisionSet.updateRevisionCacheForBranch(branch) cached = self._getRevisionCache() # Only two revisions are within the 30 day cutoff. self.assertEqual(2, len(cached)) # And both the revisions stored are a date create after the epoch. for rev in cached: self.assertTrue(rev.revision_date > epoch)
def test_new_revisions_added(self): # If there are already revisions in the cache for the branch, updating # the branch again will only add the new revisions. date_generator = time_counter( datetime.now(pytz.UTC) - timedelta(days=29), delta=timedelta(days=1)) # Initially add in 4 revisions. branch = self.factory.makeAnyBranch() self.factory.makeRevisionsForBranch( branch, count=4, date_generator=date_generator) RevisionSet.updateRevisionCacheForBranch(branch) # Now add two more revisions. self.factory.makeRevisionsForBranch( branch, count=2, date_generator=date_generator) RevisionSet.updateRevisionCacheForBranch(branch) # There will be only six revisions cached. cached = self._getRevisionCache() self.assertEqual(6, len(cached))
def test_old_revisions_not_added(self): # Revisions older than the 30 day epoch are not added to the cache. # Start 33 days ago. epoch = datetime.now(pytz.UTC) - timedelta(days=30) date_generator = time_counter(epoch - timedelta(days=3), delta=timedelta(days=2)) # And add 4 revisions at 33, 31, 29, and 27 days ago branch = self.factory.makeAnyBranch() self.factory.makeRevisionsForBranch(branch, count=4, date_generator=date_generator) RevisionSet.updateRevisionCacheForBranch(branch) cached = self._getRevisionCache() # Only two revisions are within the 30 day cutoff. self.assertEqual(2, len(cached)) # And both the revisions stored are a date create after the epoch. for rev in cached: self.assertTrue(rev.revision_date > epoch)
def test_new_revisions_added(self): # If there are already revisions in the cache for the branch, updating # the branch again will only add the new revisions. date_generator = time_counter(datetime.now(pytz.UTC) - timedelta(days=29), delta=timedelta(days=1)) # Initially add in 4 revisions. branch = self.factory.makeAnyBranch() self.factory.makeRevisionsForBranch(branch, count=4, date_generator=date_generator) RevisionSet.updateRevisionCacheForBranch(branch) # Now add two more revisions. self.factory.makeRevisionsForBranch(branch, count=2, date_generator=date_generator) RevisionSet.updateRevisionCacheForBranch(branch) # There will be only six revisions cached. cached = self._getRevisionCache() self.assertEqual(6, len(cached))
def test_same_revision_multiple_targets(self): # If there are branches that have different targets that contain the # same revision, the revision appears in the revision cache once for # each different target. b1 = self.factory.makeProductBranch() b2 = self.factory.makePackageBranch() revision = self.factory.makeRevision() b1.createBranchRevision(1, revision) RevisionSet.updateRevisionCacheForBranch(b1) b2.createBranchRevision(1, revision) RevisionSet.updateRevisionCacheForBranch(b2) [rev1, rev2] = self._getRevisionCache() # Both cached revisions point to the same underlying revisions, but # for different targets. self.assertEqual(rev1.revision, revision) self.assertEqual(rev2.revision, revision) # Make rev1 be the cached revision for the product branch. if rev1.product is None: rev1, rev2 = rev2, rev1 self.assertEqual(b1.product, rev1.product) self.assertEqual(b2.distroseries, rev2.distroseries) self.assertEqual(b2.sourcepackagename, rev2.sourcepackagename)
def test_same_revision_multiple_targets(self): # If there are branches that have different targets that contain the # same revision, the revision appears in the revision cache once for # each different target. b1 = self.factory.makeProductBranch() b2 = self.factory.makePackageBranch() revision = self.factory.makeRevision() b1.createBranchRevision(1, revision) RevisionSet.updateRevisionCacheForBranch(b1) b2.createBranchRevision(1, revision) RevisionSet.updateRevisionCacheForBranch(b2) [rev1, rev2] = self._getRevisionCache() # Both cached revisions point to the same underlying revisions, but # for different targets. self.assertEqual(rev1.revision, revision) self.assertEqual(rev2.revision, revision) # Make rev1 be the cached revision for the product branch. if rev1.product is None: rev1, rev2 = rev2, rev1 self.assertEqual(b1.product, rev1.product) self.assertEqual(b2.distroseries, rev2.distroseries) self.assertEqual(b2.sourcepackagename, rev2.sourcepackagename)
def test_empty_branch(self): # A branch with no revisions should add no revisions to the cache. branch = self.factory.makeAnyBranch() RevisionSet.updateRevisionCacheForBranch(branch) self.assertEqual(0, len(self._getRevisionCache()))
def test_empty_branch(self): # A branch with no revisions should add no revisions to the cache. branch = self.factory.makeAnyBranch() RevisionSet.updateRevisionCacheForBranch(branch) self.assertEqual(0, len(self._getRevisionCache()))