← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/launchpad:fix-core24 into launchpad:master

 

Colin Watson has proposed merging ~cjwatson/launchpad:fix-core24 into launchpad:master.

Commit message:
Fix tests for addition of core24

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)
Related bugs:
  Bug #2012405 in Launchpad itself: "Support for core24 base"
  https://bugs.launchpad.net/launchpad/+bug/2012405

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

I also further reduced the number of tests that will need attention the next time we add a core snap version.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:fix-core24 into launchpad:master.
diff --git a/lib/lp/app/widgets/tests/test_snapbuildchannels.py b/lib/lp/app/widgets/tests/test_snapbuildchannels.py
index 107c023..0fc6ce0 100644
--- a/lib/lp/app/widgets/tests/test_snapbuildchannels.py
+++ b/lib/lp/app/widgets/tests/test_snapbuildchannels.py
@@ -42,10 +42,10 @@ class TestSnapBuildChannelsWidget(TestCaseWithFactory):
         # The subwidgets are set up and a flag is set.
         self.widget.setUpSubWidgets()
         self.assertTrue(self.widget._widgets_set_up)
-        self.assertIsNotNone(getattr(self.widget, "core_widget", None))
-        self.assertIsNotNone(getattr(self.widget, "core18_widget", None))
-        self.assertIsNotNone(getattr(self.widget, "core20_widget", None))
-        self.assertIsNotNone(getattr(self.widget, "core22_widget", None))
+        for snap_name in self.field._core_snap_names:
+            self.assertIsNotNone(
+                getattr(self.widget, "%s_widget" % snap_name, None)
+            )
         self.assertIsNotNone(getattr(self.widget, "snapcraft_widget", None))
 
     def test_setUpSubWidgets_second_call(self):
@@ -53,40 +53,45 @@ class TestSnapBuildChannelsWidget(TestCaseWithFactory):
         # indicate that the widgets were set up.
         self.widget._widgets_set_up = True
         self.widget.setUpSubWidgets()
-        self.assertIsNone(getattr(self.widget, "core_widget", None))
-        self.assertIsNone(getattr(self.widget, "core18_widget", None))
-        self.assertIsNone(getattr(self.widget, "core20_widget", None))
-        self.assertIsNone(getattr(self.widget, "core22_widget", None))
+        for snap_name in self.field._core_snap_names:
+            self.assertIsNone(
+                getattr(self.widget, "%s_widget" % snap_name, None)
+            )
         self.assertIsNone(getattr(self.widget, "snapcraft_widget", None))
 
     def test_setRenderedValue_None(self):
         self.widget.setRenderedValue(None)
-        self.assertIsNone(self.widget.core_widget._getCurrentValue())
-        self.assertIsNone(self.widget.core18_widget._getCurrentValue())
-        self.assertIsNone(self.widget.core20_widget._getCurrentValue())
-        self.assertIsNone(self.widget.core22_widget._getCurrentValue())
+        for snap_name in self.field._core_snap_names:
+            self.assertIsNone(
+                getattr(
+                    self.widget, "%s_widget" % snap_name
+                )._getCurrentValue()
+            )
         self.assertIsNone(self.widget.snapcraft_widget._getCurrentValue())
 
     def test_setRenderedValue_empty(self):
         self.widget.setRenderedValue({})
-        self.assertIsNone(self.widget.core_widget._getCurrentValue())
-        self.assertIsNone(self.widget.core18_widget._getCurrentValue())
-        self.assertIsNone(self.widget.core20_widget._getCurrentValue())
-        self.assertIsNone(self.widget.core22_widget._getCurrentValue())
+        for snap_name in self.field._core_snap_names:
+            self.assertIsNone(
+                getattr(
+                    self.widget, "%s_widget" % snap_name
+                )._getCurrentValue()
+            )
         self.assertIsNone(self.widget.snapcraft_widget._getCurrentValue())
 
     def test_setRenderedValue_one_channel(self):
         self.widget.setRenderedValue({"snapcraft": "stable"})
-        self.assertIsNone(self.widget.core_widget._getCurrentValue())
-        self.assertIsNone(self.widget.core18_widget._getCurrentValue())
-        self.assertIsNone(self.widget.core20_widget._getCurrentValue())
-        self.assertIsNone(self.widget.core20_widget._getCurrentValue())
-        self.assertIsNone(self.widget.core22_widget._getCurrentValue())
+        for snap_name in self.field._core_snap_names:
+            self.assertIsNone(
+                getattr(
+                    self.widget, "%s_widget" % snap_name
+                )._getCurrentValue()
+            )
         self.assertEqual(
             "stable", self.widget.snapcraft_widget._getCurrentValue()
         )
 
