def test_with_invalid_request(): collection = Collection(id='C333666999-EOSDIS') request = Request(collection=collection, spatial=BBox(-190, -100, 100, 190)) with pytest.raises(Exception): Client(should_validate_auth=False).submit(request)
def test_request_spatial_bounding_box(west, south, east, north): spatial = BBox(west, south, east, north) request = Request( collection=Collection('foobar'), spatial=spatial, ) if request.is_valid(): assert request.spatial is not None w, s, e, n = request.spatial assert w == west assert s == south assert e == east assert n == north assert south < north assert south >= -90.0 assert north >= -90.0 assert south <= 90.0 assert north <= 90.0 assert west >= -180.0 assert east >= -180.0 assert west <= 180.0 assert east <= 180.0
def test_with_bounding_box(): collection = Collection(id='C1940468263-POCLOUD') request = Request(collection=collection, spatial=BBox(-107, 40, -105, 42)) job_id = '21469294-d6f7-42cc-89f2-c81990a5d7f4' responses.add(responses.GET, expected_submit_url(collection.id), status=200, json=expected_job(collection.id, job_id)) actual_job_id = Client(should_validate_auth=False).submit(request) assert len(responses.calls) == 1 assert responses.calls[0].request is not None assert urllib.parse.unquote( responses.calls[0].request.url) == expected_full_submit_url(request) assert actual_job_id == job_id
def test_when_multiple_submits_it_only_authenticates_once(): collection = Collection(id='C1940468263-POCLOUD') request = Request(collection=collection, spatial=BBox(-107, 40, -105, 42)) job_id = '3141592653-abcd-1234' auth_url = 'https://harmony.uat.earthdata.nasa.gov/jobs' responses.add(responses.GET, auth_url, status=200) responses.add(responses.GET, expected_submit_url(collection.id), status=200, json=expected_job(collection.id, job_id)) client = Client() client.submit(request) client.submit(request) assert len(responses.calls) == 3 assert responses.calls[0].request.url == auth_url assert urllib.parse.unquote(responses.calls[0].request.url) == auth_url assert urllib.parse.unquote( responses.calls[1].request.url) == expected_full_submit_url(request) assert urllib.parse.unquote( responses.calls[2].request.url) == expected_full_submit_url(request)
def test_with_bounding_box_and_temporal_range(): collection = Collection(id='C333666999-EOSDIS') request = Request( collection=collection, spatial=BBox(-107, 40, -105, 42), temporal={ 'start': dt.datetime(2001, 1, 1), 'stop': dt.datetime(2003, 3, 31) }, ) job_id = '1234abcd-1234-9876-6666-999999abcd' responses.add(responses.GET, expected_submit_url(collection.id), status=200, json=expected_job(collection.id, job_id)) actual_job_id = Client(should_validate_auth=False).submit(request) assert len(responses.calls) == 1 assert responses.calls[0].request is not None assert urllib.parse.unquote( responses.calls[0].request.url) == expected_full_submit_url(request) assert actual_job_id == job_id
def test_with_shapefile(): collection = Collection(id='C333666999-EOSDIS') request = Request( collection=collection, shape='./examples/asf_example.json', spatial=BBox(-107, 40, -105, 42), ) job_id = '1234abcd-1234-9876-6666-999999abcd' responses.add(responses.POST, expected_submit_url(collection.id), status=200, json=expected_job(collection.id, job_id)) actual_job_id = Client(should_validate_auth=False).submit(request) assert len(responses.calls) == 1 post_request = responses.calls[0].request post_body = post_request.body.decode('utf-8') assert post_request is not None # GeoJSON is present in the submit body assert 'FeatureCollection' in post_body assert 'Content-Type: application/geo+json' in post_body # Submit URL has no query params assert urllib.parse.unquote(post_request.url) == expected_submit_url( collection.id) # Would-be query params are in the POST body assert 'Content-Disposition: form-data; name="forceAsync"\r\n\r\ntrue' in post_body assert 'Content-Disposition: form-data; name="subset"\r\n\r\nlat(40:42)' in post_body assert 'Content-Disposition: form-data; name="subset"\r\n\r\nlon(-107:-105)' in post_body assert actual_job_id == job_id
st.text()), datetime_a=st.datetimes(), datetime_b=st.datetimes()) def test_request_temporal_range(key_a, key_b, datetime_a, datetime_b): temporal = {key_a: datetime_a, key_b: datetime_b} request = Request(collection=Collection('foobar'), temporal=temporal) if request.is_valid(): assert request.temporal is not None assert 'start' in request.temporal or 'stop' in request.temporal if 'start' in request.temporal and 'stop' in request.temporal: assert request.temporal['start'] < request.temporal['stop'] @pytest.mark.parametrize('key, value, message', [ ('spatial', BBox(10, -10, 20, -20), 'Southern latitude must be less than Northern latitude'), ('spatial', BBox(10, -100, 20, 20), 'Southern latitude must be greater than -90.0'), ('spatial', BBox(10, -110, 20, -100), 'Northern latitude must be greater than -90.0'), ('spatial', BBox(10, 100, 20, 110), 'Southern latitude must be less than 90.0'), ('spatial', BBox(10, 10, 20, 100), 'Northern latitude must be less than 90.0'), ('spatial', BBox(-190, 10, 20, 20), 'Western longitude must be greater than -180.0'), ('spatial', BBox(-200, 10, -190, 20), 'Eastern longitude must be greater than -180.0'), ('spatial', BBox(10, 10, 190, 20), 'Eastern longitude must be less than 180.0'),