Skip to content

Commit

Permalink
feat: allow specifying components when using edit-validation-sets
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewphelpsj committed Sep 23, 2024
1 parent e402615 commit 282df4f
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 1 deletion.
6 changes: 6 additions & 0 deletions snapcraft/commands/validation_sets.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@
# the provided name.
# presence: [required|optional|invalid] # Optional, defaults to required.
# revision: <n> # The revision of the snap. Optional.
# components: # Constraints to apply to the snap's components. Optional.
# <component-name>: [required|optional|invalid] # Short form for specifying the component's presence.
# <component-name>: # Long form that allows specifying the component's revision.
# presence: [required|optional|invalid] # Presence of the component. Required.
# revision: <n> # The revision of the component, required if the snap's revision is given.
# Otherwise, not allowed.
"""
)

Expand Down
10 changes: 10 additions & 0 deletions snapcraft_legacy/storeapi/v2/validation_sets.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ def _to_string(

return data

class Component(models.CraftBaseModel):
"""Represent a Component in a Validation Set."""

presence: Literal["required", "optional", "invalid"]
"""Component presence"""

revision: int | None = None
"""Component revision"""

class Snap(models.CraftBaseModel):
"""Represent a Snap in a Validation Set."""
Expand All @@ -72,6 +80,8 @@ class Snap(models.CraftBaseModel):
revision: int | None = None
"""Snap revision"""

components: dict[str, str | Component] | None = None
"""Snap components"""

class EditableBuildAssertion(models.CraftBaseModel):
"""Subset of a build assertion that can be edited by the user.
Expand Down
21 changes: 21 additions & 0 deletions tests/legacy/unit/store/v2/test_validation_sets.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ def fake_snap_data():
"id": "snap-id",
"presence": "required",
"revision": 42,
"components": {
"component-with-revision": {
"presence": "required",
"revision": 10,
},
"component-without-revision": "invalid",
},
}


Expand Down Expand Up @@ -125,6 +132,13 @@ def test_editable_build_assertion_marshal_as_str(fake_editable_build_assertion):
"name": "snap-name",
"presence": "required",
"revision": "42",
"components": {
"component-with-revision": {
"presence": "required",
"revision": "10",
},
"component-without-revision": "invalid",
},
},
],
}
Expand All @@ -147,6 +161,13 @@ def test_build_assertion_marshal_as_str(fake_build_assertion):
"name": "snap-name",
"presence": "required",
"revision": "42",
"components": {
"component-with-revision": {
"presence": "required",
"revision": "10",
},
"component-without-revision": "invalid",
},
},
],
"timestamp": "2020-10-29T16:36:56Z",
Expand Down
70 changes: 69 additions & 1 deletion tests/unit/commands/test_validation_sets.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,28 @@
"id": "XXSnapIDForXSnapName2XXXXXXXXXXX",
"name": "snap-name-2",
},
{
"id": "XXSnapIDForXSnapName3XXXXXXXXXXX",
"name": "snap-name-3",
"presence": "optional",
"revision": "1",
"components": {
"comp-name-1": {
"presence": "required",
"revision": "11",
},
},
},
{
"id": "XXSnapIDForXSnapName4XXXXXXXXXXX",
"name": "snap-name-4",
"presence": "optional",
"components": {
"comp-name-1": "required",
"comp-name-2": "optional",
"comp-name-3": "invalid",
},
},
],
"timestamp": "2020-10-29T16:36:56Z",
"type": "validation-set",
Expand Down Expand Up @@ -125,6 +147,28 @@ def edit_return_value():
"revision": "10",
},
{"id": "XXSnapIDForXSnapName2XXXXXXXXXXX", "name": "snap-name-2"},
{
"id": "XXSnapIDForXSnapName3XXXXXXXXXXX",
"name": "snap-name-3",
"presence": "optional",
"revision": "1",
"components": {
"comp-name-1": {
"presence": "required",
"revision": "11",
},
},
},
{
"id": "XXSnapIDForXSnapName4XXXXXXXXXXX",
"name": "snap-name-4",
"presence": "optional",
"components": {
"comp-name-1": "required",
"comp-name-2": "optional",
"comp-name-3": "invalid",
},
},
],
}
)
Expand Down Expand Up @@ -157,6 +201,28 @@ def fake_edit_validation_sets(mocker, edit_return_value):
"revision": 10,
},
{"name": "snap-name-2", "id": "XXSnapIDForXSnapName2XXXXXXXXXXX"},
{
"id": "XXSnapIDForXSnapName3XXXXXXXXXXX",
"name": "snap-name-3",
"presence": "optional",
"revision": 1,
"components": {
"comp-name-1": {
"presence": "required",
"revision": 11,
},
},
},
{
"id": "XXSnapIDForXSnapName4XXXXXXXXXXX",
"name": "snap-name-4",
"presence": "optional",
"components": {
"comp-name-1": "required",
"comp-name-2": "optional",
"comp-name-3": "invalid",
},
},
],
}
)
Expand All @@ -165,7 +231,9 @@ def fake_edit_validation_sets(mocker, edit_return_value):
'{{"account-id": "AccountIDXXXOfTheRequestingUserX", "name": "certification-x1", '
'"revision": "222", "sequence": "9", "snaps": [{{"name": "snap-name-1", "id": '
'"XXSnapIDForXSnapName1XXXXXXXXXXX", "presence": "optional", "revision": "10"}}, '
'{{"name": "snap-name-2", "id": "XXSnapIDForXSnapName2XXXXXXXXXXX"}}], '
'{{"name": "snap-name-2", "id": "XXSnapIDForXSnapName2XXXXXXXXXXX"}}, '
'{{"name": "snap-name-3", "id": "XXSnapIDForXSnapName3XXXXXXXXXXX", "presence": "optional", "revision": "1", "components": {{"comp-name-1": {{"presence": "required", "revision": "11"}}}}}}, '
'{{"name": "snap-name-4", "id": "XXSnapIDForXSnapName4XXXXXXXXXXX", "presence": "optional", "components": {{"comp-name-1": "required", "comp-name-2": "optional", "comp-name-3": "invalid"}}}}], '
'"authority-id": "AccountIDXXXOfTheRequestingUserX", "series": "16", "timestamp": '
'"2020-10-29T16:36:56Z", "type": "validation-set"}}\n\nSIGNED{key_name}'
)
Expand Down

0 comments on commit 282df4f

Please sign in to comment.