Skip to content

Commit 52a09f6

Browse files
committed
update tests to remove checks on link_type, replace with new method of setting catalog_type on root
1 parent 7a1a9cb commit 52a09f6

File tree

8 files changed

+27
-132
lines changed

8 files changed

+27
-132
lines changed

tests/data-files/collections/multi-extent.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@
1212
"href": "./area-1-1-labels/area-1-1-labels.json",
1313
"type": "application/json"
1414
},
15-
{
16-
"rel": "root",
17-
"href": "../../catalog.json",
18-
"type": "application/json"
19-
},
2015
{
2116
"rel": "parent",
2217
"href": "../catalog.json",

tests/data-files/eo/eo-landsat-example.json

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -227,18 +227,5 @@
227227
"title": "HTML index page"
228228
}
229229
},
230-
"links": [
231-
{
232-
"rel": "self",
233-
"href": "https://odu9mlf7d6.execute-api.us-east-1.amazonaws.com/stage/search?id=LC08_L1TP_107018_20181001_20181001_01_RT"
234-
},
235-
{
236-
"rel": "parent",
237-
"href": "https://odu9mlf7d6.execute-api.us-east-1.amazonaws.com/stage/stac/collections/landsat-8-l1"
238-
},
239-
{
240-
"rel": "root",
241-
"href": "https://odu9mlf7d6.execute-api.us-east-1.amazonaws.com/stage/stac"
242-
}
243-
]
230+
"links": []
244231
}

