← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~twom/launchpad:oci-recipe-push-rules-api into launchpad:master

 

Tom Wardill has proposed merging ~twom/launchpad:oci-recipe-push-rules-api into launchpad:master.

Commit message:
Add push_rules to the export of recipe

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

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

Push Rules should be available from the recipe, they currently aren't.
Export the attribute an API user can retrieve relevant push rules.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~twom/launchpad:oci-recipe-push-rules-api into launchpad:master.
diff --git a/lib/lp/oci/interfaces/ocirecipe.py b/lib/lp/oci/interfaces/ocirecipe.py
index 4562687..dbaf087 100644
--- a/lib/lp/oci/interfaces/ocirecipe.py
+++ b/lib/lp/oci/interfaces/ocirecipe.py
@@ -209,12 +209,12 @@ class IOCIRecipeView(Interface):
         :return: `IOCIRecipeBuild`.
         """
 
-    push_rules = CollectionField(
+    push_rules = exported(CollectionField(
         title=_("Push rules for this OCI recipe."),
         description=_("All of the push rules for registry upload "
                       "that apply to this recipe."),
         # Really IOCIPushRule, patched in _schema_cirular_imports.
-        value_type=Reference(schema=Interface), readonly=True)
+        value_type=Reference(schema=Interface), readonly=True))
 
     can_upload_to_registry = Bool(
         title=_("Can upload to registry"), required=True, readonly=True,
diff --git a/lib/lp/oci/tests/test_ocirecipe.py b/lib/lp/oci/tests/test_ocirecipe.py
index 4c8a126..833a675 100644
--- a/lib/lp/oci/tests/test_ocirecipe.py
+++ b/lib/lp/oci/tests/test_ocirecipe.py
@@ -39,9 +39,6 @@ from lp.oci.interfaces.ocirecipe import (
     OCIRecipeNotOwner,
     )
 from lp.oci.interfaces.ocirecipebuild import IOCIRecipeBuildSet
-from lp.oci.interfaces.ociregistrycredentials import (
-    OCIRegistryCredentialsAlreadyExist,
-    )
 from lp.oci.tests.helpers import OCIConfigHelperMixin
 from lp.services.config import config
 from lp.services.database.constants import (
@@ -763,3 +760,25 @@ class TestOCIRecipeWebservice(OCIConfigHelperMixin, TestCaseWithFactory):
         new_obj_url = resp.getHeader("Location")
         ws_push_rule = self.load_from_api(new_obj_url)
         self.assertEqual(obj["image_name"], ws_push_rule["image_name"])
+
+    def test_api_push_rules_exported(self):
+        """Are push rules exported for a recipe?"""
+        self.setConfig()
+
+        image_name = self.factory.getUniqueUnicode()
+
+        with person_logged_in(self.person):
+            oci_project = self.factory.makeOCIProject(
+                registrant=self.person)
+            recipe = self.factory.makeOCIRecipe(
+                oci_project=oci_project, owner=self.person,
+                registrant=self.person)
+            push_rule = self.factory.makeOCIPushRule(
+                recipe=recipe, image_name=image_name)
+            url = api_url(recipe)
+
+        ws_recipe = self.load_from_api(url)
+        push_rules = self.load_from_api(
+            ws_recipe["push_rules_collection_link"])
+        self.assertEqual(
+            image_name, push_rules["entries"][0]["image_name"])