def test_query_count(self): sprint = self.factory.makeSprint() with person_logged_in(sprint.owner): for x in range(30): sprint.attend(self.factory.makePerson(), sprint.time_starts, sprint.time_ends, True) self.assertThat(sprint, BrowsesWithQueryLimit(21, sprint.owner))
def test_publishinghistory_query_count(self): archive = self.factory.makeArchive(purpose=ArchivePurpose.PRIMARY) spph = self.factory.makeSourcePackagePublishingHistory(archive=archive) spn = spph.sourcepackagerelease.sourcepackagename dsp = archive.distribution.getSourcePackage(spn) publishinghistory_browses_under_limit = BrowsesWithQueryLimit( 27, self.factory.makePerson(), "+publishinghistory") self.assertThat(dsp, publishinghistory_browses_under_limit) with person_logged_in(archive.owner): copy_source_archive = self.factory.makeArchive() copy_spph = self.factory.makeSourcePackagePublishingHistory( archive=copy_source_archive, sourcepackagename=spn) copy_spph.copyTo(spph.distroseries, spph.pocket, archive, creator=self.factory.makePerson(), sponsor=self.factory.makePerson()) delete_spph = self.factory.makeSourcePackagePublishingHistory( archive=archive, sourcepackagename=spn) delete_spph.requestDeletion(self.factory.makePerson()) # This is a lot of extra queries per publication, and should be # ratcheted down over time; but it at least ensures that we don't # make matters any worse. publishinghistory_browses_under_limit.query_limit += 7 self.assertThat(dsp, publishinghistory_browses_under_limit)
def test_milestone_eager_loading(self): # Verify that the number of queries does not increase with more # bugs with different assignees. browses_under_limit = BrowsesWithQueryLimit(35, self.owner) self.add_bug(4) self.assertThat(self.milestone, browses_under_limit) self.add_bug(10) self.assertThat(self.milestone, browses_under_limit)
def test_query_count(self): product = self.factory.makeProduct() removeSecurityProxy(product).official_blueprints = True self.factory.makeSpecification(product=product) limit = BrowsesWithQueryLimit(37, product.owner, rootsite='blueprints') self.assertThat(product, limit) login_celebrity('admin') [self.factory.makeSpecification(product=product) for i in range(4)] self.assertThat(product, limit)
def test_query_count(self): # SearchQuestionsView does not query for the target SPN every time. owner = self.factory.makePerson() distro = self.factory.makeDistribution() removeSecurityProxy(distro).official_answers = True dsp = self.factory.makeDistributionSourcePackage( distribution=distro) [self.factory.makeQuestion(target=dsp, owner=owner) for i in range(5)] browses_under_limit = BrowsesWithQueryLimit( 31, owner, view_name="+questions") self.assertThat(dsp, browses_under_limit)
def test_packagediff_query_count(self): archive = self.factory.makeArchive(purpose=ArchivePurpose.PRIMARY) spph = self.factory.makeSourcePackagePublishingHistory(archive=archive) dsp = archive.distribution.getSourcePackage( spph.sourcepackagerelease.sourcepackagename) changelog_browses_under_limit = BrowsesWithQueryLimit( 32, self.factory.makePerson(), '+changelog') self.assertThat(dsp, changelog_browses_under_limit) with celebrity_logged_in('admin'): for i in range(5): self.factory.makePackageDiff( to_source=spph.sourcepackagerelease) self.assertThat(dsp, changelog_browses_under_limit)
def test_query_count(self): main_repo = self.factory.makeGitRepository(target=self.target) for i in range(10): self.factory.makeGitRefs(main_repo) for i in range(10): other_repo = self.factory.makeGitRepository(target=self.target) self.factory.makeGitRefs(other_repo) with admin_logged_in(): getUtility(IGitRepositorySet).setDefaultRepository( target=self.target, repository=main_repo) getUtility(IGitRepositorySet).setDefaultRepositoryForOwner( owner=other_repo.owner, target=self.target, repository=other_repo, user=other_repo.owner) self.assertThat( self.target, BrowsesWithQueryLimit(36, self.owner, '+git'))
def test_smoke(self): person = self.factory.makePerson() matcher = BrowsesWithQueryLimit(100, person) self.assertThat(person, matcher) matcher = Not(BrowsesWithQueryLimit(1, person)) self.assertThat(person, matcher)