-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: update resource revisions (#130)
- Loading branch information
Showing
7 changed files
with
283 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*- | ||
# | ||
# Copyright 2023 Canonical Ltd. | ||
# | ||
# This program is free software; you can redistribute it and/or | ||
# modify it under the terms of the GNU Lesser General Public | ||
# License version 3 as published by the Free Software Foundation. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
# Lesser General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Lesser General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
"""Tests for update_resource_revisions.""" | ||
|
||
from craft_store.models.resource_revision_model import ( | ||
CharmResourceRevisionUpdateRequest, | ||
RequestCharmResourceBase, | ||
) | ||
|
||
from .conftest import needs_charmhub_credentials | ||
|
||
|
||
@needs_charmhub_credentials() | ||
def test_charm_update_resource_revisions(charm_client, charmhub_charm_name): | ||
resource_name = "empty-file" | ||
|
||
revisions = charm_client.list_resource_revisions(charmhub_charm_name, resource_name) | ||
revision_numbers = [r.revision for r in revisions[-2:]] | ||
assert len(revision_numbers) == 2, "Needs more resource revisions" | ||
|
||
resource_updates = [ | ||
CharmResourceRevisionUpdateRequest( | ||
revision=revision_number, | ||
bases=[ | ||
RequestCharmResourceBase( | ||
name="ubuntu", | ||
channel="22.04", | ||
architectures=["riscv64"], | ||
) | ||
], | ||
) | ||
for revision_number in revision_numbers | ||
] | ||
default_updates = [ | ||
CharmResourceRevisionUpdateRequest( | ||
revision=revision_number, | ||
bases=[ | ||
RequestCharmResourceBase( | ||
name="all", channel="all", architectures=["all"] | ||
) | ||
], | ||
) | ||
for revision_number in revision_numbers | ||
] | ||
|
||
update_count = charm_client.update_resource_revisions( | ||
*resource_updates, name=charmhub_charm_name, resource_name="empty-file" | ||
) | ||
assert update_count == len(resource_updates) | ||
|
||
# Reset back to the default. | ||
update_count = charm_client.update_resource_revisions( | ||
*default_updates, name=charmhub_charm_name, resource_name="empty-file" | ||
) | ||
assert update_count == len(default_updates) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*- | ||
# | ||
# Copyright 2023 Canonical Ltd. | ||
# | ||
# This program is free software; you can redistribute it and/or | ||
# modify it under the terms of the GNU Lesser General Public | ||
# License version 3 as published by the Free Software Foundation. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
# Lesser General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Lesser General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
"""Tests for resource revision models.""" | ||
import pydantic | ||
import pytest | ||
from craft_store.models import CharmResourceRevisionUpdateRequest | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("request_dict", "match"), | ||
[ | ||
({"revision": 1}, r"bases[:\s]+field required"), | ||
( | ||
{"revision": 1, "bases": []}, | ||
r"bases[:\s]+ensure this value has at least 1 item", | ||
), | ||
( | ||
{"revision": 1, "bases": [{"architectures": ["all", "all"]}]}, | ||
r"bases -> 0 -> architectures[:\s]+the list has duplicated items", | ||
), | ||
( | ||
{"revision": 1, "bases": [{"architectures": []}]}, | ||
r"bases -> 0 -> architectures[:\s]+ensure this value has at least 1 item", | ||
), | ||
], | ||
) | ||
def test_charmresourcerevisionupdaterequest_invalid_bases(request_dict, match): | ||
with pytest.raises(pydantic.ValidationError, match=match): | ||
CharmResourceRevisionUpdateRequest.unmarshal(request_dict) |
Oops, something went wrong.