def test_tiles_expr(expression, cogeo, event): """Should work as expected (get tile).""" tilesize = 256 tile = numpy.random.rand(1, tilesize, tilesize) mask = numpy.full((tilesize, tilesize), 255) expression.return_value = (tile, mask) event["path"] = "/tiles/19/319379/270522.png" event["httpMethod"] = "GET" event["queryStringParameters"] = { "url": "https://a-totally-fake-url.fake/my.tif", "expr": "(b1-b2)/(b1+b2)", "rescale": "-1,1", "color_map": "cfastie", } headers = { "Access-Control-Allow-Credentials": "true", "Access-Control-Allow-Methods": "GET", "Access-Control-Allow-Origin": "*", "Cache-Control": "max-age=3600", "Content-Type": "image/png", } statusCode = 200 res = APP(event, {}) assert res["headers"] == headers assert res["statusCode"] == statusCode assert res["isBase64Encoded"] assert res["body"] cogeo.assert_not_called() event["path"] = "/tiles/19/319379/270522.png" event["httpMethod"] = "GET" event["queryStringParameters"] = { "url": "https://a-totally-fake-url.fake/my.tif", "expr": "(b1-b2)/(b1+b1)", "rescale": "-1,1", "color_map": "cfastie", } event["headers"]["Accept-Encoding"] = "gzip, deflate" headers = { "Access-Control-Allow-Credentials": "true", "Access-Control-Allow-Methods": "GET", "Access-Control-Allow-Origin": "*", "Content-Encoding": "gzip", "Cache-Control": "max-age=3600", "Content-Type": "image/png", } statusCode = 200 res = APP(event, {}) assert res["headers"] == headers assert res["statusCode"] == statusCode assert res["isBase64Encoded"] assert res["body"] cogeo.assert_not_called()
def test_bounds(cogeo, event): """Should work as expected (get bounds).""" cogeo.bounds.return_value = { "url": "https://a-totally-fake-url.fake/my.tif", "bounds": [ 39.28650720617372, -5.770217424643658, 39.313619221090086, -5.743046418788738, ], } event["path"] = "/bounds" event["httpMethod"] = "GET" event["queryStringParameters"] = {"url": "https://a-totally-fake-url.fake/my.tif"} headers = { "Access-Control-Allow-Credentials": "true", "Access-Control-Allow-Methods": "GET", "Access-Control-Allow-Origin": "*", "Cache-Control": "max-age=3600", "Content-Type": "application/json", } statusCode = 200 res = APP(event, {}) assert res["headers"] == headers assert res["statusCode"] == statusCode result = json.loads(res["body"]) assert result["bounds"]
def test_tiles_bands(expression, cogeo, event): """Should work as expected (get tile).""" tilesize = 256 tile = numpy.random.rand(3, tilesize, tilesize) * 1000 mask = numpy.full((tilesize, tilesize), 255) cogeo.tile.return_value = (tile.astype(numpy.uint8), mask) event["path"] = "/tiles/19/319379/270522.png" event["httpMethod"] = "GET" event["queryStringParameters"] = { "indexes": "1,2,3", "url": "https://a-totally-fake-url.fake/my.tif", } event["headers"]["Accept-Encoding"] = "gzip, deflate" headers = { "Access-Control-Allow-Credentials": "true", "Access-Control-Allow-Methods": "GET", "Access-Control-Allow-Origin": "*", "Content-Encoding": "gzip", "Cache-Control": "max-age=3600", "Content-Type": "image/png", } statusCode = 200 res = APP(event, {}) assert res["headers"] == headers assert res["statusCode"] == statusCode assert res["isBase64Encoded"] assert res["body"] expression.assert_not_called()
def test_metadata(cogeo, event): """Should work as expected (get metadata).""" cogeo.metadata.return_value = metadata_results event["path"] = "/metadata" event["httpMethod"] = "GET" event["queryStringParameters"] = { "url": "https://a-totally-fake-url.fake/my.tif" } headers = { "Access-Control-Allow-Credentials": "true", "Access-Control-Allow-Methods": "GET", "Access-Control-Allow-Origin": "*", "Content-Type": "application/json", } statusCode = 200 res = APP(event, {}) assert res["headers"] == headers assert res["statusCode"] == statusCode result = json.loads(res["body"]) assert result["bounds"] assert result["statistics"] assert len(result["statistics"].keys()) == 3
def test_tiles_error(cogeo, event): """Should work as expected (raise errors).""" event["path"] = "/tiles/19/319379/270522.png" event["httpMethod"] = "GET" event["queryStringParameters"] = { "indexes": "1", "expr": "1", "url": "https://a-totally-fake-url.fake/my.tif", } headers = { "Access-Control-Allow-Credentials": "true", "Access-Control-Allow-Methods": "GET", "Access-Control-Allow-Origin": "*", "Cache-Control": "no-cache", "Content-Type": "application/json", } statusCode = 500 res = APP(event, {}) assert res["headers"] == headers assert res["statusCode"] == statusCode result = json.loads(res["body"]) assert result["errorMessage"] == "Cannot pass indexes and expression" cogeo.assert_not_called() event["path"] = "/tiles/19/319379/270522.png" event["httpMethod"] = "GET" event["queryStringParameters"] = {} headers = { "Access-Control-Allow-Credentials": "true", "Access-Control-Allow-Methods": "GET", "Access-Control-Allow-Origin": "*", "Cache-Control": "no-cache", "Content-Type": "application/json", } statusCode = 500 res = APP(event, {}) assert res["headers"] == headers assert res["statusCode"] == statusCode result = json.loads(res["body"]) assert result["errorMessage"] == "Missing 'url' parameter" cogeo.assert_not_called()
def test_noUrl(cogeo, event): """Should work as expected (get bounds).""" event["path"] = "/bounds" event["httpMethod"] = "GET" event["queryStringParameters"] = {} headers = { "Access-Control-Allow-Credentials": "true", "Access-Control-Allow-Methods": "GET", "Access-Control-Allow-Origin": "*", "Cache-Control": "no-cache", "Content-Type": "application/json", } statusCode = 500 res = APP(event, {}) assert res["headers"] == headers assert res["statusCode"] == statusCode