Skip to content

Commit ca5df48

Browse files
authored
Fix for contract test drift parity issue #1 (#589)
* fix to compare output model with input model * encapsulating repeated error message in a variable
1 parent dccf779 commit ca5df48

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/rpdk/core/contract/resource_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ def prune_properties(document, paths):
4242

4343

4444
def prune_properties_if_not_exist_in_path(output_model, input_model, paths):
45-
"""Prune given properties from a document.
45+
"""Prune given properties from a model.
4646
4747
This assumes properties will always have an object (dict) as a parent.
48-
The function returns the document after pruning the path which exists
48+
The function returns the model after pruning the path which exists
4949
in the paths tuple but not in the input_model
5050
"""
5151
output_document = {"properties": output_model.copy()}

src/rpdk/core/contract/suite/handler_commons.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,23 @@ def test_input_equals_output(resource_client, input_model, output_model):
154154
pruned_output_model = prune_properties_if_not_exist_in_path(
155155
output_model.copy(), pruned_input_model, resource_client.read_only_paths
156156
)
157+
157158
pruned_output_model = prune_properties_if_not_exist_in_path(
158159
pruned_output_model, pruned_input_model, resource_client.create_only_paths
159160
)
160161

161-
assert pruned_input_model == pruned_output_model
162+
assertion_error_message = (
163+
"All properties specified in the request MUST "
164+
"be present in the model returned, and they MUST"
165+
" match exactly, with the exception of properties"
166+
" defined as writeOnlyProperties in the resource schema"
167+
)
168+
# only comparing properties in input model to those in output model and
169+
# ignoring extraneous properties that maybe present in output model.
170+
try:
171+
assert all(
172+
pruned_input_model[key] == pruned_output_model[key]
173+
for key in pruned_input_model
174+
), assertion_error_message
175+
except KeyError as e:
176+
raise AssertionError(assertion_error_message) from e

0 commit comments

Comments
 (0)