Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
assert (
query
== "beginPosition:[%s TO NOW] " % (format_query_date(last_24h))
+ 'producttype:SLC IW footprint:"Intersects(POLYGON((0 0,1 1,0 1,0 0)))"'
)
query = SentinelAPI.format_query(wkt, producttype="SLC", raw="IW")
assert query == 'producttype:SLC IW footprint:"Intersects(POLYGON((0 0,1 1,0 1,0 0)))"'
query = SentinelAPI.format_query(area=None, date=None)
assert query == ""
query = SentinelAPI.format_query()
assert query == ""
query = SentinelAPI.format_query(raw="test")
assert query == "test"
def test_api_query_format_sets():
query = SentinelAPI.format_query(orbitnumber={16301, 16302, 16303})
assert query == "orbitnumber:(16301 OR 16302 OR 16303)"
query = SentinelAPI.format_query(ingestiondate={date(2017, 1, 1), "20170203"})
assert query == "ingestiondate:(2017-01-01T00:00:00Z OR 2017-02-03T00:00:00Z)"
def test_api_query_format():
wkt = 'POLYGON((0 0,1 1,0 1,0 0))'
now = datetime.now()
last_24h = format_query_date(now - timedelta(hours=24))
query = SentinelAPI.format_query(wkt, (last_24h, now))
assert query == 'beginPosition:[%s TO %s] ' % (last_24h, format_query_date(now)) + \
'footprint:"Intersects(POLYGON((0 0,1 1,0 1,0 0)))"'
query = SentinelAPI.format_query(wkt, date=(last_24h, "NOW"), producttype='SLC', raw='IW')
assert query == 'beginPosition:[%s TO NOW] ' % (format_query_date(last_24h)) + \
'producttype:SLC IW footprint:"Intersects(POLYGON((0 0,1 1,0 1,0 0)))"'
query = SentinelAPI.format_query(wkt, producttype='SLC', raw='IW')
assert query == 'producttype:SLC IW footprint:"Intersects(POLYGON((0 0,1 1,0 1,0 0)))"'
query = SentinelAPI.format_query(area=None, date=None)
assert query == ''
query = SentinelAPI.format_query()
assert query == ''
query = SentinelAPI.format_query(raw='test')
assert query == 'test'
query = SentinelAPI.format_query(ingestiondate=(date(2017, 1, 1), "20170203"))
assert query == "ingestiondate:[2017-01-01T00:00:00Z TO 2017-02-03T00:00:00Z]"
query = SentinelAPI.format_query(ingestiondate="[NOW-1DAY TO NOW]")
assert query == "ingestiondate:[NOW-1DAY TO NOW]"
query = SentinelAPI.format_query(ingestiondate=[None, "NOW"])
assert query == "ingestiondate:[* TO NOW]"
for value in [(None, None), ("*", None), (None, "*"), ("*", "*")]:
query = SentinelAPI.format_query(ingestiondate=value)
assert query == ""
with pytest.raises(ValueError):
SentinelAPI.format_query(date="NOW")
with pytest.raises(ValueError):
SentinelAPI.format_query(date=["NOW"])
with pytest.raises(ValueError):
SentinelAPI.format_query(ingestiondate=[])
def test_api_query_format_ranges():
query = SentinelAPI.format_query(cloudcoverpercentage=(0, 30))
assert query == 'cloudcoverpercentage:[0 TO 30]'
query = SentinelAPI.format_query(cloudcoverpercentage=[0, 30])
assert query == 'cloudcoverpercentage:[0 TO 30]'
query = SentinelAPI.format_query(cloudcoverpercentage=[None, 30])
assert query == 'cloudcoverpercentage:[* TO 30]'
query = SentinelAPI.format_query(orbitnumber=(16302, None))
assert query == 'orbitnumber:[16302 TO *]'
query = SentinelAPI.format_query(orbitnumber=(16302, '*'))
assert query == 'orbitnumber:[16302 TO *]'
for value in [(None, None), ('*', None), (None, '*'), ('*', '*')]:
query = SentinelAPI.format_query(orbitnumber=value)
assert query == ''
with pytest.raises(ValueError):
def test_api_query_format():
wkt = 'POLYGON((0 0,1 1,0 1,0 0))'
now = datetime.now()
last_24h = format_query_date(now - timedelta(hours=24))
query = SentinelAPI.format_query(wkt, (last_24h, now))
assert query == 'beginPosition:[%s TO %s] ' % (last_24h, format_query_date(now)) + \
'footprint:"Intersects(POLYGON((0 0,1 1,0 1,0 0)))"'
query = SentinelAPI.format_query(wkt, date=(last_24h, "NOW"), producttype='SLC', raw='IW')
assert query == 'beginPosition:[%s TO NOW] ' % (format_query_date(last_24h)) + \
'producttype:SLC IW footprint:"Intersects(POLYGON((0 0,1 1,0 1,0 0)))"'
query = SentinelAPI.format_query(wkt, producttype='SLC', raw='IW')
assert query == 'producttype:SLC IW footprint:"Intersects(POLYGON((0 0,1 1,0 1,0 0)))"'
query = SentinelAPI.format_query(area=None, date=None)
assert query == ''
query = SentinelAPI.format_query()
assert query == ''
query = SentinelAPI.format_query(ingestiondate=[None, "NOW"])
assert query == "ingestiondate:[* TO NOW]"
for value in [(None, None), ("*", None), (None, "*"), ("*", "*")]:
query = SentinelAPI.format_query(ingestiondate=value)
assert query == ""
with pytest.raises(ValueError):
SentinelAPI.format_query(date="NOW")
with pytest.raises(ValueError):
SentinelAPI.format_query(date=["NOW"])
with pytest.raises(ValueError):
SentinelAPI.format_query(ingestiondate=[])
def test_api_query_format_escape_spaces(api):
query = SentinelAPI.format_query(ingestiondate=("NOW-1DAY", "NOW"))
assert query == "ingestiondate:[NOW-1DAY TO NOW]"
query = SentinelAPI.format_query(ingestiondate="[NOW-1DAY TO NOW]")
assert query == "ingestiondate:[NOW-1DAY TO NOW]"
query = SentinelAPI.format_query(ingestiondate=" [NOW-1DAY TO NOW] ")
assert query == "ingestiondate:[NOW-1DAY TO NOW]"
query = SentinelAPI.format_query(relativeorbitnumber=" {101 TO 103} ")
assert query == "relativeorbitnumber:{101 TO 103}"
query = SentinelAPI.format_query(filename="S3A_OL_2* ")
assert query == "filename:S3A_OL_2*"
query = SentinelAPI.format_query(timeliness="Non Time Critical")
assert query == r"timeliness:Non\ Time\ Critical"
query = SentinelAPI.format_query(timeliness="Non\tTime\tCritical")
assert query == r"timeliness:Non\ Time\ Critical"
assert api.count(timeliness="Non Time Critical") > 0
# Allow for regex weirdness
query = SentinelAPI.format_query(timeliness=".+ Critical")
assert query == r"timeliness:.+\ Critical"
assert api.count(timeliness=".+ Critical") > 0
query = SentinelAPI.format_query(identifier="/S[123 ]A.*/")
'footprint:"Intersects(POLYGON((0 0,1 1,0 1,0 0)))"'
query = SentinelAPI.format_query(wkt, date=(last_24h, "NOW"), producttype='SLC', raw='IW')
assert query == 'beginPosition:[%s TO NOW] ' % (format_query_date(last_24h)) + \
'producttype:SLC IW footprint:"Intersects(POLYGON((0 0,1 1,0 1,0 0)))"'
query = SentinelAPI.format_query(wkt, producttype='SLC', raw='IW')
assert query == 'producttype:SLC IW footprint:"Intersects(POLYGON((0 0,1 1,0 1,0 0)))"'
query = SentinelAPI.format_query(area=None, date=None)
assert query == ''
query = SentinelAPI.format_query()
assert query == ''
query = SentinelAPI.format_query(raw='test')
assert query == 'test'
def test_api_query_format():
wkt = "POLYGON((0 0,1 1,0 1,0 0))"
now = datetime.now()
last_24h = format_query_date(now - timedelta(hours=24))
query = SentinelAPI.format_query(wkt, (last_24h, now))
assert (
query
== "beginPosition:[%s TO %s] " % (last_24h, format_query_date(now))
+ 'footprint:"Intersects(POLYGON((0 0,1 1,0 1,0 0)))"'
)
query = SentinelAPI.format_query(wkt, date=(last_24h, "NOW"), producttype="SLC", raw="IW")
assert (
query
== "beginPosition:[%s TO NOW] " % (format_query_date(last_24h))
+ 'producttype:SLC IW footprint:"Intersects(POLYGON((0 0,1 1,0 1,0 0)))"'
)
query = SentinelAPI.format_query(wkt, producttype="SLC", raw="IW")
assert query == 'producttype:SLC IW footprint:"Intersects(POLYGON((0 0,1 1,0 1,0 0)))"'