← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/launchpad:oci-git-more-tests into launchpad:master

 

Colin Watson has proposed merging ~cjwatson/launchpad:oci-git-more-tests into launchpad:master with ~cjwatson/launchpad:oci-git-lookup as a prerequisite.

Commit message:
Add some more tests for OCI project git repositories

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)
Related bugs:
  Bug #1847444 in Launchpad itself: "Support OCI image building"
  https://bugs.launchpad.net/launchpad/+bug/1847444

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/376140

These are all based on tests that exist for other repository target types.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:oci-git-more-tests into launchpad:master.
diff --git a/lib/lp/code/model/tests/test_gitnamespace.py b/lib/lp/code/model/tests/test_gitnamespace.py
index 7585e71..5fed799 100644
--- a/lib/lp/code/model/tests/test_gitnamespace.py
+++ b/lib/lp/code/model/tests/test_gitnamespace.py
@@ -1,4 +1,4 @@
-# Copyright 2015-2018 Canonical Ltd.  This software is licensed under the
+# Copyright 2015-2019 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 """Tests for `IGitNamespace` implementations."""
@@ -348,6 +348,8 @@ class TestPersonalGitNamespace(TestCaseWithFactory, NamespaceMixin):
             owner=owner, target=self.factory.makeProduct())
         self.factory.makeGitRepository(
             owner=owner, target=self.factory.makeDistributionSourcePackage())
+        self.factory.makeGitRepository(
+            owner=owner, target=self.factory.makeOCIProject())
         self.assertContentEqual(
             repositories,
             repositories[0].namespace.collection.getRepositories())
@@ -450,6 +452,7 @@ class TestProjectGitNamespace(TestCaseWithFactory, NamespaceMixin):
             owner=repositories[0].owner, target=repositories[0].owner)
         self.factory.makeGitRepository(
             target=self.factory.makeDistributionSourcePackage())
+        self.factory.makeGitRepository(target=self.factory.makeOCIProject())
         self.assertContentEqual(
             repositories,
             repositories[0].namespace.collection.getRepositories())
@@ -554,6 +557,8 @@ class TestOCIProjectGitNamespace(TestCaseWithFactory, NamespaceMixin):
             target=self.factory.makeOCIProject())
         self.factory.makeGitRepository(target=self.factory.makeProduct())
         self.factory.makeGitRepository(
+            target=self.factory.makeDistributionSourcePackage())
+        self.factory.makeGitRepository(
             owner=repositories[0].owner, target=repositories[0].owner)
         self.assertContentEqual(
             repositories,
@@ -832,6 +837,7 @@ class TestPackageGitNamespace(TestCaseWithFactory, NamespaceMixin):
         self.factory.makeGitRepository(target=self.factory.makeProduct())
         self.factory.makeGitRepository(
             owner=repositories[0].owner, target=repositories[0].owner)
+        self.factory.makeGitRepository(target=self.factory.makeOCIProject())
         self.assertContentEqual(
             repositories,
             repositories[0].namespace.collection.getRepositories())
@@ -958,6 +964,12 @@ class TestNamespaceSet(TestCaseWithFactory):
         namespace = get_git_namespace(dsp, person)
         self.assertIsInstance(namespace, PackageGitNamespace)
 
+    def test_get_oci_project(self):
+        person = self.factory.makePerson()
+        oci_project = self.factory.makeOCIProject()
+        namespace = get_git_namespace(oci_project, person)
+        self.assertIsInstance(namespace, OCIProjectGitNamespace)
+
 
 class TestPersonalGitNamespaceAllowedInformationTypes(TestCaseWithFactory):
     """Tests for PersonalGitNamespace.getAllowedInformationTypes."""
@@ -1001,6 +1013,20 @@ class TestPackageGitNamespaceAllowedInformationTypes(TestCaseWithFactory):
             PUBLIC_INFORMATION_TYPES, namespace.getAllowedInformationTypes())
 
 
+class TestOCIProjectGitNamespaceAllowedInformationTypes(TestCaseWithFactory):
+    """Tests for OCIProjectGitNamespace.getAllowedInformationTypes."""
+
+    layer = DatabaseFunctionalLayer
+
+    def test_anyone(self):
+        # OCI project repositories are always public (for now).
+        oci_project = self.factory.makeOCIProject()
+        person = self.factory.makePerson()
+        namespace = OCIProjectGitNamespace(person, oci_project)
+        self.assertContentEqual(
+            PUBLIC_INFORMATION_TYPES, namespace.getAllowedInformationTypes())
+
+
 class BaseValidateNewRepositoryMixin:
 
     layer = DatabaseFunctionalLayer
