|
19 | 19 |
|
20 | 20 | import os |
21 | 21 |
|
| 22 | +from eodag import SearchResult |
| 23 | +from eodag.api.product import EOProduct |
| 24 | +from eodag.config import PluginConfig |
| 25 | +from eodag.plugins.download.http import HTTPDownload |
| 26 | + |
| 27 | +from stac_fastapi.eodag.config import get_settings |
| 28 | + |
22 | 29 |
|
23 | 30 | async def test_download_item_from_collection_stream( |
24 | 31 | request_valid_raw, defaults, mock_base_stream_download_dict, mock_base_authenticate, stream_response |
@@ -46,3 +53,48 @@ async def test_download_item_from_collection_no_stream( |
46 | 53 | mock_download.assert_called_once() |
47 | 54 | # downloaded file should have been immediatly deleted from the server |
48 | 55 | assert not os.path.exists(expected_file), f"File {expected_file} should have been deleted" |
| 56 | + |
| 57 | + |
| 58 | +async def test_download_auto_order_whitelist( |
| 59 | + request_valid_raw, |
| 60 | + mock_base_authenticate, |
| 61 | + mock_order, |
| 62 | + mock_search, |
| 63 | + defaults, |
| 64 | + mock_http_base_stream_download_dict, |
| 65 | + stream_response, |
| 66 | +): |
| 67 | + """Test that the order method is called when downloading a product |
| 68 | + from a federation backend included in the auto_order_whitelist. |
| 69 | +
|
| 70 | + This test simulates downloading a product from a federated backend ('peps') |
| 71 | + and checks that the order function is triggered when the backend is present |
| 72 | + in the auto_order_whitelist configuration. |
| 73 | + """ |
| 74 | + get_settings().auto_order_whitelist = ["peps"] |
| 75 | + federation_backend = "peps" |
| 76 | + collection_id = defaults.product_type |
| 77 | + |
| 78 | + url = f"data/peps/{defaults.product_type}/dummy_id/downloadLink" |
| 79 | + |
| 80 | + product = EOProduct( |
| 81 | + federation_backend, |
| 82 | + dict( |
| 83 | + geometry="POINT (0 0)", |
| 84 | + title="dummy_product", |
| 85 | + id="dummy_id", |
| 86 | + ), |
| 87 | + ) |
| 88 | + product.product_type = collection_id |
| 89 | + config = PluginConfig() |
| 90 | + config.priority = 0 |
| 91 | + downloader = HTTPDownload("peps", config) |
| 92 | + |
| 93 | + product.register_downloader(downloader=downloader, authenticator=None) |
| 94 | + |
| 95 | + mock_search.return_value = SearchResult([product]) |
| 96 | + mock_http_base_stream_download_dict.return_value = stream_response |
| 97 | + |
| 98 | + await request_valid_raw(url, search_result=SearchResult([product])) |
| 99 | + |
| 100 | + assert mock_order.called |
0 commit comments