Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_format_date(api):
assert format_query_date(datetime(2015, 1, 1)) == "2015-01-01T00:00:00Z"
assert format_query_date(date(2015, 1, 1)) == "2015-01-01T00:00:00Z"
assert format_query_date("2015-01-01T00:00:00Z") == "2015-01-01T00:00:00Z"
assert format_query_date("20150101") == "2015-01-01T00:00:00Z"
assert format_query_date(" NOW ") == "NOW"
assert format_query_date(None) == "*"
for date_str in (
"NOW",
"NOW-1DAY",
"NOW-1DAYS",
"NOW-500DAY",
"NOW-500DAYS",
"NOW-2MONTH",
"NOW-2MONTHS",
"NOW-20MINUTE",
"NOW-20MINUTES",
"NOW+10HOUR",
"2015-01-01T00:00:00Z+1DAY",
"NOW+3MONTHS-7DAYS/DAYS",
def test_format_date(api):
assert format_query_date(datetime(2015, 1, 1)) == '2015-01-01T00:00:00Z'
assert format_query_date(date(2015, 1, 1)) == '2015-01-01T00:00:00Z'
assert format_query_date('2015-01-01T00:00:00Z') == '2015-01-01T00:00:00Z'
assert format_query_date('20150101') == '2015-01-01T00:00:00Z'
assert format_query_date(' NOW ') == 'NOW'
assert format_query_date(None) == '*'
for date_str in ("NOW", "NOW-1DAY", "NOW-1DAYS", "NOW-500DAY", "NOW-500DAYS",
"NOW-2MONTH", "NOW-2MONTHS", "NOW-20MINUTE", "NOW-20MINUTES",
"NOW+10HOUR", "2015-01-01T00:00:00Z+1DAY", "NOW+3MONTHS-7DAYS/DAYS",
"*"):
assert format_query_date(date_str) == date_str
api.query(raw='ingestiondate:[{} TO *]'.format(date_str), limit=0)
for date_str in ("NOW - 1HOUR", "NOW - 1HOURS", "NOW-1 HOURS", "NOW-1", "NOW-", "**", "+", "-"):
with pytest.raises(ValueError):
format_query_date(date_str)
with pytest.raises(SentinelAPIError):
api.query(raw='ingestiondate:[{} TO *]'.format(date_str), limit=0)
def test_format_date(api):
assert format_query_date(datetime(2015, 1, 1)) == '2015-01-01T00:00:00Z'
assert format_query_date(date(2015, 1, 1)) == '2015-01-01T00:00:00Z'
assert format_query_date('2015-01-01T00:00:00Z') == '2015-01-01T00:00:00Z'
assert format_query_date('20150101') == '2015-01-01T00:00:00Z'
assert format_query_date(' NOW ') == 'NOW'
assert format_query_date(None) == '*'
for date_str in ("NOW", "NOW-1DAY", "NOW-1DAYS", "NOW-500DAY", "NOW-500DAYS",
"NOW-2MONTH", "NOW-2MONTHS", "NOW-20MINUTE", "NOW-20MINUTES",
"NOW+10HOUR", "2015-01-01T00:00:00Z+1DAY", "NOW+3MONTHS-7DAYS/DAYS",
"*"):
assert format_query_date(date_str) == date_str
api.query(raw='ingestiondate:[{} TO *]'.format(date_str), limit=0)
for date_str in ("NOW - 1HOUR", "NOW - 1HOURS", "NOW-1 HOURS", "NOW-1", "NOW-", "**", "+", "-"):
with pytest.raises(ValueError):
format_query_date(date_str)
with pytest.raises(SentinelAPIError):
api.query(raw='ingestiondate:[{} TO *]'.format(date_str), limit=0)
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 == ""
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 == ''
assert format_query_date(date(2015, 1, 1)) == '2015-01-01T00:00:00Z'
assert format_query_date('2015-01-01T00:00:00Z') == '2015-01-01T00:00:00Z'
assert format_query_date('20150101') == '2015-01-01T00:00:00Z'
assert format_query_date(' NOW ') == 'NOW'
assert format_query_date(None) == '*'
for date_str in ("NOW", "NOW-1DAY", "NOW-1DAYS", "NOW-500DAY", "NOW-500DAYS",
"NOW-2MONTH", "NOW-2MONTHS", "NOW-20MINUTE", "NOW-20MINUTES",
"NOW+10HOUR", "2015-01-01T00:00:00Z+1DAY", "NOW+3MONTHS-7DAYS/DAYS",
"*"):
assert format_query_date(date_str) == date_str
api.query(raw='ingestiondate:[{} TO *]'.format(date_str), limit=0)
for date_str in ("NOW - 1HOUR", "NOW - 1HOURS", "NOW-1 HOURS", "NOW-1", "NOW-", "**", "+", "-"):
with pytest.raises(ValueError):
format_query_date(date_str)
with pytest.raises(SentinelAPIError):
api.query(raw='ingestiondate:[{} TO *]'.format(date_str), limit=0)
def test_format_date(api):
assert format_query_date(datetime(2015, 1, 1)) == "2015-01-01T00:00:00Z"
assert format_query_date(date(2015, 1, 1)) == "2015-01-01T00:00:00Z"
assert format_query_date("2015-01-01T00:00:00Z") == "2015-01-01T00:00:00Z"
assert format_query_date("20150101") == "2015-01-01T00:00:00Z"
assert format_query_date(" NOW ") == "NOW"
assert format_query_date(None) == "*"
for date_str in (
"NOW",
"NOW-1DAY",
"NOW-1DAYS",
"NOW-500DAY",
"NOW-500DAYS",
"NOW-2MONTH",
"NOW-2MONTHS",
"NOW-20MINUTE",
"NOW-20MINUTES",
"NOW+10HOUR",
def test_format_date(api):
assert format_query_date(datetime(2015, 1, 1)) == '2015-01-01T00:00:00Z'
assert format_query_date(date(2015, 1, 1)) == '2015-01-01T00:00:00Z'
assert format_query_date('2015-01-01T00:00:00Z') == '2015-01-01T00:00:00Z'
assert format_query_date('20150101') == '2015-01-01T00:00:00Z'
assert format_query_date(' NOW ') == 'NOW'
assert format_query_date(None) == '*'
for date_str in ("NOW", "NOW-1DAY", "NOW-1DAYS", "NOW-500DAY", "NOW-500DAYS",
"NOW-2MONTH", "NOW-2MONTHS", "NOW-20MINUTE", "NOW-20MINUTES",
"NOW+10HOUR", "2015-01-01T00:00:00Z+1DAY", "NOW+3MONTHS-7DAYS/DAYS",
"*"):
assert format_query_date(date_str) == date_str
api.query(raw='ingestiondate:[{} TO *]'.format(date_str), limit=0)
for date_str in ("NOW - 1HOUR", "NOW - 1HOURS", "NOW-1 HOURS", "NOW-1", "NOW-", "**", "+", "-"):
with pytest.raises(ValueError):
format_query_date(date_str)
with pytest.raises(SentinelAPIError):
api.query(raw='ingestiondate:[{} TO *]'.format(date_str), limit=0)
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)))"'
def test_format_date(api):
assert format_query_date(datetime(2015, 1, 1)) == "2015-01-01T00:00:00Z"
assert format_query_date(date(2015, 1, 1)) == "2015-01-01T00:00:00Z"
assert format_query_date("2015-01-01T00:00:00Z") == "2015-01-01T00:00:00Z"
assert format_query_date("20150101") == "2015-01-01T00:00:00Z"
assert format_query_date(" NOW ") == "NOW"
assert format_query_date(None) == "*"
for date_str in (
"NOW",
"NOW-1DAY",
"NOW-1DAYS",
"NOW-500DAY",
"NOW-500DAYS",
"NOW-2MONTH",
"NOW-2MONTHS",
"NOW-20MINUTE",
"NOW-20MINUTES",
"NOW+10HOUR",
"2015-01-01T00:00:00Z+1DAY",