How to use the sentinelsat.SentinelAPI.check_query_length function in sentinelsat

To help you get started, we’ve selected a few sentinelsat examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sentinelsat / sentinelsat / tests / test_mod.py View on Github external
# 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)
github sentinelsat / sentinelsat / tests / test_opensearch.py View on Github external
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
    )