Skip to content

Commit

Permalink
adds build_subquery test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
kim committed Nov 16, 2023
1 parent 3545799 commit b53aea3
Show file tree
Hide file tree
Showing 5 changed files with 233 additions and 5 deletions.
6 changes: 3 additions & 3 deletions asf_search/CMR/subquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def build_subqueries(opts: ASFSearchOptions) -> List[ASFSearchOptions]:

if (processingLevel_collections := params.get('processingLevel_collections')) is not None:
if len(processingLevel_collections):
params['collections'] = intersect1d(processingLevel_collections, params['collections']).tolist()
params['collections'] = list(intersect1d(processingLevel_collections, params['collections']))

params.pop('processingLevel_collections')

Expand All @@ -78,7 +78,7 @@ def build_subqueries(opts: ASFSearchOptions) -> List[ASFSearchOptions]:

if (processingLevel_collections := params.get('processingLevel_collections')) is not None:
if len(processingLevel_collections):
params['collections'] = intersect1d(processingLevel_collections, params['collections']).tolist()
params['collections'] = list(intersect1d(processingLevel_collections, params['collections']))

params.pop('processingLevel_collections')

Expand All @@ -90,7 +90,7 @@ def build_subqueries(opts: ASFSearchOptions) -> List[ASFSearchOptions]:
params['collections'] = params.get('processingLevel_collections')
else:
if (processingLevel_collections := params.get('processingLevel_collections')) is not None:
params['collections'] = intersect1d(processingLevel_collections, params['collections']).tolist()
params['collections'] = list(intersect1d(processingLevel_collections, params['collections']))

if params.get('processingLevel_collections') is not None:
params.pop('processingLevel_collections')
Expand Down
8 changes: 8 additions & 0 deletions tests/Search/test_search.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from numbers import Number
from asf_search import ASFSearchOptions
from asf_search.ASFProduct import ASFProduct
from asf_search.CMR.subquery import build_subqueries
from asf_search.CMR.translate import get
from asf_search.constants import INTERNAL
from asf_search.exceptions import ASFSearchError
Expand Down Expand Up @@ -91,3 +92,10 @@ def run_test_dataset_search(datasets: List):
# and check that results are limited to the expected datasets by their shortname
for shortName in shortNames:
assert shortName in valid_shortnames

def run_test_build_subqueries(params: ASFSearchOptions, expected: List):
actual = build_subqueries(params)
for a, b in zip(actual, expected):
for a_param, b_param in zip(a, b):
if isinstance(b_param, list):
assert len(set(b_param).difference(set(a_param))) == 0
5 changes: 5 additions & 0 deletions tests/pytest-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,11 @@ test_types:
required_keys: dataset
method: test_search_dataset

- For running build_subquery tests:
required_in_title: search-build_subquery
required_keys: ['params', 'expected']
method: test_build_subqueries

- For running jupyter notebook example tests:
required_keys: notebook
method: test_notebook_examples
9 changes: 7 additions & 2 deletions 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_dataset_search, run_test_search, run_test_search_http_error
from Search.test_search import run_test_ASFSearchResults, run_test_build_subqueries, run_test_dataset_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 @@ -420,7 +420,12 @@ def test_ASFSearchResults_intersection(**kwargs) -> None:
def test_search_dataset(**kwargs) -> None:
dataset = get_resource(kwargs['test_info']['dataset'])
run_test_dataset_search(dataset)


def test_build_subqueries(**kwargs) -> None:
params = ASFSearchOptions(**get_resource(kwargs['test_info']['params']))
expected = [ASFSearchOptions(**subquery) for subquery in get_resource(kwargs['test_info']['expected'])]
run_test_build_subqueries(params, expected)

def test_serialization(**args) -> None:
test_info = args['test_info']
product = get_resource(test_info.get('product'))
Expand Down
210 changes: 210 additions & 0 deletions tests/yml_tests/test_search.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,213 @@ tests:

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

- test-search-build_subquery S1-Platform:
params:
platform: ['SENTINEL-1A', 'SENTINEL-1B']
expected:
[{
collections: [
"C1214470488-ASF", # S1A
"C1214470533-ASF",
"C1214470576-ASF",
"C1595422627-ASF",
"C1214470496-ASF",
"C1214470532-ASF",
"C1214472977-ASF",
"C1214472336-ASF",
"C1266376001-ASF",
"C1214472994-ASF",
"C1214470732-ASF",
"C1214473170-ASF",
"C1214470561-ASF",
"C1214471521-ASF",
"C1214470682-ASF",
"C2777443834-ASF",
"C2777436413-ASF",
"C1214471197-ASF",
"C1214471960-ASF",
"C1214472978-ASF",
"C1214473165-ASF",
"C2709161906-ASF",
"C1596065640-ASF",
"C1596065639-ASF",
"C1596065641-ASF",
"C1595765183-ASF",
"C2450786986-ASF",
"C1205428742-ASF",
"C1212201032-ASF",
"C1212212560-ASF",
"C1205264459-ASF",
"C1208117434-ASF",
"C1212209035-ASF",
"C1212209226-ASF",
"C1208115009-ASF",
"C1212158327-ASF",
"C1215704763-ASF",
"C1225776654-ASF",
"C1212158318-ASF",
"C1212212493-ASF",
"C1212158326-ASF",
"C1212233976-ASF",
"C1260726384-ASF",
"C1258354200-ASF",
"C1259982010-ASF",
"C1260721945-ASF",
"C1257995185-ASF",
"C1259976861-ASF",
"C1260726378-ASF",
"C1258354201-ASF",
"C1259981910-ASF",
"C1260721853-ASF",
"C1257995186-ASF",
"C1259974840-ASF",
"C1212200781-ASF",
"C1212209075-ASF",
"C1257024016-ASF",
"C1225776655-ASF",
"C1225776657-ASF",
"C1225776658-ASF",
"C1225776659-ASF",
"C1245953394-ASF",
"C1234413245-ASFDEV",
"C1234413229-ASFDEV",
"C1234413237-ASFDEV",
"C1234413238-ASFDEV",
"C1234413236-ASFDEV",
"C1234413230-ASFDEV",
"C1234413232-ASFDEV",
"C1234413235-ASFDEV",
"C1234413240-ASFDEV",
"C1234413234-ASFDEV",
"C1234413241-ASFDEV",
"C1234413233-ASFDEV",
"C1234413243-ASFDEV",
"C1234413244-ASFDEV",
"C1244552887-ASFDEV",
"C1234413228-ASFDEV",
"C1234413231-ASFDEV",
"C1234413239-ASFDEV",
"C1234413242-ASFDEV",
"C1257175154-ASFDEV",
"C1244598379-ASFDEV",
"C1240784657-ASFDEV",
"C1327985661-ASF", # S1B
"C1327985645-ASF",
"C1595422627-ASF",
"C1327985617-ASF",
"C1327985660-ASF",
"C1327985741-ASF",
"C1327985578-ASF",
"C1327985646-ASF",
"C1327985650-ASF",
"C1327985579-ASF",
"C1327985740-ASF",
"C1327985619-ASF",
"C1327985739-ASF",
"C1327985647-ASF",
"C2777443834-ASF",
"C2777436413-ASF",
"C1327985697-ASF",
"C1327985651-ASF",
"C1327985644-ASF",
"C1327985571-ASF",
"C1327985674-ASF",
"C2709161906-ASF",
"C1596065640-ASF",
"C1596065639-ASF",
"C1596065641-ASF",
"C1595765183-ASF",
"C2450786986-ASF",
"C1216244348-ASF",
"C1216244589-ASF",
"C1216244594-ASF",
"C1216244593-ASF",
"C1216244585-ASF",
"C1216244592-ASF",
"C1216244595-ASF",
"C1225776654-ASF",
"C1216244590-ASF",
"C1216244601-ASF",
"C1216244600-ASF",
"C1216244591-ASF",
"C1216244587-ASF",
"C1216244598-ASF",
"C1216244586-ASF",
"C1260726384-ASF",
"C1258354200-ASF",
"C1259982010-ASF",
"C1260721945-ASF",
"C1257995185-ASF",
"C1259976861-ASF",
"C1260726378-ASF",
"C1258354201-ASF",
"C1259981910-ASF",
"C1260721853-ASF",
"C1257995186-ASF",
"C1259974840-ASF",
"C1216244597-ASF",
"C1216244596-ASF",
"C1216244588-ASF",
"C1216244599-ASF",
"C1257024016-ASF",
"C1225776655-ASF",
"C1225776657-ASF",
"C1225776658-ASF",
"C1225776659-ASF",
"C1245953394-ASF",
"C1234413263-ASFDEV",
"C1234413247-ASFDEV",
"C1234413248-ASFDEV",
"C1234413255-ASFDEV",
"C1234413254-ASFDEV",
"C1234413256-ASFDEV",
"C1234413253-ASFDEV",
"C1234413252-ASFDEV",
"C1234413250-ASFDEV",
"C1234413259-ASFDEV",
"C1234413251-ASFDEV",
"C1234413261-ASFDEV",
"C1234413262-ASFDEV",
"C1234413258-ASFDEV",
"C1244552887-ASFDEV",
"C1234413246-ASFDEV",
"C1234413249-ASFDEV",
"C1234413257-ASFDEV",
"C1234413260-ASFDEV",
"C1257175154-ASFDEV",
"C1244598379-ASFDEV"
]
}]

- test-search-build_subquery S1-Platform SLC:
params:
platform: ['SENTINEL-1A', 'SENTINEL-1B']
processingLevel: ['SLC']
expected:
[{
collections: [
"C1214470488-ASF",
"C1205428742-ASF",
"C1234413245-ASFDEV",
"C1327985661-ASF",
"C1216244348-ASF",
"C1234413263-ASFDEV"
]
}]

- test-search-build_subquery S1-Dataset SLC:
params:
dataset: ['SENTINEL-1']
processingLevel: ['SLC']
expected:
[{
collections: [
"C1214470488-ASF",
"C1205428742-ASF",
"C1234413245-ASFDEV",
"C1327985661-ASF",
"C1216244348-ASF",
"C1234413263-ASFDEV"
]
}]

0 comments on commit b53aea3

Please sign in to comment.