|
1 | 1 | import datetime as dt
|
2 | 2 | import uuid
|
| 3 | +from unittest import mock |
3 | 4 |
|
4 | 5 | import pystac
|
5 | 6 | import pytest
|
@@ -143,3 +144,49 @@ def test_should_set_up42_extension(self, entity, entity_dict, attribute, key):
|
143 | 144 | new_value = "new-value"
|
144 | 145 | setattr(entity.up42, attribute, new_value) # type: ignore
|
145 | 146 | assert entity_dict[key] == new_value
|
| 147 | + |
| 148 | + |
| 149 | +class TestBulkDeletion: |
| 150 | + items = [ |
| 151 | + pystac.Item( |
| 152 | + id=f"item-id-{i}", |
| 153 | + collection="collection-id", |
| 154 | + geometry=None, |
| 155 | + bbox=None, |
| 156 | + datetime=dt.datetime.now(), |
| 157 | + properties={}, |
| 158 | + ) |
| 159 | + for i in range(2) |
| 160 | + ] |
| 161 | + collection_with_all_items = pystac.Collection( |
| 162 | + id="collection-id", |
| 163 | + description="", |
| 164 | + extent=pystac.Extent( |
| 165 | + spatial=pystac.SpatialExtent(bboxes=[[1.0, 2.0, 3.0, 4.0]]), |
| 166 | + temporal=pystac.TemporalExtent(intervals=[[dt.datetime.now(), None]]), |
| 167 | + ), |
| 168 | + extra_fields={}, |
| 169 | + ) |
| 170 | + collection_with_all_items.add_items(items) |
| 171 | + |
| 172 | + def test_should_raise_and_not_submit_when_missing_items(self): |
| 173 | + mock_stac_client = mock.Mock() |
| 174 | + mock_stac_client.get_items.return_value = iter([self.items[0]]) |
| 175 | + bulk_deletion = stac.BulkDeletion(self.items[0].id) |
| 176 | + bulk_deletion.stac_client = mock_stac_client |
| 177 | + with pytest.raises(stac.IncompleteCollectionDeletionError): |
| 178 | + bulk_deletion.delete() |
| 179 | + |
| 180 | + def test_should_delete_staged_items(self, requests_mock: req_mock.Mocker): |
| 181 | + requests_mock.delete( |
| 182 | + url=f"/v2/assets/stac/collections/{self.collection_with_all_items.id}", |
| 183 | + status_code=204, |
| 184 | + ) |
| 185 | + mock_stac_client = mock.Mock() |
| 186 | + mock_stac_client.get_items.return_value = iter(self.items) |
| 187 | + |
| 188 | + bulk_deletion = stac.BulkDeletion(self.items[0].id, self.items[1].id) |
| 189 | + bulk_deletion.stac_client = mock_stac_client |
| 190 | + |
| 191 | + bulk_deletion.delete() |
| 192 | + assert requests_mock.request_history[0].method == "DELETE" |
0 commit comments