Skip to content

Commit

Permalink
rolls dataset tests into project testing framework
Browse files Browse the repository at this point in the history
  • Loading branch information
kim committed Nov 8, 2023
1 parent e80946a commit c8ae701
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 18 deletions.
30 changes: 13 additions & 17 deletions tests/Search/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from asf_search.ASFSearchResults import ASFSearchResults
from asf_search.CMR import dataset_collections
from pytest import raises
from typing import List
import requests
import requests_mock

Expand Down Expand Up @@ -74,24 +75,19 @@ def custom_matcher(request: requests.Request):
with raises(ASFSearchError):
results.raise_if_incomplete()

def test_datasets_search():
datasets = ['SENTINEL-1', 'RADARSAT-1', 'UAVSAR']
should_raise_error = len([dataset for dataset in datasets if not dataset_collections.get(dataset)]) > 0

if should_raise_error:
def run_test_datasets_search(datasets: List):
if any(dataset for dataset in datasets if dataset_collections.get(dataset) is None):
with raises(ValueError):
search(datasets=datasets, maxResults=1)
else:
valid_shortnames = []
else:
for dataset in datasets:
valid_shortnames.extend([shortName for shortName in dataset_collections.get(dataset).keys()])

response = search(datasets=datasets, maxResults=250)
valid_shortnames = list(dataset_collections.get(dataset))

# Get collection shortName of all granules
shortNames = list(set([get(product.umm, 'CollectionReference', 'ShortName') for product in response]))

# and check that results are limited to the expected datasets by their shortname
for shortName in shortNames:
assert shortName in valid_shortnames

response = search(datasets=dataset, maxResults=250)

# Get collection shortName of all granules
shortNames = list(set([shortName for product in response if (shortName:=get(product.umm, 'CollectionReference', 'ShortName')) is not None]))

# and check that results are limited to the expected datasets by their shortname
for shortName in shortNames:
assert shortName in valid_shortnames
5 changes: 5 additions & 0 deletions tests/pytest-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,11 @@ test_types:
required_keys: results
method: test_output_format

- For running datasets keyword tests:
required_in_title: search-datasets
required_keys: datasets
method: test_search_datasets

- For running jupyter notebook example tests:
required_keys: notebook
method: test_notebook_examples
6 changes: 5 additions & 1 deletion tests/pytest-managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from ASFSearchResults.test_ASFSearchResults import run_test_output_format, run_test_ASFSearchResults_intersection
from ASFSession.test_ASFSession import run_auth_with_cookiejar, run_auth_with_creds, run_auth_with_token, run_test_asf_session_rebuild_auth
from BaselineSearch.test_baseline_search import *
from Search.test_search import run_test_ASFSearchResults, run_test_search, run_test_search_http_error
from Search.test_search import run_test_ASFSearchResults, run_test_datasets_search, run_test_search, run_test_search_http_error
from Search.test_search_generator import run_test_search_generator, run_test_search_generator_multi
from CMR.test_MissionList import run_test_get_project_names

Expand Down Expand Up @@ -417,6 +417,10 @@ def test_ASFSearchResults_intersection(**kwargs) -> None:
wkt = get_resource(kwargs['test_info']['wkt'])
run_test_ASFSearchResults_intersection(wkt)

def test_search_datasets(**kwargs) -> None:
datasets = get_resource(kwargs['test_info']['datasets'])
run_test_datasets_search(datasets)

def test_serialization(**args) -> None:
test_info = args['test_info']
product = get_resource(test_info.get('product'))
Expand Down
12 changes: 12 additions & 0 deletions tests/yml_tests/test_search.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,15 @@ tests:
platform: "Sentinel-1"
status_code: 500
report: "Server Error: This is a Test Error"

- test-search-datasets S1 Datasets:
datasets: ['SENTINEL-1', 'SLC-BURST', 'OPERA-S1']

- test-search-datasets S1 Datasets and non-S1:
datasets: ['SENTINEL-1', 'SLC-BURST', 'OPERA-S1', 'UAVSAR']

- test-search-datasets fake dataset:
datasets: 'FAKE-DATASET-V1'

- test-search-datasets S1 Datasets and fake dataset:
datasets: ['SENTINEL-1', 'SLC-BURST', 'OPERA-S1', 'FAKE-DATASET-V2']

0 comments on commit c8ae701

Please sign in to comment.