def test_input_equals_output(resource_client, input_model, output_model): pruned_input_model = prune_properties_from_model( input_model.copy(), set( list(resource_client.read_only_paths) + list(resource_client.write_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( pruned_output_model, pruned_input_model, resource_client.create_only_paths) assertion_error_message = ( "All properties specified in the request MUST " "be present in the model returned, and they MUST" " match exactly, with the exception of properties" " defined as writeOnlyProperties in the resource schema") # only comparing properties in input model to those in output model and # ignoring extraneous properties that maybe present in output model. try: resource_client.transform_model(pruned_input_model, pruned_output_model) for key in pruned_input_model: if key in resource_client.properties_without_insertion_order: assert test_unordered_list_match(pruned_input_model[key], pruned_output_model[key]) else: assert resource_client.compare( pruned_input_model[key], pruned_output_model[key]), assertion_error_message except KeyError as e: raise AssertionError(assertion_error_message) from e
def test_input_equals_output(resource_client, input_model, output_model): input_model = prune_properties_from_model(input_model, resource_client.write_only_paths) output_model = prune_properties_from_model(output_model, resource_client.read_only_paths) output_model = prune_properties_if_not_exist_in_path( output_model, input_model, resource_client.create_only_paths) assert input_model == output_model
def contract_delete_create(resource_client, deleted_resource): if resource_client.has_writable_identifier(): deleted_model, request = deleted_resource response = test_create_success(resource_client, request) # read-only properties should be excluded from the comparison prune_properties_from_model(deleted_model, resource_client.read_only_paths) prune_properties_from_model( response["resourceModel"], resource_client.read_only_paths ) assert deleted_model == response["resourceModel"] else: pytest.skip("No writable identifiers. Skipping test.")
def updated_resource(resource_client): create_request = input_model = model = resource_client.generate_create_example( ) try: _status, response, _error = resource_client.call_and_assert( Action.CREATE, OperationStatus.SUCCESS, create_request) created_model = model = response["resourceModel"] test_input_equals_output(resource_client, input_model, created_model) 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) # flake8: noqa: B950 # pylint: disable=C0301 yield create_request, created_model, update_request, updated_model, updated_input_model finally: resource_client.call_and_assert(Action.DELETE, OperationStatus.SUCCESS, model)
def test_prune_properties_from_model(): document = { "foo": "bar", "spam": "eggs", "one": "two", "array": ["first", "second"], } prune_properties_from_model( document, [ ("properties", "foo"), ("properties", "spam"), ("properties", "not_found"), ("properties", "array", "1"), ], ) assert document == {"one": "two", "array": ["first"]}
def contract_delete_create(resource_client, deleted_resource): if resource_client.has_writable_identifier(): deleted_model, request = deleted_resource response = test_create_success(resource_client, request) created_response = response.copy() # read-only properties should be excluded from the comparison prune_properties_from_model(deleted_model, resource_client.read_only_paths) prune_properties_from_model( response["resourceModel"], resource_client.read_only_paths ) assert deleted_model == response["resourceModel"] resource_client.call_and_assert( Action.DELETE, OperationStatus.SUCCESS, created_response["resourceModel"] ) else: pytest.skip("No writable identifiers. Skipping test.")
def test_input_equals_output(resource_client, input_model, output_model): pruned_input_model = prune_properties_from_model( copy.deepcopy(input_model), set( list(resource_client.read_only_paths) + list(resource_client.write_only_paths)), ) pruned_output_model = prune_properties_from_model( copy.deepcopy(output_model), resource_client.read_only_paths) pruned_output_model = prune_properties_if_not_exist_in_path( pruned_output_model, pruned_input_model, resource_client.create_only_paths) resource_client.compare( pruned_input_model, pruned_output_model, )
def contract_delete_create(resource_client, deleted_resource): if resource_client.has_writable_identifier(): deleted_model, request = deleted_resource response = test_create_success(resource_client, request) created_response = response.copy() # read-only properties should be excluded from the comparison prune_properties_from_model(deleted_model, resource_client.read_only_paths) prune_properties_from_model( response["resourceModel"], resource_client.read_only_paths ) assert ( deleted_model == response["resourceModel"] ), "Once a delete operation successfully completes, a subsequent\ create request with the same primaryIdentifier or additionalIdentifiers\ MUST NOT return FAILED with an AlreadyExists error code" resource_client.call_and_assert( Action.DELETE, OperationStatus.SUCCESS, created_response["resourceModel"] ) else: pytest.skip("No writable identifiers. Skipping test.")