Example #1
0
 def collection(self) -> Link:
     """Create the `collection` link."""
     return Link(
         rel=Relations.collection,
         type=MimeTypes.json,
         href=urljoin(self.base_url, f"/collections/{self.collection_id}"),
     )
def test_api_paging_extension():
    item_collection = request(ITEM_COLLECTION)
    item_collection["stac_version"] = STAC_VERSION
    for feat in item_collection["features"]:
        feat["stac_version"] = STAC_VERSION
    item_collection["links"] += [
        {
            "title": "next page",
            "rel": "next",
            "method": "GET",
            "href": "http://next"
        },
        {
            "title": "previous page",
            "rel": "previous",
            "method": "POST",
            "href": "http://prev",
            "body": {
                "key": "value"
            },
        },
    ]
    model = ItemCollection(**item_collection)
    links = model.to_dict()["links"]

    # Make sure we can mix links and pagination links
    normal_link = Link(**links[0])
    assert normal_link.rel == "self"
    next_link = PaginationLink(**links[1])
    assert next_link.rel == "next"
    previous_link = PaginationLink(**links[2])
    assert previous_link.rel == "previous"
    assert previous_link.body == {"key": "value"}
Example #3
0
 def item(self) -> Link:
     """Create the `item` link."""
     return Link(
         rel=Relations.item,
         type=MimeTypes.geojson,
         href=urljoin(self.base_url, f"/collections/{self.collection_id}/items"),
     )
def test_api_landing_page():
    LandingPage(
        id="test-landing-page",
        description="stac-api landing page",
        stac_extensions=["eo", "proj"],
        links=[Link(
            href="http://link",
            rel="self",
        )],
    )
def test_resolve_pagination_link():
    normal_link = Link(href="/hello/world", type="image/jpeg", rel="test")
    page_link = PaginationLink(href="/next/page",
                               type="image/jpeg",
                               method="POST",
                               rel="next")
    links = Links.parse_obj([normal_link, page_link])
    links.resolve(base_url="http://base_url.com")
    for link in links:
        if isinstance(link, PaginationLink):
            assert link.href == "http://base_url.com/next/page"
def test_api_landing_page_is_catalog():
    landing_page = LandingPage(
        id="test-landing-page",
        description="stac-api landing page",
        stac_extensions=["eo", "proj"],
        links=[Link(
            href="http://link",
            rel="self",
        )],
    )
    catalog = Catalog(**landing_page.dict())
 def another_link(self) -> Link:
     return Link(
         rel="another-link",
         type="application/json",
         href=urljoin(self.base_url, "/another-link"),
     )
def test_resolve_links():
    links = Links.parse_obj(
        [Link(href="/hello/world", type="image/jpeg", rel="test")])
    links.resolve(base_url="http://base_url.com")
    for link in links:
        assert link.href == "http://base_url.com/hello/world"
def test_resolve_link():
    link = Link(href="/hello/world", type="image/jpeg", rel="test")
    link.resolve(base_url="http://base_url.com")
    assert link.href == "http://base_url.com/hello/world"
Example #10
0
 def parent(self) -> Link:
     """Create the `parent` link."""
     return Link(
         rel=Relations.parent, type=MimeTypes.json, href=urljoin(self.base_url, "/")
     )
Example #11
0
 def root(self) -> Link:
     """Return the catalog root."""
     return Link(
         rel=Relations.root, type=MimeTypes.json, href=urljoin(self.base_url, "/")
     )