Skip to content

Commit

Permalink
Prune read only properties from input & output (#681)
Browse files Browse the repository at this point in the history
* Prune read only properties from input & output
  • Loading branch information
anshikg authored Feb 11, 2021
1 parent e874a82 commit bd9840b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
7 changes: 4 additions & 3 deletions src/rpdk/core/contract/suite/handler_commons.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,12 @@ def test_delete_failure_not_found(resource_client, current_resource_model):

def test_input_equals_output(resource_client, input_model, output_model):
pruned_input_model = prune_properties_from_model(
input_model.copy(), resource_client.write_only_paths
input_model.copy(),
list(resource_client.write_only_paths, resource_client.read_only_paths),
)

pruned_output_model = prune_properties_if_not_exist_in_path(
output_model.copy(), pruned_input_model, resource_client.read_only_paths
pruned_output_model = prune_properties_from_model(
output_model.copy(), resource_client.read_only_paths
)

pruned_output_model = prune_properties_if_not_exist_in_path(
Expand Down
9 changes: 2 additions & 7 deletions src/rpdk/core/contract/suite/handler_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
# WARNING: contract tests should use fully qualified imports to avoid issues
# when being loaded by pytest
from rpdk.core.contract.interface import Action, OperationStatus
from rpdk.core.contract.resource_client import prune_properties_from_model
from rpdk.core.contract.suite.handler_commons import (
test_input_equals_output,
test_model_in_list,
Expand All @@ -27,19 +26,15 @@ def updated_resource(resource_client):

update_request = resource_client.generate_update_example(created_model)

updated_input_model = prune_properties_from_model(
update_request.copy(), resource_client.read_only_paths
)

_status, response, _error = resource_client.call_and_assert(
Action.UPDATE, OperationStatus.SUCCESS, update_request, created_model
)
updated_model = response["resourceModel"]
test_input_equals_output(resource_client, updated_input_model, updated_model)
test_input_equals_output(resource_client, update_request, updated_model)

# flake8: noqa: B950
# pylint: disable=C0301
yield create_request, created_model, update_request, updated_model, updated_input_model
yield create_request, created_model, update_request, updated_model, update_request
finally:
resource_client.call_and_assert(Action.DELETE, OperationStatus.SUCCESS, model)

Expand Down

0 comments on commit bd9840b

Please sign in to comment.