-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Theia Update USGS API Callouts to reflect USGS API changes and Landsa…
…t Collection 1 Data Shutdown (#189) * commenting out espa wrapper orders. orders now done through eros wrapper (m2m api) * remove unneeded apiKey parameter * attempt to replace espa api calls with corresponding eros calls * update metadata parsing * update typo missing arg on cloud_cover * update Bands to match new file names * remove comments from floating_forest.py xml operations * Update ErosWraper to remove unused download_urls method and update comment of what requested -download result will look like * remove unused threading on eros wrapper * remove unused code from tasks.py wait_for_scene * undo change in settings.py on ALLOWED_HOSTS * update adapter.py to remove unused code * remove logs from espa wrapper. will keep in case we need to make any future callouts to ESPA API * fix tests in Adapter and set default dataset to Landsat c2 l2 * update eros scene-search test to not take in the expected response as an argument to expected call * remove unused vars on tests and update wait_for_scene tests to expect eros calls instead of ESPA calls * adding tests to add_scene_to_order_list new method * add login and token expiration check tests * add tests for requesting available products * add tests for requesting downloads * update test_adapter.py to fake user login
- Loading branch information
1 parent
0570a43
commit 38aee43
Showing
8 changed files
with
368 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,59 @@ | ||
import pytest | ||
from unittest.mock import patch | ||
import theia.adapters.usgs.tasks | ||
|
||
EROS_AVAILABLE_PRODUCTS_EXAMPLE = [{'entityId': 'LANDSATIMAGE123', 'productId': 123, 'displayId': 'LANDSAT_IMAGE_123'}] | ||
EROS_REQUEST_DOWNLOAD_PENDING_DOWNLOADS_RESULT = { | ||
"availableDownloads":[], | ||
"duplicateProducts":[], | ||
"preparingDownloads":[ | ||
{ | ||
"downloadId":550754832, | ||
"eulaCode":"None", | ||
"url":"https://dds.cr.usgs.gov/download-staging/eyJpZCI6NTUwNzU0ODMyLCJjb250YWN0SWQiOjI2MzY4NDQ1fQ==" | ||
} | ||
] | ||
} | ||
|
||
EROS_REQUEST_DOWNLOAD_DOWNLOADS_AVAILABLE_RESULT = { | ||
"availableDownloads":[{ | ||
"downloadId":550752861, | ||
"eulaCode":"None", | ||
"url":"https://dds.cr.usgs.gov/download-staging/eyJpZCI6NTUwNzUyODYxLCJjb250YWN0SWQiOjI2MzY4NDQ1fQ==" | ||
}], | ||
"duplicateProducts":[], | ||
"preparingDownloads":[] | ||
} | ||
|
||
@patch('theia.api.models.RequestedScene.objects.get', autospec=True) | ||
@patch('theia.adapters.usgs.EspaWrapper.order_status', autospec=True) | ||
@patch('theia.adapters.usgs.ErosWrapper.request_download', autospec=True) | ||
def test_wait_for_scene_already_done(mockStatus, mockGetScene): | ||
mockGetScene.return_value.status=1 | ||
theia.adapters.usgs.tasks.wait_for_scene(1) | ||
theia.adapters.usgs.tasks.wait_for_scene(1, EROS_AVAILABLE_PRODUCTS_EXAMPLE) | ||
mockStatus.assert_not_called() | ||
|
||
@patch('theia.api.models.RequestedScene.objects.get', autospec=True) | ||
@patch('theia.adapters.usgs.EspaWrapper.order_status', return_value='whatever') | ||
@patch('theia.adapters.usgs.EspaWrapper.download_urls', autospec=True) | ||
@patch('theia.adapters.usgs.ErosWrapper.request_download', return_value=EROS_REQUEST_DOWNLOAD_PENDING_DOWNLOADS_RESULT) | ||
@patch('theia.adapters.usgs.tasks.wait_for_scene.apply_async', autospec=True) | ||
def test_wait_for_scene_pending(mockWait, mockUrls, mockStatus, mockGetScene): | ||
def test_wait_for_scene_pending(mockWait, mockStatus, mockGetScene): | ||
mockGetScene.return_value.status=0 | ||
mockGetScene.return_value.scene_order_id='order id' | ||
|
||
theia.adapters.usgs.tasks.wait_for_scene(3) | ||
theia.adapters.usgs.tasks.wait_for_scene(3, EROS_AVAILABLE_PRODUCTS_EXAMPLE) | ||
|
||
mockGetScene.assert_called_once_with(pk=3) | ||
mockStatus.assert_called_once_with('order id') | ||
mockStatus.assert_called_once_with(EROS_AVAILABLE_PRODUCTS_EXAMPLE) | ||
mockGetScene.return_value.save.assert_called_once() | ||
mockWait.assert_called_once() | ||
|
||
@patch('theia.api.models.RequestedScene.objects.get', autospec=True) | ||
@patch('theia.adapters.usgs.EspaWrapper.order_status', return_value='complete') | ||
@patch('theia.adapters.usgs.EspaWrapper.download_urls') | ||
@patch('theia.adapters.usgs.ErosWrapper.request_download', return_value=EROS_REQUEST_DOWNLOAD_DOWNLOADS_AVAILABLE_RESULT) | ||
@patch('theia.api.models.JobBundleManager.from_requested_scene', autospec=True) | ||
def test_wait_for_scene_ready(mockConstruct, mockUrls, mockStatus, mockGetScene): | ||
def test_wait_for_scene_ready(mockConstruct, mockStatus, mockGetScene): | ||
mockGetScene.return_value.status=0 | ||
mockGetScene.return_value.scene_order_id='order id' | ||
theia.adapters.usgs.tasks.wait_for_scene(3) | ||
theia.adapters.usgs.tasks.wait_for_scene(3, EROS_AVAILABLE_PRODUCTS_EXAMPLE) | ||
|
||
mockGetScene.assert_called_once_with(pk=3) | ||
mockStatus.assert_called_once_with('order id') | ||
mockStatus.assert_called_once_with(EROS_AVAILABLE_PRODUCTS_EXAMPLE) | ||
mockGetScene.return_value.save.assert_called() | ||
mockConstruct.assert_called_once() | ||
mockConstruct.assert_called_once() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.