|
3 | 3 |
|
4 | 4 | from pystac import (STAC_IO, STACObject, Collection, CatalogType, LinkType)
|
5 | 5 | from pystac.serialization import (STACObjectType)
|
6 |
| -from pystac.utils import make_absolute_href |
| 6 | +from pystac.utils import is_absolute_href, make_absolute_href, make_relative_href |
7 | 7 | from pystac.validation import validate_dict
|
8 | 8 |
|
9 | 9 | from tests.utils import TestCases
|
@@ -31,13 +31,28 @@ def validate_file(self, path, object_type):
|
31 | 31 | return validate_dict(d, object_type)
|
32 | 32 |
|
33 | 33 | def validate_link_types(self, root_href, catalog_type):
|
| 34 | + def validate_asset_href_type(item, item_href, link_type): |
| 35 | + for asset in item.assets.values(): |
| 36 | + if link_type == LinkType.ABSOLUTE: |
| 37 | + self.assertTrue(is_absolute_href(asset.href)) |
| 38 | + else: |
| 39 | + is_valid = not is_absolute_href(asset.href) |
| 40 | + if not is_valid: |
| 41 | + # If the item href and asset href don't share |
| 42 | + # the same root, the asset href must be absolute |
| 43 | + rel_href = make_relative_href(asset.href, item_href) |
| 44 | + self.assertEqual(asset.href, rel_href) |
| 45 | + else: |
| 46 | + self.assertTrue(is_valid) |
34 | 47 | def validate_item_link_type(href, link_type, should_include_self):
|
35 | 48 | item_dict = STAC_IO.read_json(href)
|
36 | 49 | item = STACObject.from_file(href)
|
37 | 50 | for link in item.get_links():
|
38 | 51 | if not link.rel == 'self':
|
39 | 52 | self.assertEqual(link.link_type, link_type)
|
40 | 53 |
|
| 54 | + validate_asset_href_type(item, href, link_type) |
| 55 | + |
41 | 56 | rels = set([link['rel'] for link in item_dict['links']])
|
42 | 57 | self.assertEqual('self' in rels, should_include_self)
|
43 | 58 |
|
|
0 commit comments