def test_missing_ids(endpoint): example_response = get_example_response(f"{endpoint}.json") del example_response["result"]["id"] with pytest.raises(jsonschema.ValidationError): validate_against_schema(example_response, endpoint)
def test_search_dataset_pii_extra(): example_response = get_example_response("search_dataset.all_fields.json") example_response["results"][1]["extras"]["author"] = "Rieux" with pytest.raises(jsonschema.ValidationError): validate_against_schema(example_response, "search_dataset")
def test_organization_show_is_organization(): example_response = get_example_response("organization_show.json") example_response["result"]["is_organization"] = False with pytest.raises(jsonschema.ValidationError): validate_against_schema(example_response, "organization_show")
def test_format_autocomplete_result_missing_format(): example_response = get_example_response("format_autocomplete.json") del example_response["ResultSet"]["Result"][1]["Format"] with pytest.raises(jsonschema.ValidationError): validate_against_schema(example_response, "format_autocomplete")
def test_package_search_pii_field(): example_response = get_example_response("package_search.json") example_response["result"]["results"][1]["author"] = "Rieux" with pytest.raises(jsonschema.ValidationError): validate_against_schema(example_response, "package_search")
def test_package_search_empty_tag(): example_response = get_example_response("package_search.json") example_response["result"]["results"][2]["tags"].append({}) with pytest.raises(jsonschema.ValidationError): validate_against_schema(example_response, "package_search")
def test_unknown_state(endpoint): example_response = get_example_response(f"{endpoint}.json") example_response["result"]["state"] = "lockdown" with pytest.raises(jsonschema.ValidationError): validate_against_schema(example_response, endpoint)
def stable_org(inc_fixed_data): return _strip_unstable_data( clean_unstable_elements( get_example_response( "stable/organization_show.inner.test.json" ) ) )
def test_package_search_noninteger_facet(): example_response = get_example_response("package_search.json") example_response["result"]["facets"]["organization"][ "natural-england"] = "2" with pytest.raises(jsonschema.ValidationError): validate_against_schema(example_response, "package_search")
def test_package_show_org_must_follow_org_schema(): example_response = get_example_response("package_show.json") # note non-existent leap-day example_response["result"]["organization"][ "created"] = "2019-02-29T16:00:00.123Z" with pytest.raises(jsonschema.ValidationError): validate_against_schema(example_response, "package_show")
def test_package_search_pii_extra(): example_response = get_example_response("package_search.json") example_response["result"]["results"][1]["extras"].append({ "key": "author", "value": "Rieux" }) with pytest.raises(jsonschema.ValidationError): validate_against_schema(example_response, "package_search")
def stable_pkg_default_schema(variables, inc_fixed_data): json_data = get_example_response( "stable/package_show.default_schema.inner.test.json" ) return set_ckan_vars(json_data)
def stable_pkg_search(variables, inc_fixed_data): return set_ckan_vars( clean_unstable_elements( get_example_response("stable/package_search.inner.test.json") ) )
def test_responses_pass_respective_schemas(response_filename, schema_name): validate_against_schema(get_example_response(response_filename), schema_name)
def stable_org_with_datasets(variables, inc_fixed_data): return set_ckan_vars(get_example_response( "stable/organization_show_with_datasets.inner.test.json" ))
def stable_dataset(variables, inc_fixed_data): return set_ckan_vars( get_example_response( "stable/search_dataset{}.inner.test.json".format('-2.9' if variables['ckan_version'] == '2.9' else '') ) )
def test_package_list_must_be_slugs(nonslug_value): example_response = get_example_response("package_list.json") example_response["result"][2] = nonslug_value with pytest.raises(jsonschema.ValidationError): validate_against_schema(example_response, "package_list")