cloud-radar 0.14.1a2__py3-none-any.whl → 0.15.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- cloud_radar/cf/unit/_output.py +5 -4
- cloud_radar/cf/unit/_template.py +12 -4
- cloud_radar/cf/unit/functions.py +13 -4
- {cloud_radar-0.14.1a2.dist-info → cloud_radar-0.15.0.dist-info}/METADATA +4 -2
- {cloud_radar-0.14.1a2.dist-info → cloud_radar-0.15.0.dist-info}/RECORD +7 -7
- {cloud_radar-0.14.1a2.dist-info → cloud_radar-0.15.0.dist-info}/LICENSE.txt +0 -0
- {cloud_radar-0.14.1a2.dist-info → cloud_radar-0.15.0.dist-info}/WHEEL +0 -0
cloud_radar/cf/unit/_output.py
CHANGED
@@ -27,11 +27,12 @@ class Output(UserDict):
|
|
27
27
|
Args:
|
28
28
|
value (Any): The value to compare the output value to.
|
29
29
|
"""
|
30
|
-
|
30
|
+
actual_value = self.get_value()
|
31
31
|
|
32
|
-
assert (
|
33
|
-
value
|
34
|
-
|
32
|
+
assert value == actual_value, (
|
33
|
+
f"Output '{self.name}' actual value ({actual_value}) did not match"
|
34
|
+
f" input value ({value})."
|
35
|
+
)
|
35
36
|
|
36
37
|
def has_export(self):
|
37
38
|
"""Check if the output has an export."""
|
cloud_radar/cf/unit/_template.py
CHANGED
@@ -232,7 +232,6 @@ class Template:
|
|
232
232
|
return {**functions.ALL_FUNCTIONS, **transform_functions}
|
233
233
|
|
234
234
|
if isinstance(self.transforms, list):
|
235
|
-
|
236
235
|
transform_functions = {}
|
237
236
|
|
238
237
|
for transform in self.transforms:
|
@@ -505,8 +504,14 @@ class Template:
|
|
505
504
|
|
506
505
|
t_params: dict = self.template["Parameters"]
|
507
506
|
|
508
|
-
|
509
|
-
|
507
|
+
params_not_in_template = set(parameters) - set(t_params)
|
508
|
+
if params_not_in_template:
|
509
|
+
raise ValueError(
|
510
|
+
(
|
511
|
+
"You supplied one or more Parameters that were not in the "
|
512
|
+
f"Template - {params_not_in_template}"
|
513
|
+
)
|
514
|
+
)
|
510
515
|
|
511
516
|
for p_name, p_value in t_params.items():
|
512
517
|
if p_name in parameters:
|
@@ -519,7 +524,10 @@ class Template:
|
|
519
524
|
|
520
525
|
if "Default" not in p_value:
|
521
526
|
raise ValueError(
|
522
|
-
|
527
|
+
(
|
528
|
+
f'Must provide values for parameter "{p_name}" '
|
529
|
+
"that does not have a default value."
|
530
|
+
)
|
523
531
|
)
|
524
532
|
|
525
533
|
t_params[p_name]["Value"] = p_value["Default"]
|
cloud_radar/cf/unit/functions.py
CHANGED
@@ -459,14 +459,17 @@ def get_att(template: "Template", values: Any) -> str:
|
|
459
459
|
# Check if there is a value in the resource Metadata for this attribute.
|
460
460
|
# If the attribute requested is in the metadata, return it.
|
461
461
|
# Otherwise use the string value of "{resource_name}.{att_name}"
|
462
|
-
|
463
|
-
metadata = resource.get("Metadata", {})
|
464
|
-
cloud_radar_metadata = metadata.get("Cloud-Radar", {})
|
462
|
+
cloud_radar_metadata = _get_cloud_radar_metadata(resource)
|
465
463
|
attribute_values = cloud_radar_metadata.get("attribute-values", {})
|
466
464
|
|
467
465
|
return attribute_values.get(att_name, f"{resource_name}.{att_name}")
|
468
466
|
|
469
467
|
|
468
|
+
def _get_cloud_radar_metadata(resource) -> dict:
|
469
|
+
metadata = resource.get("Metadata", {})
|
470
|
+
return metadata.get("Cloud-Radar", {})
|
471
|
+
|
472
|
+
|
470
473
|
def get_azs(_t: "Template", region: Any) -> List[str]:
|
471
474
|
"""Solves AWS GetAZs intrinsic function.
|
472
475
|
|
@@ -857,7 +860,13 @@ def ref(template: "Template", var_name: str) -> Any:
|
|
857
860
|
return param_value
|
858
861
|
|
859
862
|
if var_name in template.template["Resources"]:
|
860
|
-
|
863
|
+
# Check if there is a value in the resource Metadata for this reference.
|
864
|
+
# If the ref requested is in the metadata, return it.
|
865
|
+
# Otherwise use the string value of the logical resource name
|
866
|
+
cloud_radar_metadata = _get_cloud_radar_metadata(
|
867
|
+
template.template["Resources"][var_name]
|
868
|
+
)
|
869
|
+
return cloud_radar_metadata.get("ref", var_name)
|
861
870
|
|
862
871
|
raise Exception(f"Fn::Ref - {var_name} is not a valid Resource or Parameter.")
|
863
872
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.3
|
2
2
|
Name: cloud-radar
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.15.0
|
4
4
|
Summary: Run functional tests on cloudformation stacks.
|
5
5
|
License: Apache-2.0
|
6
6
|
Keywords: aws,cloudformation,cloud-radar,testing,taskcat,cloud,radar
|
@@ -239,7 +239,7 @@ dynamic_references = {
|
|
239
239
|
template = Template(template_content, dynamic_references=dynamic_references)
|
240
240
|
```
|
241
241
|
|
242
|
-
There are cases where the default behaviour of our `GetAtt`
|
242
|
+
There are cases where the default behaviour of our `Ref` and `GetAtt` implementations may not be sufficient and you need a more accurate returned value. When unit testing there are no real AWS resources created, and cloud-radar does not attempt to realistically generate attribute values - a string is always returned. For `Ref` this is the logical resource name, for `GetAtt` this is `<logical resource name>.<attribute name>`. This works good enough most of the time, but there are some cases where if you are attempting to apply intrinsic functions against these value it needs to be more correct. When this occurs, you can add Metadata to the template to provide test values to use.
|
243
243
|
|
244
244
|
```
|
245
245
|
Resources:
|
@@ -247,6 +247,7 @@ Resources:
|
|
247
247
|
Type: AWS::MediaPackageV2::Channel
|
248
248
|
Metadata:
|
249
249
|
Cloud-Radar:
|
250
|
+
ref: arn:aws:mediapackagev2:region:AccountId:ChannelGroup/ChannelGroupName/Channel/ChannelName
|
250
251
|
attribute-values:
|
251
252
|
# Default behaviour of a string is not good enough here, the attribute value is expected to be a List.
|
252
253
|
IngestEndpointUrls:
|
@@ -256,6 +257,7 @@ Resources:
|
|
256
257
|
ChannelGroupName: dev_video_1
|
257
258
|
ChannelName: !Sub ${AWS::StackName}-MediaPackageChannel
|
258
259
|
```
|
260
|
+
If you are unable to modify the template itself, it is also possible to inject this metadata as part of the unit test. See [this test case](./tests/test_cf/test_unit/test_functions_ref.py) for an example.
|
259
261
|
|
260
262
|
A real unit testing example using Pytest can be seen [here](./tests/test_cf/test_examples/test_unit.py)
|
261
263
|
|
@@ -5,14 +5,14 @@ cloud_radar/cf/e2e/_stack.py,sha256=Qm5vQsUSUluHirTFTs_n40yI6Z8-HMZ837OvSJcyWqM,
|
|
5
5
|
cloud_radar/cf/unit/__init__.py,sha256=H9iQw4PSZEW-u0Ey-Z8eZfzQ6GJ7wdxmkKE8Z09U7pU,198
|
6
6
|
cloud_radar/cf/unit/_condition.py,sha256=e7gwcz87yF6dKl2quxmOmjzHku8OW6EWAsgbCeDMARg,711
|
7
7
|
cloud_radar/cf/unit/_hooks.py,sha256=BzFQ2pV6Wfk9KEETTM4DU6Ue0BO1D0HdMFjRM1xo1VM,6866
|
8
|
-
cloud_radar/cf/unit/_output.py,sha256=
|
8
|
+
cloud_radar/cf/unit/_output.py,sha256=U036lzszMN5awuKoybqOD6GCa7z8Ad4g-mbWLx8TFR0,1865
|
9
9
|
cloud_radar/cf/unit/_parameter.py,sha256=AdPIqc2ggSW1VR0USF30zjphX3z1HHbGKQt8n-Kzhfo,3199
|
10
10
|
cloud_radar/cf/unit/_resource.py,sha256=dWaR-5s6ea5mIu6Dhf1hY31Wd4WLHbHsbyxnu2Tz6QI,8512
|
11
11
|
cloud_radar/cf/unit/_stack.py,sha256=_S0L9O7Lw-QAJDKubClp2b6UYtYfyzg272_7WQkUdo8,5785
|
12
|
-
cloud_radar/cf/unit/_template.py,sha256=
|
13
|
-
cloud_radar/cf/unit/functions.py,sha256=
|
12
|
+
cloud_radar/cf/unit/_template.py,sha256=o7AnEyeuc0DUThR28W4GHO71uf1IWHKRj9FEYxMWeRU,32474
|
13
|
+
cloud_radar/cf/unit/functions.py,sha256=l6orvpQjEHzRm_OPtxeza3U5icbujIzPUmtCrduxKAU,26796
|
14
14
|
cloud_radar/cf/unit/test__template.py,sha256=nHc9WziIeGDo0d-rsn3HV4X7BsoKmwwHUxcp3qzuZo8,1414
|
15
|
-
cloud_radar-0.
|
16
|
-
cloud_radar-0.
|
17
|
-
cloud_radar-0.
|
18
|
-
cloud_radar-0.
|
15
|
+
cloud_radar-0.15.0.dist-info/LICENSE.txt,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
16
|
+
cloud_radar-0.15.0.dist-info/METADATA,sha256=dXDJ-abrwV24q0y8hnudwIGUCKfXgrXni9NE9tMEidY,17203
|
17
|
+
cloud_radar-0.15.0.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
|
18
|
+
cloud_radar-0.15.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|