Пример #1
0
 def test_count(self):
     # The 'count' property of a collection is the number of elements in
     # the collection.
     collection = GenericGitCollection(self.store)
     self.assertEqual(0, collection.count())
     for i in range(3):
         self.factory.makeGitRepository()
     self.assertEqual(3, collection.count())
Пример #2
0
 def test_count_respects_filter(self):
     # If a collection is a subset of all possible repositories, then the
     # count will be the size of that subset.  That is, 'count' respects
     # any filters that are applied.
     repository = self.factory.makeGitRepository()
     self.factory.makeGitRepository()
     collection = GenericGitCollection(
         self.store, [GitRepository.project == repository.target])
     self.assertEqual(1, collection.count())
Пример #3
0
 def test_getRepositories_project_filter(self):
     # If the specified filter is for the repositories of a particular
     # project, then the collection contains only repositories of that
     # project.
     repository = self.factory.makeGitRepository()
     self.factory.makeGitRepository()
     collection = GenericGitCollection(
         self.store, [GitRepository.project == repository.target])
     self.assertEqual([repository], list(collection.getRepositories()))
 def preLoadReferencedBranches(sourcepackagerecipedatas):
     # Circular imports.
     from lp.code.model.branchcollection import GenericBranchCollection
     from lp.code.model.gitcollection import GenericGitCollection
     # Load the related Branch, _SourcePackageRecipeDataInstruction.
     base_branches = load_related(Branch, sourcepackagerecipedatas,
                                  ['base_branch_id'])
     base_repositories = load_related(GitRepository,
                                      sourcepackagerecipedatas,
                                      ['base_git_repository_id'])
     sprd_instructions = load_referencing(
         _SourcePackageRecipeDataInstruction, sourcepackagerecipedatas,
         ['recipe_data_id'])
     sub_branches = load_related(Branch, sprd_instructions, ['branch_id'])
     sub_repositories = load_related(GitRepository, sprd_instructions,
                                     ['git_repository_id'])
     all_branches = base_branches + sub_branches
     all_repositories = base_repositories + sub_repositories
     # Pre-load branches'/repositories' data.
     if all_branches:
         GenericBranchCollection.preloadDataForBranches(all_branches)
     if all_repositories:
         GenericGitCollection.preloadDataForRepositories(all_repositories)
     # Store the pre-fetched objects on the sourcepackagerecipedatas
     # objects.
     branch_to_recipe_data = {
         instr.branch_id: instr.recipe_data_id
         for instr in sprd_instructions if instr.branch_id is not None
     }
     repository_to_recipe_data = {
         instr.git_repository_id: instr.recipe_data_id
         for instr in sprd_instructions
         if instr.git_repository_id is not None
     }
     caches = {
         sprd.id: [sprd, get_property_cache(sprd)]
         for sprd in sourcepackagerecipedatas
     }
     for _, [sprd, cache] in caches.items():
         cache._referenced_branches = [sprd.base]
     for branch in sub_branches:
         cache = caches[branch_to_recipe_data[branch.id]][1]
         cache._referenced_branches.append(branch)
     for repository in sub_repositories:
         cache = caches[repository_to_recipe_data[repository.id]][1]
         cache._referenced_branches.append(repository)
Пример #5
0
 def test_getRepositories_caches_viewers(self):
     # getRepositories() caches the user as a known viewer so that
     # repository.visibleByUser() does not have to hit the database.
     collection = GenericGitCollection(self.store)
     owner = self.factory.makePerson()
     project = self.factory.makeProduct()
     repository = self.factory.makeGitRepository(
         owner=owner, target=project,
         information_type=InformationType.USERDATA)
     someone = self.factory.makePerson()
     with person_logged_in(owner):
         getUtility(IService, 'sharing').ensureAccessGrants(
             [someone], owner, gitrepositories=[repository],
             ignore_permissions=True)
     [repository] = list(collection.visibleByUser(
         someone).getRepositories())
     with StormStatementRecorder() as recorder:
         self.assertTrue(repository.visibleByUser(someone))
         self.assertThat(recorder, HasQueryCount(Equals(0)))
Пример #6
0
 def test_getRepositoryIds(self):
     repository = self.factory.makeGitRepository()
     self.factory.makeGitRepository()
     collection = GenericGitCollection(
         self.store, [GitRepository.project == repository.target])
     self.assertEqual([repository.id], list(collection.getRepositoryIds()))
Пример #7
0
 def test_getRepositories_no_filter(self):
     # If no filter is specified, then the collection is of all
     # repositories in Launchpad.
     collection = GenericGitCollection(self.store)
     repository = self.factory.makeGitRepository()
     self.assertEqual([repository], list(collection.getRepositories()))
Пример #8
0
 def test_getRepositories_no_filter_no_repositories(self):
     # If no filter is specified, then the collection is of all
     # repositories in Launchpad.  By default, there are no repositories.
     collection = GenericGitCollection(self.store)
     self.assertEqual([], list(collection.getRepositories()))
Пример #9
0
 def test_provides_gitcollection(self):
     # `GenericGitCollection` provides the `IGitCollection`
     # interface.
     self.assertProvides(GenericGitCollection(self.store), IGitCollection)