← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~pappacena/launchpad:fix-overriding-ocirecipe-error-msg into launchpad:master

 

Thiago F. Pappacena has proposed merging ~pappacena/launchpad:fix-overriding-ocirecipe-error-msg into launchpad:master.

Commit message:
Avoid overriding important OCIRecipe form error msg

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~pappacena/launchpad/+git/launchpad/+merge/396390
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~pappacena/launchpad:fix-overriding-ocirecipe-error-msg into launchpad:master.
diff --git a/lib/lp/oci/browser/ocirecipe.py b/lib/lp/oci/browser/ocirecipe.py
index a2543e6..a2b8119 100644
--- a/lib/lp/oci/browser/ocirecipe.py
+++ b/lib/lp/oci/browser/ocirecipe.py
@@ -908,6 +908,9 @@ class OCIRecipeEditView(BaseOCIRecipeEditView, EnableProcessorsMixin,
         oci_proj_url = canonical_url(oci_proj)
         widget = self.widgets["git_ref"]
         widget.setUpSubWidgets()
+        if widget.error():
+            # Do not override more important git_ref errors.
+            return
         msg = None
         if self.context.git_ref.namespace.target != self.context.oci_project:
             msg = ("This recipe's git repository is not in the "
diff --git a/lib/lp/oci/browser/tests/test_ocirecipe.py b/lib/lp/oci/browser/tests/test_ocirecipe.py
index afea558..3505fd3 100644
--- a/lib/lp/oci/browser/tests/test_ocirecipe.py
+++ b/lib/lp/oci/browser/tests/test_ocirecipe.py
@@ -723,6 +723,34 @@ class TestOCIRecipeEditView(OCIConfigHelperMixin, BaseTestOCIRecipeView):
             "This recipe's git repository is not in the correct namespace",
             browser.contents)
 
+    def test_edit_repository_dont_override_important_msgs(self):
+        self.setUpDistroSeries()
+        oci_project = self.factory.makeOCIProject(
+            registrant=self.person, pillar=self.distribution)
+
+        [git_ref] = self.factory.makeGitRefs()
+        recipe = self.factory.makeOCIRecipe(
+            registrant=self.person, owner=self.person, oci_project=oci_project,
+            git_ref=git_ref)
+
+        wrong_namespace_msg = (
+            "This recipe's git repository is not in the correct namespace")
+        wrong_ref_path_msg = (
+                "The repository at %s does not contain a branch named "
+                "'non-existing git-ref'."
+            ) % git_ref.repository.display_name
+        with person_logged_in(self.person):
+            browser = self.getViewBrowser(
+                recipe, view_name="+edit", user=self.person)
+            self.assertIn(wrong_namespace_msg, browser.contents)
+            args = browser.getControl(name="field.git_ref.path")
+            args.value = "non-existing git-ref"
+            browser.getControl("Update OCI recipe").click()
+
+            # The error message should have changed.
+            self.assertNotIn(wrong_namespace_msg, browser.contents)
+            self.assertIn(wrong_ref_path_msg, browser.contents)
+
 
 class TestOCIRecipeDeleteView(BaseTestOCIRecipeView):
 

Follow ups