Example #1
0
def get_entry_info(request: Request, entry: str):
    from optimade.models import EntryInfoResource

    valid_entry_info_endpoints = ENTRY_INFO_SCHEMAS.keys()
    if entry not in valid_entry_info_endpoints:
        raise StarletteHTTPException(
            status_code=404,
            detail=f"Entry info not found for {entry}, valid entry info endpoints are: {', '.join(valid_entry_info_endpoints)}",
        )

    schema = ENTRY_INFO_SCHEMAS[entry]()
    queryable_properties = {"id", "type", "attributes"}
    properties = retrieve_queryable_properties(schema, queryable_properties)

    output_fields_by_format = {"json": list(properties.keys())}

    return EntryInfoResponse(
        meta=meta_values(str(request.url), 1, 1, more_data_available=False),
        data=EntryInfoResource(
            formats=list(output_fields_by_format.keys()),
            description=schema.get("description", "Entry Resources"),
            properties=properties,
            output_fields_by_format=output_fields_by_format,
        ),
    )
Example #2
0
 def test_info_structures_endpoint_data(self):
     """Check known properties/attributes for successful response"""
     assert "data" in self.json_response
     data = EntryInfoResource.schema()["required"]
     self.check_keys(data, self.json_response["data"])
Example #3
0
 def test_info_structures_endpoint_data(self):
     assert "data" in self.json_response
     data = EntryInfoResource.schema().get("required")
     self.check_keys(data, self.json_response["data"])