def test_with_branches(self):
     # Test the selection of the links.
     # Make two package branches that we care about.
     b1 = make_linked_package_branch(self.factory)
     b2 = make_linked_package_branch(self.factory)
     # And two we don't.
     make_linked_package_branch(self.factory)
     make_linked_package_branch(self.factory)
     links = (BranchListingQueryOptimiser.
              getOfficialSourcePackageLinksForBranches([b1.id, b2.id]))
     self.assertEqual(sorted([b1, b2]),
                      sorted([link.branch for link in links]))
 def test_with_branches(self):
     # Test the selection of the links.
     # Make two package branches that we care about.
     b1 = make_linked_package_branch(self.factory)
     b2 = make_linked_package_branch(self.factory)
     # And two we don't.
     make_linked_package_branch(self.factory)
     make_linked_package_branch(self.factory)
     links = (BranchListingQueryOptimiser.
              getOfficialSourcePackageLinksForBranches([b1.id, b2.id]))
     self.assertEqual(
         sorted([b1, b2]),
         sorted([link.branch for link in links]))
    def test_objects_loaded(self):
        # Traversing through the source package and the distribution should
        # not cause more queries.

        b1 = make_linked_package_branch(self.factory)
        store = Store.of(b1)
        # Constructing a distribution causes the "ubuntu" celebrity to be
        # created which hits the database. So load it now.
        store.flush()
        store.reset()
        getUtility(ILaunchpadCelebrities).ubuntu

        (link, ) = self.assertStatementCount(
            1, BranchListingQueryOptimiser.
            getOfficialSourcePackageLinksForBranches, [b1.id])
        # Accessing the source package doesn't hit the database.
        sp = self.assertStatementCount(0, getattr, link, "sourcepackage")
        # Getting the distribution from the source package doesn't hit the
        # database.
        self.assertStatementCount(0, getattr, sp, "distribution")
        # Nor does getting the path or displayname.
        self.assertStatementCount(0, getattr, sp, "displayname")
        self.assertStatementCount(0, getattr, sp, "path")
 def makeLinkedPackageBranch(self, distribution, sourcepackagename):
     """Make a new package branch and make it official."""
     return make_linked_package_branch(self.factory, distribution,
                                       sourcepackagename)
 def makeLinkedPackageBranch(self, distribution, sourcepackagename):
     """Make a new package branch and make it official."""
     return make_linked_package_branch(
         self.factory, distribution, sourcepackagename)