|
5 | 5 |
|
6 | 6 | import pystac
|
7 | 7 | from pystac.extensions import version
|
| 8 | +from tests.utils import TestCases |
8 | 9 |
|
9 | 10 | URL_TEMPLATE = 'http://example.com/catalog/%s.json'
|
10 | 11 |
|
@@ -104,6 +105,39 @@ def test_all_links(self):
|
104 | 105 | self.item.ext.version.apply(self.version, deprecated, latest, predecessor, successor)
|
105 | 106 | self.item.validate()
|
106 | 107 |
|
| 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 | + |
107 | 141 |
|
108 | 142 | def make_collection(year):
|
109 | 143 | asset_id = 'my/collection/of/things'
|
@@ -202,6 +236,39 @@ def test_validate_all(self):
|
202 | 236 | self.collection.ext.version.apply(self.version, deprecated, latest, predecessor, successor)
|
203 | 237 | self.collection.validate()
|
204 | 238 |
|
| 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 | + |
205 | 272 |
|
206 | 273 | if __name__ == '__main__':
|
207 | 274 | unittest.main()
|
0 commit comments