tests/data-files/eo/sample-bands-in-item-properties.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@
6666
"collection": "CS3",
6767
"links": [
6868
{"rel": "self", "href": "http://cool-sat.com/catalog/CS3-20160503_132130_04/CS3-20160503_132130_04.json"},
69-
{"rel": "root", "href": "http://cool-sat.com/catalog/catalog.json"},
7069
{"rel": "parent", "href": "http://cool-sat.com/catalog/CS3-20160503_132130_04/catalog.json"},
7170
{"rel": "collection", "href": "http://cool-sat.com/catalog/CS3-20160503_132130_04/catalog.json"},
7271
{"rel": "alternate", "type": "text/html", "href": "http://cool-sat.com/catalog/CS3-20160503_132130_04/CS3-20160503_132130_04.html"}

tests/data-files/label/label-example-1.json

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -95,17 +95,7 @@
9595
"links": [
9696
{
9797
"rel": "source",
98-
"href": "../area-1-1-imagery/area-1-1-imagery.json",
99-
"type": "application/json"
100-
},
101-
{
102-
"rel": "root",
103-
"href": "../../../catalog.json",
104-
"type": "application/json"
105-
},
106-
{
107-
"rel": "parent",
108-
"href": "../collection.json",
98+
"href": "http://example.com/area-1-1-imagery/area-1-1-imagery.json",
10999
"type": "application/json"
110100
}
111101
],

tests/data-files/label/label-example-2.json

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -88,17 +88,7 @@
8888
"links": [
8989
{
9090
"rel": "source",
91-
"href": "../area-1-1-imagery/area-1-1-imagery.json",
92-
"type": "application/json"
93-
},
94-
{
95-
"rel": "root",
96-
"href": "../../../catalog.json",
97-
"type": "application/json"
98-
},
99-
{
100-
"rel": "parent",
101-
"href": "../collection.json",
91+
"href": "http://example.com/area-1-1-imagery/area-1-1-imagery.json",
10292
"type": "application/json"
10393
}
10494
],

tests/test_catalog.py

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from collections import defaultdict
77

88
import pystac
9-
from pystac import (Catalog, Collection, CatalogType, Item, Asset, MediaType, Extensions)
9+
from pystac import (Catalog, Collection, CatalogType, Item, Asset, MediaType, Extensions, HIERARCHICAL_LINKS)
1010
from pystac.extensions.label import LabelClasses
1111
from pystac.validation import STACValidationError
1212
from pystac.utils import is_absolute_href
@@ -262,14 +262,6 @@ def test_clone_uses_previous_catalog_type(self):
262262
clone = catalog.clone()
263263
self.assertEqual(clone.catalog_type, CatalogType.SELF_CONTAINED)
264264

265-
def test_save_throws_if_no_catalog_type(self):
266-
catalog = TestCases.test_case_3()
267-
assert catalog.catalog_type is None
268-
with TemporaryDirectory() as tmp_dir:
269-
catalog.normalize_hrefs(tmp_dir)
270-
with self.assertRaises(ValueError):
271-
catalog.save()
272-
273265
def test_normalize_hrefs_sets_all_hrefs(self):
274266
catalog = TestCases.test_case_1()
275267
catalog.normalize_hrefs('http://example.com')
@@ -659,23 +651,21 @@ def test_make_all_links_relative_or_absolute(self):
659651
def check_all_relative(cat):
660652
for root, catalogs, items in cat.walk():
661653
for link in root.links:
662-
if link.rel != 'self':
663-
self.assertTrue(link.link_type == LinkType.RELATIVE)
654+
if link.rel in HIERARCHICAL_LINKS:
664655
self.assertFalse(is_absolute_href(link.get_href()))
665656
for item in items:
666657
for link in item.links:
667-
if link.rel != 'self':
668-
self.assertTrue(link.link_type == LinkType.RELATIVE)
658+
if link.rel in HIERARCHICAL_LINKS:
659+
if is_absolute_href(link.get_href()):
660+
import pdb; pdb.set_trace()
669661
self.assertFalse(is_absolute_href(link.get_href()))
670662

671663
def check_all_absolute(cat):
672664
for root, catalogs, items in cat.walk():
673665
for link in root.links:
674-
self.assertTrue(link.link_type == LinkType.ABSOLUTE)
675666
self.assertTrue(is_absolute_href(link.get_href()))
676667
for item in items:
677668
for link in item.links:
678-
self.assertTrue(link.link_type == LinkType.ABSOLUTE)
679669
self.assertTrue(is_absolute_href(link.get_href()))
680670

681671
test_cases = TestCases.all_test_catalogs()
@@ -684,9 +674,9 @@ def check_all_absolute(cat):
684674
with TemporaryDirectory() as tmp_dir:
685675
c2 = catalog.full_copy()
686676
c2.normalize_hrefs(tmp_dir)
687-
c2.make_all_links_relative()
677+
c2.catalog_type = CatalogType.RELATIVE_PUBLISHED
688678
check_all_relative(c2)
689-
c2.make_all_links_absolute()
679+
c2.catalog_type = CatalogType.ABSOLUTE_PUBLISHED
690680
check_all_absolute(c2)
691681

692682
def test_full_copy_and_normalize_works_with_created_stac(self):

tests/test_link.py

Lines changed: 1 addition & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,6 @@ def test_minimal(self):
4949
link.set_owner(None)
5050
self.assertIsNone(link.owner)
5151

52-
self.assertEqual(pystac.LinkType.ABSOLUTE, link.link_type)
53-
54-
link.make_absolute()
55-
self.assertEqual(pystac.LinkType.ABSOLUTE, link.link_type)
56-
self.assertEqual(target, link.get_href())
57-
self.assertEqual(target, link.get_absolute_href())
58-
59-
link.make_relative()
60-
self.assertEqual(pystac.LinkType.RELATIVE, link.link_type)
61-
self.assertEqual(target, link.get_href())
62-
self.assertEqual(target, link.get_absolute_href())
63-
6452
link.set_owner(self.item)
6553
self.assertEqual(self.item, link.owner)
6654

@@ -72,8 +60,7 @@ def test_relative(self):
7260
target,
7361
mime_type,
7462
'a title',
75-
properties={'a': 'b'},
76-
link_type=pystac.LinkType.RELATIVE)
63+
properties={'a': 'b'})
7764
expected_dict = {
7865
'rel': rel,
7966
'href': target,
@@ -83,14 +70,11 @@ def test_relative(self):
8370
}
8471
self.assertEqual(expected_dict, link.to_dict())
8572

86-
self.assertEqual(pystac.LinkType.RELATIVE, link.link_type)
87-
8873
def test_link_does_not_fail_if_href_is_none(self):
8974
"""Test to ensure get_href does not fail when the href is None."""
9075
catalog = pystac.Catalog(id='test', description='test desc')
9176
catalog.add_item(self.item)
9277
catalog.set_self_href('/some/href')
93-
catalog.make_all_links_relative()
9478

9579
link = catalog.get_single_link('item')
9680
self.assertIsNone(link.get_href())
@@ -133,52 +117,11 @@ def test_from_dict_round_trip(self):
133117
d2 = pystac.Link.from_dict(d).to_dict()
134118
self.assertEqual(d, d2)
135119

136-
def test_from_dict_link_type(self):
137-
test_cases = [
138-
({
139-
'rel': '',
140-
'href': 'https://a'
141-
}, pystac.LinkType.ABSOLUTE),
142-
({
143-
'rel': '',
144-
'href': '/a'
145-
}, pystac.LinkType.ABSOLUTE),
146-
({
147-
'rel': '',
148-
'href': 'a'
149-
}, pystac.LinkType.RELATIVE),
150-
({
151-
'rel': '',
152-
'href': './a'
153-
}, pystac.LinkType.RELATIVE),
154-
# 'self' is a special case.
155-
({
156-
'rel': 'self',
157-
'href': 'does not matter'
158-
}, pystac.LinkType.ABSOLUTE),
159-
]
160-
for case in test_cases:
161-
item = pystac.Link.from_dict(case[0])
162-
self.assertEqual(case[1], item.link_type)
163-
164120
def test_from_dict_failures(self):
165121
for d in [{}, {'href': 't'}, {'rel': 'r'}]:
166122
with self.assertRaises(KeyError):
167123
pystac.Link.from_dict(d)
168124