@@ -1084,6 +1110,14 @@ class TestPackageGitNamespaceValidateNewRepository(
         return PackageGitNamespace(owner, dsp)
 
 
+class TestOCIProjectGitNamespaceValidateNewRepository(
+    TestCaseWithFactory, BaseValidateNewRepositoryMixin):
+
+    def _getNamespace(self, owner):
+        oci_project = self.factory.makeOCIProject()
+        return OCIProjectGitNamespace(owner, oci_project)
+
+
 class TestProjectGitNamespaceValidateNewRepository(
     TestCaseWithFactory, BaseValidateNewRepositoryMixin):
 
diff --git a/lib/lp/code/model/tests/test_gitrepository.py b/lib/lp/code/model/tests/test_gitrepository.py
index aed13a0..991ba7b 100644
--- a/lib/lp/code/model/tests/test_gitrepository.py
+++ b/lib/lp/code/model/tests/test_gitrepository.py
@@ -1330,6 +1330,17 @@ class TestGitRepositoryNamespace(TestCaseWithFactory):
             sourcepackagename=dsp.sourcepackagename)
         self.assertEqual(namespace, repository.namespace)
 
+    def test_namespace_oci_project(self):
+        # The namespace attribute of an OCI project repository points to the
+        # namespace that corresponds to
+        # ~owner/distribution/+oci/ociprojectname.
+        oci_project = self.factory.makeOCIProject()
+        repository = self.factory.makeGitRepository(target=oci_project)
+        namespace = getUtility(IGitNamespaceSet).get(
+            person=repository.owner, distribution=oci_project.pillar,
+            ociprojectname=oci_project.ociprojectname)
+        self.assertEqual(namespace, repository.namespace)
+
 
 class TestGitRepositoryPendingUpdates(TestCaseWithFactory):
     """Are there changes to this repository not reflected in the database?"""
@@ -1394,6 +1405,15 @@ class TestGitRepositoryPrivacy(TestCaseWithFactory):
         removeSecurityProxy(repository)._reconcileAccess()
         self.assertEqual([], get_policies_for_artifact(repository))
 
+    def test__reconcileAccess_for_oci_project_repository(self):
+        # Git repository privacy isn't yet supported for OCI projects, so no
+        # AccessPolicyArtifact is created for an OCI project repository.
+        repository = self.factory.makeGitRepository(
+            target=self.factory.makeOCIProject(),
+            information_type=InformationType.USERDATA)
+        removeSecurityProxy(repository)._reconcileAccess()
+        self.assertEqual([], get_policies_for_artifact(repository))
+
     def test__reconcileAccess_for_personal_repository(self):
         # _reconcileAccess uses a person policy for a personal repository.
         team_owner = self.factory.makeTeam()
@@ -2181,6 +2201,15 @@ class TestGitRepositorySetTarget(TestCaseWithFactory):
             repository.setTarget(target=dsp, user=owner)
         self.assertEqual(dsp, repository.target)
 
+    def test_personal_to_oci_project(self):
+        # A personal repository can be moved to an OCI project.
+        owner = self.factory.makePerson()
+        repository = self.factory.makeGitRepository(owner=owner, target=owner)
+        oci_project = self.factory.makeOCIProject()
+        with person_logged_in(owner):
+            repository.setTarget(target=oci_project, user=owner)
+        self.assertEqual(oci_project, repository.target)
+
     def test_project_to_other_project(self):
         # Move a repository from one project to another.
         repository = self.factory.makeGitRepository()
@@ -2197,6 +2226,14 @@ class TestGitRepositorySetTarget(TestCaseWithFactory):
             repository.setTarget(target=dsp, user=repository.owner)
         self.assertEqual(dsp, repository.target)
 
+    def test_project_to_oci_project(self):
+        # Move a repository from a project to an OCI project.
+        repository = self.factory.makeGitRepository()
+        oci_project = self.factory.makeOCIProject()
+        with person_logged_in(repository.owner):
+            repository.setTarget(target=oci_project, user=repository.owner)
+        self.assertEqual(oci_project, repository.target)
+
     def test_project_to_personal(self):
         # Move a repository from a project to a personal namespace.
         owner = self.factory.makePerson()
@@ -2223,6 +2260,15 @@ class TestGitRepositorySetTarget(TestCaseWithFactory):
             repository.setTarget(target=project, user=repository.owner)
         self.assertEqual(project, repository.target)
 
