Skip to content

Commit defd7ef

Browse files
committed
Add tests for version extension that test full_copy.
This commit adds two tests, one for each of the Item and Collection extensions of the Version extension. The test checks that when items or collections are linked by the version links (predecessor, successor, or latest_version), that a full copy will end up with a catalog that has those links point to the correct object instances. If this test were to fail, that would indicate that the STAC object linked to by the version links was a separate copy of item or collection, which is incorrect.
1 parent c34eeb1 commit defd7ef

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

tests/extensions/test_version.py

+67
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import pystac
77
from pystac.extensions import version
8+
from tests.utils import TestCases
89

910
URL_TEMPLATE = 'http://example.com/catalog/%s.json'
1011

@@ -104,6 +105,39 @@ def test_all_links(self):
104105
self.item.ext.version.apply(self.version, deprecated, latest, predecessor, successor)
105106
self.item.validate()
106107

108+
def test_full_copy(self):
109+
cat = TestCases.test_case_1()
110+
111+
# Fetch two items from the catalog
112+
item1 = cat.get_item('area-1-1-imagery', recursive=True)
113+
item2 = cat.get_item('area-2-2-imagery', recursive=True)
114+
115+
# Enable the version extension on each, and link them
116+
# as if they are different versions of the same Item
117+
item1.ext.enable(pystac.Extensions.VERSION)
118+
item2.ext.enable(pystac.Extensions.VERSION)
119+
120+
item1.ext.version.apply(version='2.0', predecessor=item2)
121+
item2.ext.version.apply(version='1.0', successor=item1, latest=item1)
122+
123+
# Make a full copy of the catalog
124+
cat_copy = cat.full_copy()
125+
126+
# Retrieve the copied version of the items
127+
item1_copy = cat_copy.get_item('area-1-1-imagery', recursive=True)
128+
item2_copy = cat_copy.get_item('area-2-2-imagery', recursive=True)
129+
130+
# Check to see if the version links point to the instances of the
131+
# item objects as they should.
132+
133+
predecessor = item1_copy.get_single_link(version.PREDECESSOR_VERSION).target
134+
successor = item2_copy.get_single_link(version.SUCCESSOR_VERSION).target
135+
latest = item2_copy.get_single_link(version.LATEST_VERSION).target
136+
137+
self.assertIs(predecessor, item2_copy)
138+
self.assertIs(successor, item1_copy)
139+
self.assertIs(latest, item1_copy)
140+
107141

108142
def make_collection(year):
109143
asset_id = 'my/collection/of/things'
@@ -202,6 +236,39 @@ def test_validate_all(self):
202236
self.collection.ext.version.apply(self.version, deprecated, latest, predecessor, successor)
203237
self.collection.validate()
204238

239+
def test_full_copy(self):
240+
cat = TestCases.test_case_1()
241+
242+
# Fetch two collections from the catalog
243+
col1 = cat.get_child('area-1-1', recursive=True)
244+
col2 = cat.get_child('area-2-2', recursive=True)
245+
246+
# Enable the version extension on each, and link them
247+
# as if they are different versions of the same Collection
248+
col1.ext.enable(pystac.Extensions.VERSION)
249+
col2.ext.enable(pystac.Extensions.VERSION)
250+
251+
col1.ext.version.apply(version='2.0', predecessor=col2)
252+
col2.ext.version.apply(version='1.0', successor=col1, latest=col1)
253+
254+
# Make a full copy of the catalog
255+
cat_copy = cat.full_copy()
256+
257+
# Retrieve the copied version of the items
258+
col1_copy = cat_copy.get_child('area-1-1', recursive=True)
259+
col2_copy = cat_copy.get_child('area-2-2', recursive=True)
260+
261+
# Check to see if the version links point to the instances of the
262+
# col objects as they should.
263+
264+
predecessor = col1_copy.get_single_link(version.PREDECESSOR_VERSION).target
265+
successor = col2_copy.get_single_link(version.SUCCESSOR_VERSION).target
266+
latest = col2_copy.get_single_link(version.LATEST_VERSION).target
267+
268+
self.assertIs(predecessor, col2_copy)
269+
self.assertIs(successor, col1_copy)
270+
self.assertIs(latest, col1_copy)
271+
205272

206273
if __name__ == '__main__':
207274
unittest.main()

0 commit comments

Comments
 (0)