Skip to content

Commit

Permalink
Merge branch 'canonical:main' into sgmoore/add_core24_support
Browse files Browse the repository at this point in the history
  • Loading branch information
ScarlettGatelyMoore authored Oct 12, 2024
2 parents 0a19bc0 + c905016 commit 19d47f7
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 2 deletions.
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
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

0 comments on commit 19d47f7

Please sign in to comment.