Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow specifying components when using edit-validation-sets #5059

Merged
merged 1 commit into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
mr-cal marked this conversation as resolved.
Show resolved Hide resolved
"""
)

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

return data

Presence = Literal["required", "optional", "invalid"]

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

presence: Presence
"""Component presence"""

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

class Snap(models.CraftBaseModel):
"""Represent a Snap in a Validation Set."""
Expand All @@ -66,12 +76,14 @@ class Snap(models.CraftBaseModel):
id: SnapId | None = None
"""Snap ID"""

presence: Literal["required", "optional", "invalid"] | None = None
presence: Presence | None = None
"""Snap presence"""

revision: int | None = None
"""Snap revision"""

components: dict[str, Presence | 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
Loading