169-
for d in [
170-
{
171-
'rel': '',
172-
'href': 1
173-
},
174-
{
175-
'rel': '',
176-
'href': None
177-
},
178-
]:
179-
with self.assertRaises(AttributeError):
180-
pystac.Link.from_dict(d)
181-
182125
def test_collection(self):
183126
c = pystac.Collection('collection id', 'desc', extent=None)
184127
link = pystac.Link.collection(c)

tests/test_writing.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import unittest
22
from tempfile import TemporaryDirectory
33

4-
from pystac import (STAC_IO, STACObject, Collection, CatalogType)
4+
from pystac import (STAC_IO, STACObject, Collection, CatalogType, HIERARCHICAL_LINKS)
55
from pystac.serialization import (STACObjectType)
66
from pystac.utils import is_absolute_href, make_absolute_href, make_relative_href
77
from pystac.validation import validate_dict
@@ -30,12 +30,11 @@ def validate_file(self, path, object_type):
3030
d = STAC_IO.read_json(path)
3131
return validate_dict(d, object_type)
3232

33-
def validate_link_types(self, root_href, catalog_type):
33+
def validate_link_types(self, root_href, catalog_type):
34+
3435
def validate_asset_href_type(item, item_href, link_type):
3536
for asset in item.assets.values():
36-
if link_type == LinkType.ABSOLUTE:
37-
self.assertTrue(is_absolute_href(asset.href))
38-
else:
37+
if not is_absolute_href(asset.href):
3938
is_valid = not is_absolute_href(asset.href)
4039
if not is_valid:
4140
# If the item href and asset href don't share
@@ -50,7 +49,10 @@ def validate_item_link_type(href, link_type, should_include_self):
5049
item = STACObject.from_file(href)
5150
for link in item.get_links():
5251
if not link.rel == 'self':
53-
self.assertEqual(link.link_type, link_type)
52+
if link_type == 'RELATIVE' and link.rel in HIERARCHICAL_LINKS:
53+
self.assertFalse(is_absolute_href(link.get_href()))
54+
else:
55+
self.assertTrue(is_absolute_href(link.get_href()))
5456

5557
validate_asset_href_type(item, href, link_type)
5658

@@ -60,9 +62,6 @@ def validate_item_link_type(href, link_type, should_include_self):
6062
def validate_catalog_link_type(href, link_type, should_include_self):
6163
cat_dict = STAC_IO.read_json(href)
6264
cat = STACObject.from_file(href)
63-
for link in cat.get_links():
64-
if not link.rel == 'self':
65-
self.assertEqual(link.link_type, link_type)
6665

6766
rels = set([link['rel'] for link in cat_dict['links']])
6867
self.assertEqual('self' in rels, should_include_self)
@@ -77,9 +76,9 @@ def validate_catalog_link_type(href, link_type, should_include_self):
7776
validate_item_link_type(item_href, link_type,
7877
catalog_type == CatalogType.ABSOLUTE_PUBLISHED)
7978

80-
link_type = LinkType.RELATIVE
79+
link_type = 'RELATIVE'
8180
if catalog_type == CatalogType.ABSOLUTE_PUBLISHED:
82-
link_type = LinkType.ABSOLUTE
81+
link_type = 'ABSOLUTE'
8382

8483
root_should_include_href = catalog_type in [
8584
CatalogType.ABSOLUTE_PUBLISHED, CatalogType.RELATIVE_PUBLISHED
@@ -110,9 +109,11 @@ def do_test(self, catalog, catalog_type):
110109
def test_testcases(self):
111110
for catalog in TestCases.all_test_catalogs():
112111
catalog = catalog.full_copy()
113-
for catalog_type in [
114-
CatalogType.ABSOLUTE_PUBLISHED, CatalogType.RELATIVE_PUBLISHED,
115-
CatalogType.SELF_CONTAINED
116-
]:
112+
ctypes = [
113+
CatalogType.ABSOLUTE_PUBLISHED,
114+
CatalogType.RELATIVE_PUBLISHED,
115+
CatalogType.SELF_CONTAINED
116+
]
117+
for catalog_type in ctypes:
117118
with self.subTest(title='Catalog {} [{}]'.format(catalog.id, catalog_type)):
118119
self.do_test(catalog, catalog_type)

0 commit comments

Comments
 (0)