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

Proposed by Tom Wardill
Status: Merged
Approved by: Tom Wardill
Approved revision: ffc235f486ee1797cb0a5cae78e1074cfb9b482c
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~twom/launchpad:oci-recipe-push-rules-api
Merge into: launchpad:master
Diff against target: 59 lines (+24/-5)
2 files modified
lib/lp/oci/interfaces/ocirecipe.py (+2/-2)
lib/lp/oci/tests/test_ocirecipe.py (+22/-3)
Reviewer Review Type Date Requested Status
Colin Watson (community) Approve
Review via email: mp+382771@code.launchpad.net

Commit message

Add push_rules to the export of recipe

Description of the change

Push Rules should be available from the recipe, they currently aren't.
Export the attribute an API user can retrieve relevant push rules.

To post a comment you must log in.
Revision history for this message
Colin Watson (cjwatson) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/oci/interfaces/ocirecipe.py b/lib/lp/oci/interfaces/ocirecipe.py
2index 4562687..dbaf087 100644
3--- a/lib/lp/oci/interfaces/ocirecipe.py
4+++ b/lib/lp/oci/interfaces/ocirecipe.py
5@@ -209,12 +209,12 @@ class IOCIRecipeView(Interface):
6 :return: `IOCIRecipeBuild`.
7 """
8
9- push_rules = CollectionField(
10+ push_rules = exported(CollectionField(
11 title=_("Push rules for this OCI recipe."),
12 description=_("All of the push rules for registry upload "
13 "that apply to this recipe."),
14 # Really IOCIPushRule, patched in _schema_cirular_imports.
15- value_type=Reference(schema=Interface), readonly=True)
16+ value_type=Reference(schema=Interface), readonly=True))
17
18 can_upload_to_registry = Bool(
19 title=_("Can upload to registry"), required=True, readonly=True,
20diff --git a/lib/lp/oci/tests/test_ocirecipe.py b/lib/lp/oci/tests/test_ocirecipe.py
21index 4c8a126..833a675 100644
22--- a/lib/lp/oci/tests/test_ocirecipe.py
23+++ b/lib/lp/oci/tests/test_ocirecipe.py
24@@ -39,9 +39,6 @@ from lp.oci.interfaces.ocirecipe import (
25 OCIRecipeNotOwner,
26 )
27 from lp.oci.interfaces.ocirecipebuild import IOCIRecipeBuildSet
28-from lp.oci.interfaces.ociregistrycredentials import (
29- OCIRegistryCredentialsAlreadyExist,
30- )
31 from lp.oci.tests.helpers import OCIConfigHelperMixin
32 from lp.services.config import config
33 from lp.services.database.constants import (
34@@ -763,3 +760,25 @@ class TestOCIRecipeWebservice(OCIConfigHelperMixin, TestCaseWithFactory):
35 new_obj_url = resp.getHeader("Location")
36 ws_push_rule = self.load_from_api(new_obj_url)
37 self.assertEqual(obj["image_name"], ws_push_rule["image_name"])
38+
39+ def test_api_push_rules_exported(self):
40+ """Are push rules exported for a recipe?"""
41+ self.setConfig()
42+
43+ image_name = self.factory.getUniqueUnicode()
44+
45+ with person_logged_in(self.person):
46+ oci_project = self.factory.makeOCIProject(
47+ registrant=self.person)
48+ recipe = self.factory.makeOCIRecipe(
49+ oci_project=oci_project, owner=self.person,
50+ registrant=self.person)
51+ push_rule = self.factory.makeOCIPushRule(
52+ recipe=recipe, image_name=image_name)
53+ url = api_url(recipe)
54+
55+ ws_recipe = self.load_from_api(url)
56+ push_rules = self.load_from_api(
57+ ws_recipe["push_rules_collection_link"])
58+ self.assertEqual(
59+ image_name, push_rules["entries"][0]["image_name"])

Subscribers

People subscribed via source and target branches

to status/vote changes: