-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue 19 Use preferred CMR-Search-After method for iterating through …
…results (#22) * Added vcr tests * Added uniquess test * More comments * Updated dependencies * Refatored fixture location * Remove DSStore files * Remove ds store files * Removed CMR-Search-After header once get method completes * Removed unnecessary reference to requests_mock --------- Co-authored-by: Doug Newman <douglas.j.newamn@nasa.gov>
- Loading branch information
1 parent
32fb1fb
commit 1702100
Showing
11 changed files
with
53,164 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,5 @@ venv/ | |
tags | ||
.venv | ||
*.egg-info | ||
dist | ||
dist | ||
.vscode/* |
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
12,068 changes: 12,068 additions & 0 deletions
12,068
tests/fixtures/vcr_cassettes/MOD02QKM_2000.yaml
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import unittest | ||
import json | ||
|
||
import vcr | ||
import urllib.request | ||
|
||
from cmr.queries import GranuleQuery | ||
|
||
my_vcr = vcr.VCR( | ||
record_mode='once', | ||
decode_compressed_response=True, | ||
# Header matching is not set by default, we need that to test the | ||
# search-after functionality is performing correctly. | ||
match_on=['method', 'scheme', 'host', 'port', 'path', 'query', 'headers'] | ||
) | ||
|
||
def assert_unique_granules_from_results(granules): | ||
""" | ||
When we invoke a search request multiple times we want to ensure that we don't | ||
get the same results back. This is a one shot test as the results are preserved | ||
by VCR but still useful. | ||
""" | ||
granule_ids = [] | ||
for granule in granules: | ||
granule_ids.append(granule['title']) | ||
|
||
unique_granules = set(granule_ids) | ||
return len(unique_granules) == len(granule_ids) | ||
|
||
class TestMultipleQueries(unittest.TestCase): | ||
|
||
def test_get_more_than_2000(self): | ||
""" | ||
If we execute a get with a limit of more than 2000 | ||
then we expect multiple invocations of a cmr granule search and | ||
to not fetch back more results than we ask for | ||
""" | ||
with my_vcr.use_cassette('tests/fixtures/vcr_cassettes/MOD02QKM.yaml') as cass: | ||
api = GranuleQuery() | ||
|
||
granules = api.short_name("MOD02QKM").get(3000) | ||
self.assertEqual(len(granules), 3000) | ||
# Assert all 3000 qranule results have unique granule ids | ||
assert_unique_granules_from_results(granules) | ||
# Assert that we performed two search results queries | ||
self.assertEqual(len(cass), 2) | ||
self.assertIsNone(api.headers.get('cmr-search-after')) | ||
|
||
def test_get(self): | ||
""" | ||
If we execute a get with no arguments then we expect | ||
to get the maximum no. of granules from a single CMR call (2000) | ||
in a single request | ||
""" | ||
with my_vcr.use_cassette('tests/fixtures/vcr_cassettes/MOD02QKM_2000.yaml') as cass: | ||
api = GranuleQuery() | ||
granules = api.short_name("MOD02QKM").get() | ||
self.assertEqual(len(granules), 2000) | ||
# Assert all 2000 qranule results have unique granule ids | ||
assert_unique_granules_from_results(granules) | ||
# Assert that we performed one search results query | ||
self.assertEqual(len(cass), 1) | ||
self.assertIsNone(api.headers.get('cmr-search-after')) | ||
|
||
def test_get_all_less_than_2k(self): | ||
""" | ||
If we execute a get_all then we expect multiple | ||
invocations of a cmr granule search and | ||
to not fetch back more results than we ask for | ||
""" | ||
with my_vcr.use_cassette('tests/fixtures/vcr_cassettes/TELLUS_GRAC.yaml') as cass: | ||
api = GranuleQuery() | ||
granules = api.short_name("TELLUS_GRAC_L3_JPL_RL06_LND_v04").get_all() | ||
self.assertEqual(len(granules), 163) | ||
# Assert all 163 qranule results have unique granule ids | ||
assert_unique_granules_from_results(granules) | ||
# Assert that we performed a hits query and one search results query | ||
self.assertEqual(len(cass), 2) | ||
self.assertIsNone(api.headers.get('cmr-search-after')) | ||
|
||
def test_get_all_more_than_2k(self): | ||
""" | ||
If we execute a get_all then we expect multiple | ||
invocations of a cmr granule search and | ||
to not fetch back more results than we ask for | ||
""" | ||
with my_vcr.use_cassette('tests/fixtures/vcr_cassettes/CYGNSS.yaml') as cass: | ||
api = GranuleQuery() | ||
granules = api.short_name("CYGNSS_NOAA_L2_SWSP_25KM_V1.2").get_all() | ||
self.assertEqual(len(granules), 2285) | ||
# Assert all 2285 qranule results have unique granule ids | ||
assert_unique_granules_from_results(granules) | ||
# Assert that we performed a hits query and two search results queries | ||
self.assertEqual(len(cass), 3) | ||
self.assertIsNone(api.headers.get('cmr-search-after')) |