コード例 #1
0
def test_prune_properties():
    document = {
        "foo": "bar",
        "spam": "eggs",
        "one": "two",
        "array": ["first", "second"],
    }
    prune_properties(document, [("foo",), ("spam",), ("not_found",), ("array", "1")])
    assert document == {"one": "two", "array": ["first"]}
コード例 #2
0
def contract_delete_create(resource_client, deleted_resource):
    deleted_model, request = deleted_resource
    response = test_create_success(resource_client, request)

    # read-only properties should be excluded from the comparison
    prune_properties(deleted_model, resource_client.read_only_paths)
    prune_properties(response["resourceModel"],
                     resource_client.read_only_paths)

    assert deleted_model == response["resourceModel"]
コード例 #3
0
    def _generate_target_example(self, target):
        LOG.debug("Generating example for target '%s'", target)
        if not self._target_info or not self._target_info.get(target):
            return {}

        info = self._target_info.get(target)
        if not info.get("SchemaStrategy"):
            # imported here to avoid hypothesis being loaded before pytest is loaded
            from .resource_generator import ResourceGenerator

            # make a copy so the original schema is never modified
            target_schema = json.loads(json.dumps(info["Schema"]))

            prune_properties(target_schema, info["readOnlyProperties"])

            info["SchemaStrategy"] = ResourceGenerator(
                target_schema).generate_schema_strategy(target_schema)

        return info.get("SchemaStrategy").example()