+    def test_package_to_oci_project(self):
+        # Move a repository from a package to an OCI project.
+        repository = self.factory.makeGitRepository(
+            target=self.factory.makeDistributionSourcePackage())
+        oci_project = self.factory.makeOCIProject()
+        with person_logged_in(repository.owner):
+            repository.setTarget(target=oci_project, user=repository.owner)
+        self.assertEqual(oci_project, repository.target)
+
     def test_package_to_personal(self):
         # Move a repository from a package to a personal namespace.
         owner = self.factory.makePerson()
@@ -2232,6 +2278,42 @@ class TestGitRepositorySetTarget(TestCaseWithFactory):
             repository.setTarget(target=owner, user=owner)
         self.assertEqual(owner, repository.target)
 
+    def test_oci_project_to_other_package(self):
+        # Move a repository from one OCI project to another.
+        repository = self.factory.makeGitRepository(
+            target=self.factory.makeOCIProject())
+        oci_project = self.factory.makeOCIProject()
+        with person_logged_in(repository.owner):
+            repository.setTarget(target=oci_project, user=repository.owner)
+        self.assertEqual(oci_project, repository.target)
+
+    def test_oci_project_to_project(self):
+        # Move a repository from an OCI project to a project.
+        repository = self.factory.makeGitRepository(
+            target=self.factory.makeOCIProject())
+        project = self.factory.makeProduct()
+        with person_logged_in(repository.owner):
+            repository.setTarget(target=project, user=repository.owner)
+        self.assertEqual(project, repository.target)
+
+    def test_oci_project_to_oci_project(self):
+        # Move a repository from an OCI project to an OCI project.
+        repository = self.factory.makeGitRepository(
+            target=self.factory.makeOCIProject())
+        oci_project = self.factory.makeOCIProject()
+        with person_logged_in(repository.owner):
+            repository.setTarget(target=oci_project, user=repository.owner)
+        self.assertEqual(oci_project, repository.target)
+
+    def test_oci_project_to_personal(self):
+        # Move a repository from an OCI project to a personal namespace.
+        owner = self.factory.makePerson()
+        repository = self.factory.makeGitRepository(
+            owner=owner, target=self.factory.makeOCIProject())
+        with person_logged_in(owner):
+            repository.setTarget(target=owner, user=owner)
+        self.assertEqual(owner, repository.target)
+
     def test_private_personal_forbidden_for_public_teams(self):
         # Only private teams can have private personal repositories.
         owner = self.factory.makeTeam()
diff --git a/lib/lp/code/xmlrpc/tests/test_git.py b/lib/lp/code/xmlrpc/tests/test_git.py
index 757443a..106d1e9 100644
--- a/lib/lp/code/xmlrpc/tests/test_git.py
+++ b/lib/lp/code/xmlrpc/tests/test_git.py
@@ -725,6 +725,16 @@ class TestGitAPI(TestGitAPIMixin, TestCaseWithFactory):
                 requester.name,
                 dsp.distribution.name, dsp.sourcepackagename.name))
 
+    def test_translatePath_create_oci_project(self):
+        # translatePath creates an OCI project repository that doesn't
+        # exist, if it can.
+        requester = self.factory.makePerson()
+        oci_project = self.factory.makeOCIProject()
+        self.assertCreates(
+            requester,
+            u"/~%s/%s/+oci/%s/+git/random" % (
+                requester.name, oci_project.pillar.name, oci_project.name))
+
     def test_translatePath_create_personal(self):
         # translatePath creates a personal repository that doesn't exist, if
         # it can.
@@ -872,6 +882,18 @@ class TestGitAPI(TestGitAPIMixin, TestCaseWithFactory):
         self.assertPermissionDenied(
             requester, path, message=message, permission="write")
 
+    def test_translatePath_create_oci_project_default_denied(self):
+        # A repository cannot (yet) be created and immediately set as the
+        # default for an OCI project.
+        requester = self.factory.makePerson()
+        oci_project = self.factory.makeOCIProject()
+        path = u"/%s/+oci/%s" % (oci_project.pillar.name, oci_project.name)
+        message = (
+            "Cannot automatically set the default repository for this target; "
+            "push to a named repository instead.")
+        self.assertPermissionDenied(
+            requester, path, message=message, permission="write")
+
     def test_translatePath_create_project_owner_default(self):
         # A repository can be created and immediately set as its owner's
         # default for a project.