Exemplo n.º 1
0
 class LinksSchema(Schema):
     self = fields.Link(
         template=URITemplate("/records{?params*}"),
         params=lambda o: {
             "params": {
                 # type is expected to show in the query string as type=A&type=B
                 "type": ["A", "B"],
                 "sort": "newest",
                 "subtype": ["1"],
                 "size": 10,
             }
         })
     publish = fields.Link(
         template=URITemplate("/admin{/pid}"),
         params=lambda o: {"pid": o.get("pid")},
         permission="admin",
     )
     prev = fields.Link(template=URITemplate("/prev"),
                        params=lambda o: {},
                        when=lambda o: o.get("allowed", True))
Exemplo n.º 2
0
 class ItemLinkSchema2(Schema):
     self = fields.Link(template=URITemplate("/2/{?pid}"),
                        params=lambda o: {'pid': o.get("pid")},
                        permission="create")
Exemplo n.º 3
0
def test_link_field_initialization():
    """Test that you can pass both URI templates and strings."""
    tpls = ["/records{?params*}", URITemplate("/records{?params*})")]
    for t in tpls:
        assert isinstance(fields.Link(template=t).template, URITemplate)