From ea66c4f2975e466361c73dda9a552bcd894689cb Mon Sep 17 00:00:00 2001 From: Zoe Statman-Weil Date: Tue, 4 Jan 2022 10:26:21 -0800 Subject: [PATCH 1/8] updated gitignore --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 3947546d4..2fd055e74 100644 --- a/.gitignore +++ b/.gitignore @@ -35,6 +35,7 @@ tests/logging.ini # Distribution / packaging .Python env/ +venv/ build/ develop-eggs/ dist/ @@ -106,7 +107,7 @@ celerybeat-schedule *.sage.py # dotenv -.env +../pgstac/.env # Spyder project settings .spyderproject From 1d38c5d7d9b733c8b4b081b012d51b7bacde194f Mon Sep 17 00:00:00 2001 From: Zoe Statman-Weil Date: Mon, 10 Jan 2022 16:04:57 -0800 Subject: [PATCH 2/8] added new test item --- .../pgstac/tests/data/test_item2.json | 646 ++++++++++++++++++ 1 file changed, 646 insertions(+) create mode 100644 stac_fastapi/pgstac/tests/data/test_item2.json diff --git a/stac_fastapi/pgstac/tests/data/test_item2.json b/stac_fastapi/pgstac/tests/data/test_item2.json new file mode 100644 index 000000000..0d8ec7630 --- /dev/null +++ b/stac_fastapi/pgstac/tests/data/test_item2.json @@ -0,0 +1,646 @@ +{ + "type": "Feature", + "id": "test_item2", + "stac_version": "1.0.0", + "stac_extensions": [ + "https://stac-extensions.github.io/eo/v1.0.0/schema.json", + "https://stac-extensions.github.io/projection/v1.0.0/schema.json" + ], + "bbox": [ + -123.37257493384075, + 46.35430508465464, + -120.21745704411174, + 48.51504491534536 + ], + "links": [ + { + "rel": "collection", + "type": "application/json", + "href": "http://localhost:8081/api/stac/v1/collections/landsat-8-c2-l2" + }, + { + "rel": "parent", + "type": "application/json", + "href": "http://localhost:8081/api/stac/v1/collections/landsat-8-c2-l2" + }, + { + "rel": "root", + "type": "application/json", + "href": "http://localhost:8081/api/stac/v1/" + }, + { + "rel": "self", + "type": "application/geo+json", + "href": "http://localhost:8081/api/stac/v1/collections/landsat-8-c2-l2/items/LC08_L2SP_046027_20200908_02_T1" + }, + { + "rel": "alternate", + "type": "application/json", + "title": "tiles", + "href": "http://localhost:8081/api/stac/v1/collections/landsat-8-c2-l2/items/LC08_L2SP_046027_20200908_02_T1/tiles" + }, + { + "rel": "alternate", + "href": "https://landsatlook.usgs.gov/stac-browser/collection02/level-2/standard/oli-tirs/2020/046/027/LC08_L2SP_046027_20200908_02_T1", + "type": "text/html", + "title": "USGS stac-browser page" + }, + { + "rel": "preview", + "href": "http://localhost:8081/api/data/v1/item/map?collection=landsat-8-c2-l2&item=LC08_L2SP_046027_20200908_02_T1", + "title": "Map of item", + "type": "text/html" + } + ], + "assets": { + "ANG": { + "href": "https://landsateuwest.blob.core.windows.net/landsat-c2/level-2/standard/oli-tirs/2020/046/027/LC08_L2SP_046027_20200908_20200919_02_T1/LC08_L2SP_046027_20200908_20200919_02_T1_ANG.txt", + "type": "text/plain", + "title": "Angle Coefficients File", + "description": "Collection 2 Level-1 Angle Coefficients File (ANG)" + }, + "SR_B1": { + "gsd": 30, + "href": "https://landsateuwest.blob.core.windows.net/landsat-c2/level-2/standard/oli-tirs/2020/046/027/LC08_L2SP_046027_20200908_20200919_02_T1/LC08_L2SP_046027_20200908_20200919_02_T1_SR_B1.TIF", + "type": "image/tiff; application=geotiff; profile=cloud-optimized", + "title": "Coastal/Aerosol Band (B1)", + "eo:bands": [ + { + "gsd": 30, + "name": "SR_B1", + "common_name": "coastal", + "center_wavelength": 0.44, + "full_width_half_max": 0.02 + } + ], + "proj:shape": [ + 7891, + 7771 + ], + "description": "Collection 2 Level-2 Coastal/Aerosol Band (B1) Surface Reflectance", + "proj:transform": [ + 30, + 0, + 472485, + 0, + -30, + 5373615 + ] + }, + "SR_B2": { + "gsd": 30, + "href": "https://landsateuwest.blob.core.windows.net/landsat-c2/level-2/standard/oli-tirs/2020/046/027/LC08_L2SP_046027_20200908_20200919_02_T1/LC08_L2SP_046027_20200908_20200919_02_T1_SR_B2.TIF", + "type": "image/tiff; application=geotiff; profile=cloud-optimized", + "title": "Blue Band (B2)", + "eo:bands": [ + { + "gsd": 30, + "name": "SR_B2", + "common_name": "blue", + "center_wavelength": 0.48, + "full_width_half_max": 0.06 + } + ], + "proj:shape": [ + 7891, + 7771 + ], + "description": "Collection 2 Level-2 Blue Band (B2) Surface Reflectance", + "proj:transform": [ + 30, + 0, + 472485, + 0, + -30, + 5373615 + ] + }, + "SR_B3": { + "gsd": 30, + "href": "https://landsateuwest.blob.core.windows.net/landsat-c2/level-2/standard/oli-tirs/2020/046/027/LC08_L2SP_046027_20200908_20200919_02_T1/LC08_L2SP_046027_20200908_20200919_02_T1_SR_B3.TIF", + "type": "image/tiff; application=geotiff; profile=cloud-optimized", + "title": "Green Band (B3)", + "eo:bands": [ + { + "gsd": 30, + "name": "SR_B3", + "common_name": "green", + "center_wavelength": 0.56, + "full_width_half_max": 0.06 + } + ], + "proj:shape": [ + 7891, + 7771 + ], + "description": "Collection 2 Level-2 Green Band (B3) Surface Reflectance", + "proj:transform": [ + 30, + 0, + 472485, + 0, + -30, + 5373615 + ] + }, + "SR_B4": { + "gsd": 30, + "href": "https://landsateuwest.blob.core.windows.net/landsat-c2/level-2/standard/oli-tirs/2020/046/027/LC08_L2SP_046027_20200908_20200919_02_T1/LC08_L2SP_046027_20200908_20200919_02_T1_SR_B4.TIF", + "type": "image/tiff; application=geotiff; profile=cloud-optimized", + "title": "Red Band (B4)", + "eo:bands": [ + { + "gsd": 30, + "name": "SR_B4", + "common_name": "red", + "center_wavelength": 0.65, + "full_width_half_max": 0.04 + } + ], + "proj:shape": [ + 7891, + 7771 + ], + "description": "Collection 2 Level-2 Red Band (B4) Surface Reflectance", + "proj:transform": [ + 30, + 0, + 472485, + 0, + -30, + 5373615 + ] + }, + "SR_B5": { + "gsd": 30, + "href": "https://landsateuwest.blob.core.windows.net/landsat-c2/level-2/standard/oli-tirs/2020/046/027/LC08_L2SP_046027_20200908_20200919_02_T1/LC08_L2SP_046027_20200908_20200919_02_T1_SR_B5.TIF", + "type": "image/tiff; application=geotiff; profile=cloud-optimized", + "title": "Near Infrared Band 0.8 (B5)", + "eo:bands": [ + { + "gsd": 30, + "name": "SR_B5", + "common_name": "nir08", + "center_wavelength": 0.86, + "full_width_half_max": 0.03 + } + ], + "proj:shape": [ + 7891, + 7771 + ], + "description": "Collection 2 Level-2 Near Infrared Band 0.8 (B5) Surface Reflectance", + "proj:transform": [ + 30, + 0, + 472485, + 0, + -30, + 5373615 + ] + }, + "SR_B6": { + "gsd": 30, + "href": "https://landsateuwest.blob.core.windows.net/landsat-c2/level-2/standard/oli-tirs/2020/046/027/LC08_L2SP_046027_20200908_20200919_02_T1/LC08_L2SP_046027_20200908_20200919_02_T1_SR_B6.TIF", + "type": "image/tiff; application=geotiff; profile=cloud-optimized", + "title": "Short-wave Infrared Band 1.6 (B6)", + "eo:bands": [ + { + "gsd": 30, + "name": "SR_B6", + "common_name": "swir16", + "center_wavelength": 1.6, + "full_width_half_max": 0.08 + } + ], + "proj:shape": [ + 7891, + 7771 + ], + "description": "Collection 2 Level-2 Short-wave Infrared Band 1.6 (B6) Surface Reflectance", + "proj:transform": [ + 30, + 0, + 472485, + 0, + -30, + 5373615 + ] + }, + "SR_B7": { + "gsd": 30, + "href": "https://landsateuwest.blob.core.windows.net/landsat-c2/level-2/standard/oli-tirs/2020/046/027/LC08_L2SP_046027_20200908_20200919_02_T1/LC08_L2SP_046027_20200908_20200919_02_T1_SR_B7.TIF", + "type": "image/tiff; application=geotiff; profile=cloud-optimized", + "title": "Short-wave Infrared Band 2.2 (B7)", + "eo:bands": [ + { + "gsd": 30, + "name": "SR_B7", + "common_name": "swir22", + "center_wavelength": 2.2, + "full_width_half_max": 0.2 + } + ], + "proj:shape": [ + 7891, + 7771 + ], + "description": "Collection 2 Level-2 Short-wave Infrared Band 2.2 (B7) Surface Reflectance", + "proj:transform": [ + 30, + 0, + 472485, + 0, + -30, + 5373615 + ] + }, + "ST_QA": { + "gsd": 30, + "href": "https://landsateuwest.blob.core.windows.net/landsat-c2/level-2/standard/oli-tirs/2020/046/027/LC08_L2SP_046027_20200908_20200919_02_T1/LC08_L2SP_046027_20200908_20200919_02_T1_ST_QA.TIF", + "type": "image/tiff; application=geotiff; profile=cloud-optimized", + "title": "Surface Temperature Quality Assessment Band", + "proj:shape": [ + 7891, + 7771 + ], + "description": "Landsat Collection 2 Level-2 Surface Temperature Band Surface Temperature Product", + "proj:transform": [ + 30, + 0, + 472485, + 0, + -30, + 5373615 + ] + }, + "ST_B10": { + "gsd": 100, + "href": "https://landsateuwest.blob.core.windows.net/landsat-c2/level-2/standard/oli-tirs/2020/046/027/LC08_L2SP_046027_20200908_20200919_02_T1/LC08_L2SP_046027_20200908_20200919_02_T1_ST_B10.TIF", + "type": "image/tiff; application=geotiff; profile=cloud-optimized", + "title": "Surface Temperature Band (B10)", + "eo:bands": [ + { + "gsd": 100, + "name": "ST_B10", + "common_name": "lwir11", + "center_wavelength": 10.9, + "full_width_half_max": 0.8 + } + ], + "proj:shape": [ + 7891, + 7771 + ], + "description": "Landsat Collection 2 Level-2 Surface Temperature Band (B10) Surface Temperature Product", + "proj:transform": [ + 30, + 0, + 472485, + 0, + -30, + 5373615 + ] + }, + "MTL.txt": { + "href": "https://landsateuwest.blob.core.windows.net/landsat-c2/level-2/standard/oli-tirs/2020/046/027/LC08_L2SP_046027_20200908_20200919_02_T1/LC08_L2SP_046027_20200908_20200919_02_T1_MTL.txt", + "type": "text/plain", + "title": "Product Metadata File", + "description": "Collection 2 Level-1 Product Metadata File (MTL)" + }, + "MTL.xml": { + "href": "https://landsateuwest.blob.core.windows.net/landsat-c2/level-2/standard/oli-tirs/2020/046/027/LC08_L2SP_046027_20200908_20200919_02_T1/LC08_L2SP_046027_20200908_20200919_02_T1_MTL.xml", + "type": "application/xml", + "title": "Product Metadata File (xml)", + "description": "Collection 2 Level-1 Product Metadata File (xml)" + }, + "ST_DRAD": { + "gsd": 30, + "href": "https://landsateuwest.blob.core.windows.net/landsat-c2/level-2/standard/oli-tirs/2020/046/027/LC08_L2SP_046027_20200908_20200919_02_T1/LC08_L2SP_046027_20200908_20200919_02_T1_ST_DRAD.TIF", + "type": "image/tiff; application=geotiff; profile=cloud-optimized", + "title": "Downwelled Radiance Band", + "eo:bands": [ + { + "gsd": 30, + "name": "ST_DRAD", + "description": "downwelled radiance" + } + ], + "proj:shape": [ + 7891, + 7771 + ], + "description": "Landsat Collection 2 Level-2 Downwelled Radiance Band Surface Temperature Product", + "proj:transform": [ + 30, + 0, + 472485, + 0, + -30, + 5373615 + ] + }, + "ST_EMIS": { + "gsd": 30, + "href": "https://landsateuwest.blob.core.windows.net/landsat-c2/level-2/standard/oli-tirs/2020/046/027/LC08_L2SP_046027_20200908_20200919_02_T1/LC08_L2SP_046027_20200908_20200919_02_T1_ST_EMIS.TIF", + "type": "image/tiff; application=geotiff; profile=cloud-optimized", + "title": "Emissivity Band", + "eo:bands": [ + { + "gsd": 30, + "name": "ST_EMIS", + "description": "emissivity" + } + ], + "proj:shape": [ + 7891, + 7771 + ], + "description": "Landsat Collection 2 Level-2 Emissivity Band Surface Temperature Product", + "proj:transform": [ + 30, + 0, + 472485, + 0, + -30, + 5373615 + ] + }, + "ST_EMSD": { + "gsd": 30, + "href": "https://landsateuwest.blob.core.windows.net/landsat-c2/level-2/standard/oli-tirs/2020/046/027/LC08_L2SP_046027_20200908_20200919_02_T1/LC08_L2SP_046027_20200908_20200919_02_T1_ST_EMSD.TIF", + "type": "image/tiff; application=geotiff; profile=cloud-optimized", + "title": "Emissivity Standard Deviation Band", + "eo:bands": [ + { + "gsd": 30, + "name": "ST_EMSD", + "description": "emissivity standard deviation" + } + ], + "proj:shape": [ + 7891, + 7771 + ], + "description": "Landsat Collection 2 Level-2 Emissivity Standard Deviation Band Surface Temperature Product", + "proj:transform": [ + 30, + 0, + 472485, + 0, + -30, + 5373615 + ] + }, + "ST_TRAD": { + "gsd": 30, + "href": "https://landsateuwest.blob.core.windows.net/landsat-c2/level-2/standard/oli-tirs/2020/046/027/LC08_L2SP_046027_20200908_20200919_02_T1/LC08_L2SP_046027_20200908_20200919_02_T1_ST_TRAD.TIF", + "type": "image/tiff; application=geotiff; profile=cloud-optimized", + "title": "Thermal Radiance Band", + "eo:bands": [ + { + "gsd": 30, + "name": "ST_TRAD", + "description": "thermal radiance" + } + ], + "proj:shape": [ + 7891, + 7771 + ], + "description": "Landsat Collection 2 Level-2 Thermal Radiance Band Surface Temperature Product", + "proj:transform": [ + 30, + 0, + 472485, + 0, + -30, + 5373615 + ] + }, + "ST_URAD": { + "gsd": 30, + "href": "https://landsateuwest.blob.core.windows.net/landsat-c2/level-2/standard/oli-tirs/2020/046/027/LC08_L2SP_046027_20200908_20200919_02_T1/LC08_L2SP_046027_20200908_20200919_02_T1_ST_URAD.TIF", + "type": "image/tiff; application=geotiff; profile=cloud-optimized", + "title": "Upwelled Radiance Band", + "eo:bands": [ + { + "gsd": 30, + "name": "ST_URAD", + "description": "upwelled radiance" + } + ], + "proj:shape": [ + 7891, + 7771 + ], + "description": "Landsat Collection 2 Level-2 Upwelled Radiance Band Surface Temperature Product", + "proj:transform": [ + 30, + 0, + 472485, + 0, + -30, + 5373615 + ] + }, + "MTL.json": { + "href": "https://landsateuwest.blob.core.windows.net/landsat-c2/level-2/standard/oli-tirs/2020/046/027/LC08_L2SP_046027_20200908_20200919_02_T1/LC08_L2SP_046027_20200908_20200919_02_T1_MTL.json", + "type": "application/json", + "title": "Product Metadata File (json)", + "description": "Collection 2 Level-1 Product Metadata File (json)" + }, + "QA_PIXEL": { + "gsd": 30, + "href": "https://landsateuwest.blob.core.windows.net/landsat-c2/level-2/standard/oli-tirs/2020/046/027/LC08_L2SP_046027_20200908_20200919_02_T1/LC08_L2SP_046027_20200908_20200919_02_T1_QA_PIXEL.TIF", + "type": "image/tiff; application=geotiff; profile=cloud-optimized", + "title": "Pixel Quality Assessment Band", + "proj:shape": [ + 7891, + 7771 + ], + "description": "Collection 2 Level-1 Pixel Quality Assessment Band", + "proj:transform": [ + 30, + 0, + 472485, + 0, + -30, + 5373615 + ] + }, + "ST_ATRAN": { + "gsd": 30, + "href": "https://landsateuwest.blob.core.windows.net/landsat-c2/level-2/standard/oli-tirs/2020/046/027/LC08_L2SP_046027_20200908_20200919_02_T1/LC08_L2SP_046027_20200908_20200919_02_T1_ST_ATRAN.TIF", + "type": "image/tiff; application=geotiff; profile=cloud-optimized", + "title": "Atmospheric Transmittance Band", + "eo:bands": [ + { + "gsd": 30, + "name": "ST_ATRAN", + "description": "atmospheric transmission" + } + ], + "proj:shape": [ + 7891, + 7771 + ], + "description": "Landsat Collection 2 Level-2 Atmospheric Transmittance Band Surface Temperature Product", + "proj:transform": [ + 30, + 0, + 472485, + 0, + -30, + 5373615 + ] + }, + "ST_CDIST": { + "gsd": 30, + "href": "https://landsateuwest.blob.core.windows.net/landsat-c2/level-2/standard/oli-tirs/2020/046/027/LC08_L2SP_046027_20200908_20200919_02_T1/LC08_L2SP_046027_20200908_20200919_02_T1_ST_CDIST.TIF", + "type": "image/tiff; application=geotiff; profile=cloud-optimized", + "title": "Cloud Distance Band", + "eo:bands": [ + { + "gsd": 30, + "name": "ST_CDIST", + "description": "distance to nearest cloud" + } + ], + "proj:shape": [ + 7891, + 7771 + ], + "description": "Landsat Collection 2 Level-2 Cloud Distance Band Surface Temperature Product", + "proj:transform": [ + 30, + 0, + 472485, + 0, + -30, + 5373615 + ] + }, + "QA_RADSAT": { + "gsd": 30, + "href": "https://landsateuwest.blob.core.windows.net/landsat-c2/level-2/standard/oli-tirs/2020/046/027/LC08_L2SP_046027_20200908_20200919_02_T1/LC08_L2SP_046027_20200908_20200919_02_T1_QA_RADSAT.TIF", + "type": "image/tiff; application=geotiff; profile=cloud-optimized", + "title": "Radiometric Saturation Quality Assessment Band", + "proj:shape": [ + 7891, + 7771 + ], + "description": "Collection 2 Level-1 Radiometric Saturation Quality Assessment Band", + "proj:transform": [ + 30, + 0, + 472485, + 0, + -30, + 5373615 + ] + }, + "thumbnail": { + "href": "https://landsateuwest.blob.core.windows.net/landsat-c2/level-2/standard/oli-tirs/2020/046/027/LC08_L2SP_046027_20200908_20200919_02_T1/LC08_L2SP_046027_20200908_20200919_02_T1_thumb_small.jpeg", + "type": "image/jpeg", + "title": "Thumbnail image" + }, + "SR_QA_AEROSOL": { + "gsd": 30, + "href": "https://landsateuwest.blob.core.windows.net/landsat-c2/level-2/standard/oli-tirs/2020/046/027/LC08_L2SP_046027_20200908_20200919_02_T1/LC08_L2SP_046027_20200908_20200919_02_T1_SR_QA_AEROSOL.TIF", + "type": "image/tiff; application=geotiff; profile=cloud-optimized", + "title": "Aerosol Quality Analysis Band", + "proj:shape": [ + 7891, + 7771 + ], + "description": "Collection 2 Level-2 Aerosol Quality Analysis Band (ANG) Surface Reflectance", + "proj:transform": [ + 30, + 0, + 472485, + 0, + -30, + 5373615 + ] + }, + "reduced_resolution_browse": { + "href": "https://landsateuwest.blob.core.windows.net/landsat-c2/level-2/standard/oli-tirs/2020/046/027/LC08_L2SP_046027_20200908_20200919_02_T1/LC08_L2SP_046027_20200908_20200919_02_T1_thumb_large.jpeg", + "type": "image/jpeg", + "title": "Reduced resolution browse image" + }, + "tilejson": { + "title": "TileJSON with default rendering", + "href": "https://planetarycomputer.microsoft.com/api/data/v1/item/tilejson.json?collection=landsat-8-c2-l2&items=LC08_L2SP_046027_20200908_02_T1&assets=SR_B4,SR_B3,SR_B2&color_formula=gamma+RGB+2.7%2C+saturation+1.5%2C+sigmoidal+RGB+15+0.55", + "type": "application/json", + "roles": [ + "tiles" + ] + }, + "rendered_preview": { + "title": "Rendered preview", + "rel": "preview", + "href": "https://planetarycomputer.microsoft.com/api/data/v1/item/preview.png?collection=landsat-8-c2-l2&items=LC08_L2SP_046027_20200908_02_T1&assets=SR_B4,SR_B3,SR_B2&color_formula=gamma+RGB+2.7%2C+saturation+1.5%2C+sigmoidal+RGB+15+0.55", + "roles": [ + "overview" + ], + "type": "image/png" + } + }, + "geometry": { + "type": "Polygon", + "coordinates": [ + [ + [ + -122.73659863, + 48.512551 + ], + [ + -120.21828301, + 48.09736515 + ], + [ + -120.85665503, + 46.35688928 + ], + [ + -123.37063967, + 46.78158223 + ], + [ + -122.73659863, + 48.512551 + ] + ] + ] + }, + "collection": "test-collection", + "properties": { + "datetime": "2020-09-08T18:55:51.575595Z", + "platform": "landsat-8", + "proj:bbox": [ + 472485, + 5136885, + 705615, + 5373615 + ], + "proj:epsg": 32610, + "description": "Landsat Collection 2 Level-2 Surface Reflectance Product", + "instruments": [ + "oli", + "tirs" + ], + "eo:cloud_cover": 0.19, + "view:off_nadir": 0, + "landsat:wrs_row": "027", + "landsat:scene_id": "LC80460272020252LGN00", + "landsat:wrs_path": "046", + "landsat:wrs_type": "2", + "view:sun_azimuth": 155.2327918, + "view:sun_elevation": 45.33819766, + "landsat:cloud_cover_land": 0.21, + "landsat:processing_level": "L2SP", + "landsat:collection_number": "02", + "landsat:collection_category": "T1" + } +} \ No newline at end of file From d067f205027b8ab34004d2db59014989865df1ae Mon Sep 17 00:00:00 2001 From: Zoe Statman-Weil Date: Mon, 10 Jan 2022 16:05:17 -0800 Subject: [PATCH 3/8] added second item to tests --- .../pgstac/tests/resources/test_item.py | 88 ++++++++++++++++++- 1 file changed, 87 insertions(+), 1 deletion(-) diff --git a/stac_fastapi/pgstac/tests/resources/test_item.py b/stac_fastapi/pgstac/tests/resources/test_item.py index baa8b2b82..addbea97f 100644 --- a/stac_fastapi/pgstac/tests/resources/test_item.py +++ b/stac_fastapi/pgstac/tests/resources/test_item.py @@ -366,6 +366,13 @@ async def test_item_search_spatial_query_post( ) assert resp.status_code == 200 + # Add second item with a different datetime. + second_test_item = load_test_data("test_item2.json") + resp = await app_client.post( + f"/collections/{test_item['collection']}/items", json=second_test_item + ) + assert resp.status_code == 200 + params = { "collections": [test_item["collection"]], "intersects": test_item["geometry"], @@ -373,6 +380,7 @@ async def test_item_search_spatial_query_post( resp = await app_client.post("/search", json=params) assert resp.status_code == 200 resp_json = resp.json() + assert len(resp_json["features"]) == 1 assert resp_json["features"][0]["id"] == test_item["id"] @@ -387,6 +395,13 @@ async def test_item_search_temporal_query_post( ) assert resp.status_code == 200 + # Add second item with a different datetime. + second_test_item = load_test_data("test_item2.json") + resp = await app_client.post( + f"/collections/{test_item['collection']}/items", json=second_test_item + ) + assert resp.status_code == 200 + item_date = datetime.strptime(test_item["properties"]["datetime"], DATETIME_RFC339) print(item_date) item_date = item_date + timedelta(seconds=1) @@ -400,6 +415,7 @@ async def test_item_search_temporal_query_post( resp = await app_client.post("/search", json=params) print(resp.content) resp_json = resp.json() + assert len(resp_json["features"]) == 1 assert resp_json["features"][0]["id"] == test_item["id"] @@ -414,6 +430,13 @@ async def test_item_search_temporal_window_post( ) assert resp.status_code == 200 + # Add second item with a different datetime. + second_test_item = load_test_data("test_item2.json") + resp = await app_client.post( + f"/collections/{test_item['collection']}/items", json=second_test_item + ) + assert resp.status_code == 200 + item_date = datetime.strptime(test_item["properties"]["datetime"], DATETIME_RFC339) item_date_before = item_date - timedelta(seconds=1) item_date_after = item_date + timedelta(seconds=1) @@ -425,6 +448,7 @@ async def test_item_search_temporal_window_post( } resp = await app_client.post("/search", json=params) resp_json = resp.json() + assert len(resp_json["features"]) == 1 assert resp_json["features"][0]["id"] == test_item["id"] @@ -439,6 +463,13 @@ async def test_item_search_temporal_open_window( ) assert resp.status_code == 200 + # Add second item with a different datetime. + second_test_item = load_test_data("test_item2.json") + resp = await app_client.post( + f"/collections/{test_item['collection']}/items", json=second_test_item + ) + assert resp.status_code == 200 + params = { "collections": [test_item["collection"]], "intersects": test_item["geometry"], @@ -446,6 +477,7 @@ async def test_item_search_temporal_open_window( } resp = await app_client.post("/search", json=params) resp_json = resp.json() + assert len(resp_json["features"]) == 1 assert resp_json["features"][0]["id"] == test_item["id"] @@ -508,6 +540,13 @@ async def test_item_search_bbox_get(app_client, load_test_data, load_test_collec ) assert resp.status_code == 200 + # Add second item with a different datetime. + second_test_item = load_test_data("test_item2.json") + resp = await app_client.post( + f"/collections/{test_item['collection']}/items", json=second_test_item + ) + assert resp.status_code == 200 + params = { "collections": test_item["collection"], "bbox": ",".join([str(coord) for coord in test_item["bbox"]]), @@ -515,6 +554,7 @@ async def test_item_search_bbox_get(app_client, load_test_data, load_test_collec resp = await app_client.get("/search", params=params) assert resp.status_code == 200 resp_json = resp.json() + assert len(resp_json["features"]) == 1 assert resp_json["features"][0]["id"] == test_item["id"] @@ -529,12 +569,20 @@ async def test_item_search_get_without_collections( ) assert resp.status_code == 200 + # Add second item with a different datetime. + second_test_item = load_test_data("test_item2.json") + resp = await app_client.post( + f"/collections/{test_item['collection']}/items", json=second_test_item + ) + assert resp.status_code == 200 + params = { "bbox": ",".join([str(coord) for coord in test_item["bbox"]]), } resp = await app_client.get("/search", params=params) assert resp.status_code == 200 resp_json = resp.json() + assert len(resp_json["features"]) == 1 assert resp_json["features"][0]["id"] == test_item["id"] @@ -549,6 +597,13 @@ async def test_item_search_temporal_window_get( ) assert resp.status_code == 200 + # Add second item with a different datetime. + second_test_item = load_test_data("test_item2.json") + resp = await app_client.post( + f"/collections/{test_item['collection']}/items", json=second_test_item + ) + assert resp.status_code == 200 + item_date = datetime.strptime(test_item["properties"]["datetime"], DATETIME_RFC339) item_date_before = item_date - timedelta(seconds=1) item_date_after = item_date + timedelta(seconds=1) @@ -560,6 +615,7 @@ async def test_item_search_temporal_window_get( } resp = await app_client.get("/search", params=params) resp_json = resp.json() + assert len(resp_json["features"]) == 1 assert resp_json["features"][0]["id"] == test_item["id"] @@ -600,6 +656,12 @@ async def test_item_search_post_without_collection( ) assert resp.status_code == 200 + second_test_item = load_test_data("test_item2.json") + resp = await app_client.post( + f"/collections/{test_item['collection']}/items", json=second_test_item + ) + assert resp.status_code == 200 + params = { "bbox": test_item["bbox"], } @@ -620,6 +682,12 @@ async def test_item_search_properties_jsonb( ) assert resp.status_code == 200 + second_test_item = load_test_data("test_item2.json") + resp = await app_client.post( + f"/collections/{test_item['collection']}/items", json=second_test_item + ) + assert resp.status_code == 200 + # EPSG is a JSONB key params = {"query": {"proj:epsg": {"gt": test_item["properties"]["proj:epsg"] - 1}}} print(params) @@ -640,7 +708,13 @@ async def test_item_search_properties_field( ) assert resp.status_code == 200 - params = {"query": {"platform": {"eq": "landsat-8"}}} + second_test_item = load_test_data("test_item2.json") + resp = await app_client.post( + f"/collections/{test_item['collection']}/items", json=second_test_item + ) + assert resp.status_code == 200 + + params = {"query": {"eo:cloud_cover": {"eq": 0}}} print(params) resp = await app_client.post("/search", json=params) assert resp.status_code == 200 @@ -659,6 +733,12 @@ async def test_item_search_get_query_extension( ) assert resp.status_code == 200 + second_test_item = load_test_data("test_item2.json") + resp = await app_client.post( + f"/collections/{test_item['collection']}/items", json=second_test_item + ) + assert resp.status_code == 200 + # EPSG is a JSONB key params = { "collections": [test_item["collection"]], @@ -694,6 +774,12 @@ async def test_item_search_get_filter_extension_cql( ) assert resp.status_code == 200 + second_test_item = load_test_data("test_item2.json") + resp = await app_client.post( + f"/collections/{test_item['collection']}/items", json=second_test_item + ) + assert resp.status_code == 200 + # EPSG is a JSONB key params = { "collections": [test_item["collection"]], From 5d83c92cffc894099e7d1a891445b7aae78b07fd Mon Sep 17 00:00:00 2001 From: Zoe Statman-Weil Date: Mon, 10 Jan 2022 16:07:09 -0800 Subject: [PATCH 4/8] removed Dict as an option for base get search --- stac_fastapi/types/stac_fastapi/types/search.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stac_fastapi/types/stac_fastapi/types/search.py b/stac_fastapi/types/stac_fastapi/types/search.py index ec1bb9579..b7ca69f40 100644 --- a/stac_fastapi/types/stac_fastapi/types/search.py +++ b/stac_fastapi/types/stac_fastapi/types/search.py @@ -73,7 +73,7 @@ class BaseSearchGetRequest(APIRequest): ids: Optional[str] = attr.ib(default=None, converter=str2list) bbox: Optional[str] = attr.ib(default=None, converter=str2list) intersects: Optional[str] = attr.ib(default=None, converter=str2list) - datetime: Optional[Union[str, Dict]] = attr.ib(default=None) + datetime: Optional[str] = attr.ib(default=None) limit: Optional[int] = attr.ib(default=10) From cfd7a67a072979cdd5cc7cc0c3e1243e295fb5fd Mon Sep 17 00:00:00 2001 From: Zoe Statman-Weil Date: Mon, 10 Jan 2022 16:44:04 -0800 Subject: [PATCH 5/8] simplifies temporal tests so they only address a datetime search --- stac_fastapi/pgstac/tests/resources/test_item.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/stac_fastapi/pgstac/tests/resources/test_item.py b/stac_fastapi/pgstac/tests/resources/test_item.py index addbea97f..0d6bde634 100644 --- a/stac_fastapi/pgstac/tests/resources/test_item.py +++ b/stac_fastapi/pgstac/tests/resources/test_item.py @@ -443,7 +443,6 @@ async def test_item_search_temporal_window_post( params = { "collections": [test_item["collection"]], - "intersects": test_item["geometry"], "datetime": f"{item_date_before.strftime(DATETIME_RFC339)}/{item_date_after.strftime(DATETIME_RFC339)}", } resp = await app_client.post("/search", json=params) @@ -472,13 +471,11 @@ async def test_item_search_temporal_open_window( params = { "collections": [test_item["collection"]], - "intersects": test_item["geometry"], "datetime": "../..", } resp = await app_client.post("/search", json=params) resp_json = resp.json() - assert len(resp_json["features"]) == 1 - assert resp_json["features"][0]["id"] == test_item["id"] + assert len(resp_json["features"]) == 2 @pytest.mark.asyncio @@ -610,7 +607,6 @@ async def test_item_search_temporal_window_get( params = { "collections": test_item["collection"], - "bbox": ",".join([str(coord) for coord in test_item["bbox"]]), "datetime": f"{item_date_before.strftime(DATETIME_RFC339)}/{item_date_after.strftime(DATETIME_RFC339)}", } resp = await app_client.get("/search", params=params) From 7b490ddd9e417fe5528869a9615ca94a9e5fe766 Mon Sep 17 00:00:00 2001 From: Zoe Statman-Weil Date: Mon, 10 Jan 2022 16:50:39 -0800 Subject: [PATCH 6/8] updated change log --- CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 9b7524828..e990b612c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -22,6 +22,8 @@ * The minimum `limit` value for searches is now 1 ([#296](https://github.com/stac-utils/stac-fastapi/pull/296)) * Links stored with Collections and Items (e.g. license links) are now returned with those STAC objects ([#282](https://github.com/stac-utils/stac-fastapi/pull/282)) * Content-type response headers for the /api endpoint now reflect those expected in the STAC api spec ([#287](https://github.com/stac-utils/stac-fastapi/pull/287)) +* Changed type options for datetime in BaseSearchGetRequest ([#315](https://github.com/stac-utils/stac-fastapi/pull/315)) +* Expanded on tests to ensure properly testing get and post searches ([#315](https://github.com/stac-utils/stac-fastapi/pull/315)) ## [2.2.0] From a39386f669ca027b62fb66bbe752561e3e9b0556 Mon Sep 17 00:00:00 2001 From: Zoe Statman-Weil Date: Mon, 10 Jan 2022 16:54:23 -0800 Subject: [PATCH 7/8] modified gitignore --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 08db2f4d4..407d0fe9a 100644 --- a/.gitignore +++ b/.gitignore @@ -107,7 +107,7 @@ celerybeat-schedule *.sage.py # dotenv -../pgstac/.env +**/.env # Spyder project settings .spyderproject From 2c9b49ac5a5b7c9f14c518bd8e57a2df39672882 Mon Sep 17 00:00:00 2001 From: Zoe Statman-Weil Date: Mon, 10 Jan 2022 17:02:45 -0800 Subject: [PATCH 8/8] updated changelog to reflect actual PR number --- CHANGES.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index e990b612c..9c5acafb3 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -22,8 +22,8 @@ * The minimum `limit` value for searches is now 1 ([#296](https://github.com/stac-utils/stac-fastapi/pull/296)) * Links stored with Collections and Items (e.g. license links) are now returned with those STAC objects ([#282](https://github.com/stac-utils/stac-fastapi/pull/282)) * Content-type response headers for the /api endpoint now reflect those expected in the STAC api spec ([#287](https://github.com/stac-utils/stac-fastapi/pull/287)) -* Changed type options for datetime in BaseSearchGetRequest ([#315](https://github.com/stac-utils/stac-fastapi/pull/315)) -* Expanded on tests to ensure properly testing get and post searches ([#315](https://github.com/stac-utils/stac-fastapi/pull/315)) +* Changed type options for datetime in BaseSearchGetRequest ([#315](https://github.com/stac-utils/stac-fastapi/pull/318)) +* Expanded on tests to ensure properly testing get and post searches ([#315](https://github.com/stac-utils/stac-fastapi/pull/318)) ## [2.2.0]