Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# Test whether our limit calculation is reasonably correct and
# that a relevant error message is provided
def create_query(n):
return " a_-.*:,?+~!" * n
# Expect no error
q = create_query(163)
assert 0.99 < SentinelAPI.check_query_length(q) < 1.0
with pytest.raises(SentinelAPIError) as excinfo:
api.count(raw=q)
assert "Invalid query string" in excinfo.value.msg
# Expect HTTP status 500 Internal Server Error
q = create_query(164)
assert 0.999 <= SentinelAPI.check_query_length(q) < 1.01
with pytest.raises(SentinelAPIError) as excinfo:
api.count(raw=q)
assert excinfo.value.response.status_code == 500
assert ("Request Entity Too Large" in excinfo.value.msg or
"Request-URI Too Long" in excinfo.value.msg)
def test_too_long_query(api):
# Test whether our limit calculation is reasonably correct and
# that a relevant error message is provided
def create_query(n):
return " a_-.*:,?+~!" * n
# Expect no error
q = create_query(163)
assert 0.99 < SentinelAPI.check_query_length(q) < 1.0
with pytest.raises(SentinelAPIError) as excinfo:
api.count(raw=q)
assert "Invalid query string" in excinfo.value.msg
# Expect HTTP status 500 Internal Server Error
q = create_query(164)
assert 0.999 <= SentinelAPI.check_query_length(q) < 1.01
with pytest.raises(SentinelAPIError) as excinfo:
api.count(raw=q)
assert excinfo.value.response.status_code == 500
assert (
"Request Entity Too Large" in excinfo.value.msg
or "Request-URI Too Long" in excinfo.value.msg
)