-    def test_setRenderedValue_all_channels(self):
+    def test_setRenderedValue_multiple_channels(self):
         self.widget.setRenderedValue(
             {
                 "core": "candidate",
@@ -125,23 +130,33 @@ class TestSnapBuildChannelsWidget(TestCaseWithFactory):
         # (At the moment, individual channel names are not validated, so
         # there is no "false" counterpart to this test.)
         form = {
-            "field.auto_build_channels.core": "",
-            "field.auto_build_channels.core18": "beta",
-            "field.auto_build_channels.core20": "edge",
-            "field.auto_build_channels.core22": "edge/feature",
-            "field.auto_build_channels.snapcraft": "stable",
+            "field.auto_build_channels.%s" % snap_name: ""
+            for snap_name in self.field._core_snap_names
         }
+        form.update(
+            {
+                "field.auto_build_channels.core18": "beta",
+                "field.auto_build_channels.core20": "edge",
+                "field.auto_build_channels.core22": "edge/feature",
+                "field.auto_build_channels.snapcraft": "stable",
+            }
+        )
         self.widget.request = LaunchpadTestRequest(form=form)
         self.assertTrue(self.widget.hasValidInput())
 
     def test_getInputValue(self):
         form = {
-            "field.auto_build_channels.core": "",
-            "field.auto_build_channels.core18": "beta",
-            "field.auto_build_channels.core20": "edge",
-            "field.auto_build_channels.core22": "edge/feature",
-            "field.auto_build_channels.snapcraft": "stable",
+            "field.auto_build_channels.%s" % snap_name: ""
+            for snap_name in self.field._core_snap_names
         }
+        form.update(
+            {
+                "field.auto_build_channels.core18": "beta",
+                "field.auto_build_channels.core20": "edge",
+                "field.auto_build_channels.core22": "edge/feature",
+                "field.auto_build_channels.snapcraft": "stable",
+            }
+        )
         self.widget.request = LaunchpadTestRequest(form=form)
         self.assertEqual(
             {
@@ -156,19 +171,15 @@ class TestSnapBuildChannelsWidget(TestCaseWithFactory):
     def test_call(self):
         # The __call__ method sets up the widgets.
         markup = self.widget()
-        self.assertIsNotNone(self.widget.core_widget)
-        self.assertIsNotNone(self.widget.core18_widget)
-        self.assertIsNotNone(self.widget.core20_widget)
-        self.assertIsNotNone(self.widget.core22_widget)
+        for snap_name in self.field._core_snap_names:
+            self.assertIsNotNone(getattr(self.widget, "%s_widget" % snap_name))
         self.assertIsNotNone(self.widget.snapcraft_widget)
         soup = BeautifulSoup(markup)
         fields = soup.find_all(["input"], {"id": re.compile(".*")})
         expected_ids = [
-            "field.auto_build_channels.core",
-            "field.auto_build_channels.core18",
-            "field.auto_build_channels.core20",
-            "field.auto_build_channels.core22",
-            "field.auto_build_channels.snapcraft",
+            "field.auto_build_channels.%s" % snap_name
+            for snap_name in self.field._core_snap_names
         ]
+        expected_ids.append("field.auto_build_channels.snapcraft")
         ids = [field["id"] for field in fields]
         self.assertContentEqual(expected_ids, ids)
diff --git a/lib/lp/charms/browser/tests/test_charmrecipe.py b/lib/lp/charms/browser/tests/test_charmrecipe.py
index 60c561e..997b711 100644
--- a/lib/lp/charms/browser/tests/test_charmrecipe.py
+++ b/lib/lp/charms/browser/tests/test_charmrecipe.py
@@ -1682,6 +1682,7 @@ class TestCharmRecipeRequestBuildsView(BaseTestCharmRecipeView):
             core18
             core20
             core22
+            core24
             The channels to use for build tools when building the charm
             recipe.
             or
diff --git a/lib/lp/snappy/browser/tests/test_snap.py b/lib/lp/snappy/browser/tests/test_snap.py
index 4821790..1efc57d 100644
--- a/lib/lp/snappy/browser/tests/test_snap.py
+++ b/lib/lp/snappy/browser/tests/test_snap.py
@@ -2653,6 +2653,7 @@ class TestSnapRequestBuildsView(BaseTestSnapView):
             core18
             core20
             core22
+            core24
             snapcraft
             snapd
             The channels to use for build tools when building the snap