def test_repository_can_get_collections_from_catalog(): s3 = S3(key=None, secret=None, s3_endpoint=None, region_name='us-east-1') initialise_stac_bucket(s3_resource=s3.s3_resource, bucket_name=BUCKET) catalog_test = load_json('tests/data/catalog.json') collection_test = load_json('tests/data/sentinel-2/collection.json') repo = repository.S3Repository(s3) collections = repo.get_collections_from_catalog(catalog_test) assert collections == [collection_test]
def test_repository_get_items_from_collection(): s3 = S3(key=None, secret=None, s3_endpoint=None, region_name='us-east-1') initialise_stac_bucket(s3_resource=s3.s3_resource, bucket_name=BUCKET) collection_test = load_json('tests/data/sentinel-2/collection.json') items_test = [load_json(item) for item in get_files_from_dir('tests/data/sentinel-2', 'json') if not item.endswith('collection.json')] repo = repository.S3Repository(s3) items = repo.get_items_from_collection(collection_test) assert any(x != y for x, y in zip(items, items_test))
def test_rel_links_item(): metadata = load_json('tests/data/sentinel-2/collection.json') child_links = get_rel_links(metadata, 'item') assert child_links == [ 'https://s3-uk-1.sa-catapult.co.uk/public-eo-data/stac_catalogs/cs_stac/sentinel-2' '/S2A_MSIL2A_20151002T222056_T01KAU/S2A_MSIL2A_20151002T222056_T01KAU.json', 'https://s3-uk-1.sa-catapult.co.uk/public-eo-data/stac_catalogs/cs_stac/sentinel-2' '/S2A_MSIL2A_20151002T222056_T01KBU/S2A_MSIL2A_20151002T222056_T01KBU.json', 'https://s3-uk-1.sa-catapult.co.uk/public-eo-data/stac_catalogs/cs_stac/sentinel-2' '/S2A_MSIL2A_20151022T222102_T01KAU/S2A_MSIL2A_20151022T222102_T01KAU.json', 'https://s3-uk-1.sa-catapult.co.uk/public-eo-data/stac_catalogs/cs_stac/sentinel-2' '/S2A_MSIL2A_20151022T222102_T01KBU/S2A_MSIL2A_20151022T222102_T01KBU.json', 'https://s3-uk-1.sa-catapult.co.uk/public-eo-data/stac_catalogs/cs_stac/sentinel-2' '/S2A_MSIL2A_20151114T223002_T60KWD/S2A_MSIL2A_20151114T223002_T60KWD.json', 'https://s3-uk-1.sa-catapult.co.uk/public-eo-data/stac_catalogs/cs_stac/sentinel-2' '/S2A_MSIL2A_20151114T223002_T60KWE/S2A_MSIL2A_20151114T223002_T60KWE.json', 'https://s3-uk-1.sa-catapult.co.uk/public-eo-data/stac_catalogs/cs_stac/sentinel-2' '/S2A_MSIL2A_20151114T223002_T60KWF/S2A_MSIL2A_20151114T223002_T60KWF.json', 'https://s3-uk-1.sa-catapult.co.uk/public-eo-data/stac_catalogs/cs_stac/sentinel-2' '/S2A_MSIL2A_20151114T223002_T60KWG/S2A_MSIL2A_20151114T223002_T60KWG.json', 'https://s3-uk-1.sa-catapult.co.uk/public-eo-data/stac_catalogs/cs_stac/sentinel-2' '/S2A_MSIL2A_20151114T223002_T60KXD/S2A_MSIL2A_20151114T223002_T60KXD.json', 'https://s3-uk-1.sa-catapult.co.uk/public-eo-data/stac_catalogs/cs_stac/sentinel-2' '/S2A_MSIL2A_20151114T223002_T60KXE/S2A_MSIL2A_20151114T223002_T60KXE.json' ]
def test_rel_links_child(): metadata = load_json('tests/data/catalog.json') child_links = get_rel_links(metadata, 'child') assert child_links == [ "https://s3-uk-1.sa-catapult.co.uk/public-eo-data/stac_catalogs/cs_stac/sentinel-2" "/collection.json" ]
def test_guess_location_relative(): metadata = load_json( 'tests/data/uksa-ssgp/uksa-ssgp-spot/' 'UKSA_SPOT155_SO18034609-55-01_DS_SPOT6_201810101058095_FR1_FR1_FR1_FR1_W001N52_01140/' 'UKSA_SPOT155_SO18034609-55-01_DS_SPOT6_201810101058095_FR1_FR1_FR1_FR1_W001N52_01140.json' ) uri, relative = guess_location(metadata) assert relative
def test_repository_can_get_catalogs_from_s3_path(): s3 = S3(key=None, secret=None, s3_endpoint=None, region_name='us-east-1') initialise_stac_bucket(s3_resource=s3.s3_resource, bucket_name=BUCKET) repo = repository.S3Repository(s3) catalogs = repo.get_catalogs_from_path(bucket=BUCKET, path='stac_catalogs/cs_stac') assert catalogs == [load_json('tests/data/catalog.json')]
def test_get_product_metadata_from_collection(): collection = load_json('tests/data/sentinel-2/collection.json') product = get_product_metadata_from_collection(collection) schema = Schema({ 'name': str, 'description': str, 'metadata_type': str, 'metadata': dict, 'measurements': list }) assert schema.validate(product)
def test_guess_location_absolute(): metadata = load_json( 'tests/data/sentinel-s2-l2a-cogs/S2A_30VXL_20210203_0_L2A.json') uri, relative = guess_location(metadata) assert not relative
def test_rel_links_no_exists(): metadata = load_json('tests/data/catalog.json') child_links = get_rel_links(metadata, 'foo') assert child_links == []