Skip to content

Commit 1e865e7

Browse files
committed
AWS: Fix bug on PromotionalResources model
This commit fixes a bug in the `PromotionalResources` which did expected the attribute `promotional_media` to be an optional string, while it should be an optional list of resources. It also introduces the class `PromotionalMedia` to map the missing resource type. Refers to SPSTRAT-671 Signed-off-by: Jonathan Gangi <[email protected]>
1 parent 06364cf commit 1e865e7

File tree

3 files changed

+63
-2
lines changed

3 files changed

+63
-2
lines changed

cloudpub/models/aws.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -638,12 +638,26 @@ class PromoResourcesVideo(BaseResources):
638638
"""The promotional video title."""
639639

640640

641+
@define
642+
class PromotionalMedia(BaseResources):
643+
"""Represent a single element of promotional media from class :class:`~cloudpub.models.aws.PromotionalResources`.""" # noqa: E501
644+
645+
title: str = field(validator=instance_of(str), metadata={"alias": "Title"})
646+
"""The title of the promotional media resource."""
647+
648+
description: Optional[str] = field(
649+
validator=optional(instance_of(str)), metadata={"alias": "Description"}
650+
)
651+
"""The description of the promotional media resource."""
652+
653+
641654
@define
642655
class PromotionalResources(AttrsJSONDecodeMixin):
643656
"""Represent the "PromotionalResources" section of the :class:`~cloudpub.models.aws.ProductDetailResponse`.""" # noqa: E501
644657

645-
promotional_media: Optional[str] = field(
646-
validator=optional(instance_of(str)),
658+
promotional_media: Optional[List[PromotionalMedia]] = field(
659+
converter=lambda x: [PromotionalMedia.from_json(a) for a in x] if x else None,
660+
on_setattr=NO_OP,
647661
metadata={"alias": "PromotionalMedia", "hide_unset": True},
648662
)
649663
"""The product's promotional media."""

docs/cloud_providers/models/aws.rst.incl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ Resources internal elements
122122
.. autoclass:: cloudpub.models.aws.PromoResourcesVideo()
123123
:members:
124124

125+
.. autoclass:: cloudpub.models.aws.PromotionalMedia()
126+
:members:
127+
125128
.. autoclass:: cloudpub.models.aws.PositiveTargeting()
126129
:members:
127130

tests/aws/test_models.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
ProductVersionsBase,
1717
ProductVersionsCloudFormationSource,
1818
ProductVersionsVirtualizationSource,
19+
PromotionalMedia,
20+
PromotionalResources,
1921
SecurityGroup,
2022
Version,
2123
VersionMapping,
@@ -125,3 +127,45 @@ def test_describe_entity_response_parsed_details(
125127
def test_list_changeset_response_parsed(list_changeset_response: Dict[str, Any]) -> None:
126128
resp = ListChangeSetsResponse.from_json(list_changeset_response)
127129
assert len(resp.change_set_list) == 1
130+
131+
132+
@pytest.mark.parametrize(
133+
"promotional_media",
134+
[
135+
None,
136+
[
137+
{
138+
'Type': 'Image',
139+
'Url': 'https://foo.com/bar.png',
140+
'Title': 'Logo1',
141+
'Description': None,
142+
}
143+
],
144+
[
145+
{
146+
'Type': 'Image',
147+
'Url': 'https://foo.com/bar.png',
148+
'Title': 'Logo1',
149+
'Description': 'This is the logo1',
150+
},
151+
{
152+
'Type': 'Video',
153+
'Url': 'https://foo.com/video.mp4',
154+
'Title': 'Video',
155+
'Description': 'This is the promotional video',
156+
},
157+
],
158+
],
159+
)
160+
def test_promotional_resources_promotional_media(
161+
promotional_media, promotional_resource: Dict[str, Any]
162+
) -> None:
163+
promotional_resource["PromotionalMedia"] = promotional_media
164+
165+
obj = PromotionalResources.from_json(promotional_resource)
166+
167+
assert obj
168+
if not promotional_media:
169+
assert obj.promotional_media is None
170+
else:
171+
assert obj.promotional_media == [PromotionalMedia.from_json(x) for x in promotional_media]

0 commit comments

Comments
 (0)