← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~jugmac00/launchpad:improve-exception-message-when-repository-creation-fails into launchpad:master

 

Jürgen Gmach has proposed merging ~jugmac00/launchpad:improve-exception-message-when-repository-creation-fails into launchpad:master.

Commit message:
Improve exception message when Git repository creation fails

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~jugmac00/launchpad/+git/launchpad/+merge/480676
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~jugmac00/launchpad:improve-exception-message-when-repository-creation-fails into launchpad:master.
diff --git a/lib/lp/code/model/gitnamespace.py b/lib/lp/code/model/gitnamespace.py
index 5586f4d..c210e1f 100644
--- a/lib/lp/code/model/gitnamespace.py
+++ b/lib/lp/code/model/gitnamespace.py
@@ -190,7 +190,8 @@ class _BaseGitNamespace:
 
         if not self.getAllowedInformationTypes(registrant):
             raise GitRepositoryCreationForbidden(
-                'You cannot create Git repositories in "%s"' % self.name
+                'You cannot create Git repositories in "%s" (context: %s)'
+                % (self.name, self.__class__.__name__)
             )
 
     def validateRepositoryName(self, name):
diff --git a/lib/lp/code/model/tests/test_gitnamespace.py b/lib/lp/code/model/tests/test_gitnamespace.py
index ab477b9..bc61a22 100644
--- a/lib/lp/code/model/tests/test_gitnamespace.py
+++ b/lib/lp/code/model/tests/test_gitnamespace.py
@@ -20,6 +20,7 @@ from lp.app.validators import LaunchpadValidationError
 from lp.code.enums import GitRepositoryType
 from lp.code.errors import (
     GitDefaultConflict,
+    GitRepositoryCreationForbidden,
     GitRepositoryCreatorNotMemberOfOwnerTeam,
     GitRepositoryCreatorNotOwner,
     GitRepositoryExists,
@@ -1339,6 +1340,19 @@ class TestProjectGitNamespaceCanCreateBranches(
         namespace = self._getNamespace(person, BranchSharingPolicy.PROPRIETARY)
         self.assertFalse(namespace.canCreateRepositories(person))
 
+    def test_any_person_with_proprietary_repositories_raises_exception(self):
+        # If the sharing policy defaults to PROPRIETARY, then non-privileged
+        # users cannot create a repository - this raises an exception.
+        person = self.factory.makePerson()
+        namespace = self._getNamespace(person, BranchSharingPolicy.PROPRIETARY)
+        self.assertRaisesWithContent(
+            GitRepositoryCreationForbidden,
+            'You cannot create Git repositories in "%s" (context: %s)'
+            % (namespace.name, namespace.__class__.__name__),
+            namespace.validateRegistrant,
+            person,
+        )
+
     def test_grantee_with_proprietary_repositories(self):
         # If the sharing policy defaults to PROPRIETARY, then non-privileged
         # users cannot create a repository.

Follow ups