Exemple #1
0
async def add_item(addItem: addItem):
    """[summary]
    Inserts a new item on the DB.
    [description]
    Endpoint to add a new item.
    """
    collection_id = addItem.collection

    if (collection_id == 'sentinel-s2-l2a-cogs'
            or collection_id == 'landsat-8-l1-c1'):
        return "cannot add to this collection"
    else:
        col = DB[collection_id]

    item = addItem.item
    with open('tester.json', 'w') as fp:
        json.dump(item, fp)

    stac = stac_validator.StacValidate('tester.json')
    stac.run()
    if stac.message[0]["valid_stac"] == False:
        return "not a valid stac item"

    exists = await col.count_documents({'_id': item['id']}) > 0
    if exists > 0:
        return "item already exists"
    else:
        item['_id'] = item['id']
        item_op = await col.insert_one(item)
        return "item succesfully added"
Exemple #2
0
def test_correct_validate_dict_return_method():
    stac = stac_validator.StacValidate()
    with open("tests/test_data/1rc2/extensions-collection/collection.json",
              "r") as f:
        good_stac = json.load(f)
    if stac.validate_dict(good_stac) is True:
        return True
Exemple #3
0
    def test_stac_compliant(self):
        self.manifest.flush()
        self.manifest[self.name].search(self.spatial)
        response = self.manifest.execute()

        # Confirming that output features are STAC-compliant
        for feat in response[self.name]['features']:

            fd, path = tempfile.mkstemp()
            try:
                with os.fdopen(fd, 'w') as tmp:
                    json.dump(feat, tmp)

                stac = stac_validator.StacValidate(path)
                stac.run()
                try:
                    self.assertEqual(stac.status['items']['valid'], 1)
                except:
                    # TODO: figure out why this error happens
                    if 'Unresolvable JSON pointer' in stac.message[0][
                            'error_message']:
                        pass
                    else:
                        raise

            finally:
                os.remove(path)
Exemple #4
0
def test_incorrect_validate_dict_return_method():
    stac = stac_validator.StacValidate()
    with open("tests/test_data/1rc2/extensions-collection/collection.json",
              "r") as f:
        good_stac = json.load(f)
        bad_stac = good_stac.pop("type", None)
    if stac.validate_dict(bad_stac) is False:
        return True
def _run_validate(url,
                  stac_spec_dirs=None,
                  version="master",
                  log_level="DEBUG",
                  follow=False):
    stac = stac_validator.StacValidate(url, stac_spec_dirs, version, log_level,
                                       follow)
    stac.run()
    return stac
Exemple #6
0
def test_validate_dict_catalog_v1rc2():
    stac_file = {
        "id":
        "examples",
        "type":
        "Catalog",
        "stac_version":
        "1.0.0-rc.2",
        "description":
        "This catalog is a simple demonstration of an example catalog that is used to organize a hierarchy of collections and their items.",
        "links": [
            {
                "rel": "root",
                "href": "./catalog.json",
                "type": "application/json"
            },
            {
                "rel": "child",
                "href": "./extensions-collection/collection.json",
                "type": "application/json",
                "title": "Collection Demonstrating STAC Extensions",
            },
            {
                "rel": "child",
                "href": "./collection-only/collection.json",
                "type": "application/json",
                "title": "Collection with no items (standalone)",
            },
            {
                "rel": "self",
                "href":
                "https://raw.githubusercontent.com/radiantearth/stac-spec/v1.0.0-rc.2/examples/catalog.json",
                "type": "application/json",
            },
        ],
    }

    stac = stac_validator.StacValidate()
    stac.validate_dict(stac_file)
    assert stac.message == [{
        "path":
        None,
        "asset_type":
        "CATALOG",
        "version":
        "1.0.0-rc.2",
        "validation_method":
        "default",
        "schema": [
            "https://schemas.stacspec.org/v1.0.0-rc.2/catalog-spec/json-schema/catalog.json"
        ],
        "valid_stac":
        True,
    }]
Exemple #7
0
def test_no_extensions_v1beta2():
    stac_file = "tests/test_data/1beta2/stac_item.json"
    stac = stac_validator.StacValidate(stac_file, extensions=True)
    stac.run()
    assert stac.message == [{
        "path": "tests/test_data/1beta2/stac_item.json",
        "asset_type": "ITEM",
        "version": "1.0.0-beta.2",
        "validation_method": "extensions",
        "schema": [],
        "valid_stac": True,
    }]
Exemple #8
0
def test_core_item_local_v070():
    stac_file = "tests/test_data/v070/items/sample-full.json"
    stac = stac_validator.StacValidate(stac_file, core=True)
    stac.run()
    assert stac.message == [{
        "version": "",
        "path": "tests/test_data/v070/items/sample-full.json",
        "schema": [""],
        "valid_stac": False,
        "error_type": "KeyError",
        "error_message": "'stac_version'",
    }]
Exemple #9
0
def test_custom_item_remote_schema_v090():
    schema = "https://cdn.staclint.com/v0.9.0/catalog.json"
    stac_file = "https://raw.githubusercontent.com/stac-utils/pystac/main/tests/data-files/examples/0.9.0/collection-spec/examples/landsat-collection.json"
    stac = stac_validator.StacValidate(stac_file, custom=schema)
    stac.run()
    assert stac.message == [
        {
            "version": "0.9.0",
            "path": "https://raw.githubusercontent.com/stac-utils/pystac/main/tests/data-files/examples/0.9.0/collection-spec/examples/landsat-collection.json",
            "schema": ["https://cdn.staclint.com/v0.9.0/catalog.json"],
            "asset_type": "COLLECTION",
            "validation_method": "custom",
            "valid_stac": True,
        }
    ]
Exemple #10
0
def test_custom_item_remote_schema_v080():
    schema = "https://cdn.staclint.com/v0.8.0/item.json"
    stac_file = "tests/test_data/v080/items/digitalglobe-sample.json"
    stac = stac_validator.StacValidate(stac_file, custom=schema)
    stac.run()
    assert stac.message == [
        {
            "version": "0.8.0",
            "path": "tests/test_data/v080/items/digitalglobe-sample.json",
            "schema": ["https://cdn.staclint.com/v0.8.0/item.json"],
            "asset_type": "ITEM",
            "validation_method": "custom",
            "valid_stac": False,
            "error_type": "ValidationError",
            "error_message": "'bbox' is a required property of the root of the STAC object",
        }
    ]
Exemple #11
0
def test_recursive_v1beta1():
    stac_file = "tests/test_data/1beta1/sentinel2.json"
    stac = stac_validator.StacValidate(stac_file, recursive=True, max_depth=0)
    stac.run()
    assert stac.message == [{
        "version":
        "1.0.0-beta.1",
        "path":
        "tests/test_data/1beta1/sentinel2.json",
        "schema": ["https://cdn.staclint.com/v1.0.0-beta.1/collection.json"],
        "asset_type":
        "COLLECTION",
        "validation_method":
        "recursive",
        "valid_stac":
        True,
    }]
Exemple #12
0
def test_core_item_local_extensions_v090():
    stac_file = "tests/test_data/v090/items/CBERS_4.json"
    stac = stac_validator.StacValidate(stac_file, core=True)
    stac.run()
    assert stac.message == [{
        "version":
        "0.9.0",
        "path":
        "tests/test_data/v090/items/CBERS_4.json",
        "schema": ["https://cdn.staclint.com/v0.9.0/item.json"],
        "asset_type":
        "ITEM",
        "validation_method":
        "core",
        "valid_stac":
        True,
    }]
Exemple #13
0
def test_core_collection_local_v070():
    stac_file = "tests/test_data/v070/collections/sentinel2.json"
    stac = stac_validator.StacValidate(stac_file, core=True)
    stac.run()
    assert stac.message == [{
        "version":
        "0.7.0",
        "path":
        "tests/test_data/v070/collections/sentinel2.json",
        "schema": ["https://cdn.staclint.com/v0.7.0/collection.json"],
        "valid_stac":
        True,
        "asset_type":
        "COLLECTION",
        "validation_method":
        "core",
    }]
Exemple #14
0
def test_default_v070():
    stac_file = "https://radarstac.s3.amazonaws.com/stac/catalog.json"
    stac = stac_validator.StacValidate(stac_file)
    stac.run()
    assert stac.message == [{
        "version":
        "0.7.0",
        "path":
        "https://radarstac.s3.amazonaws.com/stac/catalog.json",
        "asset_type":
        "CATALOG",
        "validation_method":
        "default",
        "schema": ["https://cdn.staclint.com/v0.7.0/catalog.json"],
        "valid_stac":
        True,
    }]
Exemple #15
0
def test_item_local_v080():
    stac_file = "tests/test_data/v080/items/sample-full.json"
    stac = stac_validator.StacValidate(stac_file, extensions=True)
    stac.run()
    assert stac.message == [{
        "version":
        "0.8.0",
        "path":
        "tests/test_data/v080/items/sample-full.json",
        "asset_type":
        "ITEM",
        "validation_method":
        "extensions",
        "schema": ["https://cdn.staclint.com/v0.8.0/extension/eo.json"],
        "valid_stac":
        True,
    }]
Exemple #16
0
def test_custom_item_remote_schema_v1rc2():
    schema = "https://schemas.stacspec.org/v1.0.0-rc.2/item-spec/json-schema/item.json"

    stac_file = "tests/test_data/1rc2/simple-item.json"
    stac = stac_validator.StacValidate(stac_file, custom=schema)
    stac.run()
    assert stac.message == [
        {
            "path": "tests/test_data/1rc2/simple-item.json",
            "asset_type": "ITEM",
            "version": "1.0.0-rc.2",
            "validation_method": "custom",
            "schema": [
                "https://schemas.stacspec.org/v1.0.0-rc.2/item-spec/json-schema/item.json"
            ],
            "valid_stac": True,
        }
    ]
Exemple #17
0
def test_local_v1rc2():
    stac_file = (
        "tests/test_data/1rc2/extensions-collection/./proj-example/proj-example.json"
    )
    stac = stac_validator.StacValidate(stac_file, extensions=True)
    stac.run()
    assert stac.message == [{
        "version":
        "1.0.0-rc.2",
        "path":
        "tests/test_data/1rc2/extensions-collection/./proj-example/proj-example.json",
        "schema": ["https://stac-extensions.github.io/eo/v1.0.0/schema.json"],
        "valid_stac":
        False,
        "error_type":
        "ValidationError",
        "error_message":
        "'panchromatic' is not one of ['coastal', 'blue', 'green', 'red', 'rededge', 'yellow', 'pan', 'nir', 'nir08', 'nir09', 'cirrus', 'swir16', 'swir22', 'lwir', 'lwir11', 'lwir12']. Error is in assets -> B8 -> eo:bands -> 0 -> common_name",
    }]
Exemple #18
0
def test_core_collection_local_v1rc1():
    stac_file = "tests/test_data/1rc1/collection.json"
    stac = stac_validator.StacValidate(stac_file, core=True)
    stac.run()
    assert stac.message == [{
        "version":
        "1.0.0-rc.1",
        "path":
        "tests/test_data/1rc1/collection.json",
        "schema": [
            "https://schemas.stacspec.org/v1.0.0-rc.1/collection-spec/json-schema/collection.json"
        ],
        "asset_type":
        "COLLECTION",
        "validation_method":
        "core",
        "valid_stac":
        True,
    }]
Exemple #19
0
def test_recursive_v1beta2():
    stac_file = "https://raw.githubusercontent.com/stac-utils/pystac/main/tests/data-files/examples/1.0.0-beta.2/collection-spec/examples/sentinel2.json"
    stac = stac_validator.StacValidate(stac_file, recursive=True, max_depth=0)
    stac.run()
    assert stac.message == [{
        "version":
        "1.0.0-beta.2",
        "path":
        "https://raw.githubusercontent.com/stac-utils/pystac/main/tests/data-files/examples/1.0.0-beta.2/collection-spec/examples/sentinel2.json",
        "schema": [
            "https://schemas.stacspec.org/v1.0.0-beta.2/collection-spec/json-schema/collection.json"
        ],
        "asset_type":
        "COLLECTION",
        "validation_method":
        "recursive",
        "valid_stac":
        True,
    }]
Exemple #20
0
def test_core_item_local_v100():
    stac_file = "tests/test_data/v100/extended-item.json"
    stac = stac_validator.StacValidate(stac_file, core=True)
    stac.run()
    assert stac.message == [{
        "version":
        "1.0.0",
        "path":
        "tests/test_data/v100/extended-item.json",
        "schema": [
            "https://schemas.stacspec.org/v1.0.0/item-spec/json-schema/item.json"
        ],
        "valid_stac":
        True,
        "asset_type":
        "ITEM",
        "validation_method":
        "core",
    }]
Exemple #21
0
def test_catalog_v1rc2():
    stac_file = "tests/test_data/1rc2/catalog.json"
    stac = stac_validator.StacValidate(stac_file, extensions=True)
    stac.run()
    assert stac.message == [{
        "version":
        "1.0.0-rc.2",
        "path":
        "tests/test_data/1rc2/catalog.json",
        "schema": [
            "https://schemas.stacspec.org/v1.0.0-rc.2/catalog-spec/json-schema/catalog.json"
        ],
        "asset_type":
        "CATALOG",
        "validation_method":
        "extensions",
        "valid_stac":
        True,
    }]
Exemple #22
0
def test_assets_v090():
    stac_file = "tests/test_data/v090/items/CBERS_4_bad_links.json"
    stac = stac_validator.StacValidate(stac_file, assets=True)
    stac.run()
    assert stac.message == [{
        "version":
        "0.9.0",
        "path":
        "tests/test_data/v090/items/CBERS_4_bad_links.json",
        "schema": [
            "https://cdn.staclint.com/v0.9.0/extension/view.json",
            "https://cdn.staclint.com/v0.9.0/item.json",
        ],
        "valid_stac":
        False,
        "error_type":
        "ValidationError",
        "error_message":
        "-0.00751271 is less than the minimum of 0. Error is in properties -> view:off_nadir",
        "validation_method":
        "default",
        "assets_validated": {
            "format_valid": [
                "https://s3.amazonaws.com/cbers-meta-pds/CBERS4/MUX/177/106/CBERS_4_MUX_20181029_177_106_L4/CBERS_4_MUX_20181029_177_106.jpg",
                "s3://cbers-pds/CBERS4/MUX/177/106/CBERS_4_MUX_20181029_177_106_L4/CBERS_4_MUX_20181029_177_106_L4_BAND6.xml",
                "s3://cbers-pds/CBERS4/MUX/177/106/CBERS_4_MUX_20181029_177_106_L4/CBERS_4_MUX_20181029_177_106_L4_BAND5.tif",
                "s3://cbers-pds/CBERS4/MUX/177/106/CBERS_4_MUX_20181029_177_106_L4/CBERS_4_MUX_20181029_177_106_L4_BAND6.tif",
                "s3://cbers-pds/CBERS4/MUX/177/106/CBERS_4_MUX_20181029_177_106_L4/CBERS_4_MUX_20181029_177_106_L4_BAND7.tif",
                "s3://cbers-pds/CBERS4/MUX/177/106/CBERS_4_MUX_20181029_177_106_L4/CBERS_4_MUX_20181029_177_106_L4_BAND8.tif",
            ],
            "format_invalid": [],
            "request_valid": [
                "https://s3.amazonaws.com/cbers-meta-pds/CBERS4/MUX/177/106/CBERS_4_MUX_20181029_177_106_L4/CBERS_4_MUX_20181029_177_106.jpg"
            ],
            "request_invalid": [
                "s3://cbers-pds/CBERS4/MUX/177/106/CBERS_4_MUX_20181029_177_106_L4/CBERS_4_MUX_20181029_177_106_L4_BAND6.xml",
                "s3://cbers-pds/CBERS4/MUX/177/106/CBERS_4_MUX_20181029_177_106_L4/CBERS_4_MUX_20181029_177_106_L4_BAND5.tif",
                "s3://cbers-pds/CBERS4/MUX/177/106/CBERS_4_MUX_20181029_177_106_L4/CBERS_4_MUX_20181029_177_106_L4_BAND6.tif",
                "s3://cbers-pds/CBERS4/MUX/177/106/CBERS_4_MUX_20181029_177_106_L4/CBERS_4_MUX_20181029_177_106_L4_BAND7.tif",
                "s3://cbers-pds/CBERS4/MUX/177/106/CBERS_4_MUX_20181029_177_106_L4/CBERS_4_MUX_20181029_177_106_L4_BAND8.tif",
            ],
        },
    }]
Exemple #23
0
def test_v1beta2():
    stac_file = "tests/test_data/1beta2/CBERS_4.json"
    stac = stac_validator.StacValidate(stac_file, extensions=True)
    stac.run()
    assert stac.message == [{
        "version":
        "1.0.0-beta.2",
        "path":
        "tests/test_data/1beta2/CBERS_4.json",
        "schema": [
            "https://cdn.staclint.com/v1.0.0-beta.1/extension/projection.json",
            "https://cdn.staclint.com/v1.0.0-beta.1/extension/view.json",
        ],
        "asset_type":
        "ITEM",
        "validation_method":
        "extensions",
        "valid_stac":
        True,
    }]
Exemple #24
0
def test_v090():
    stac_file = "tests/test_data/v090/extensions/eo/examples/example-landsat8.json"
    stac = stac_validator.StacValidate(stac_file, extensions=True)
    stac.run()
    assert stac.message == [{
        "version":
        "0.9.0",
        "path":
        "tests/test_data/v090/extensions/eo/examples/example-landsat8.json",
        "asset_type":
        "ITEM",
        "validation_method":
        "extensions",
        "schema": [
            "https://cdn.staclint.com/v0.9.0/extension/eo.json",
            "https://cdn.staclint.com/v0.9.0/extension/view.json",
        ],
        "valid_stac":
        True,
    }]
Exemple #25
0
def test_core_bad_item_local_v090():
    stac_file = "tests/test_data/bad_data/bad_item_v090.json"
    stac = stac_validator.StacValidate(stac_file, core=True)
    stac.run()
    assert stac.message == [{
        "version":
        "0.9.0",
        "path":
        "tests/test_data/bad_data/bad_item_v090.json",
        "asset_type":
        "ITEM",
        "validation_method":
        "core",
        "schema": ["https://cdn.staclint.com/v0.9.0/item.json"],
        "valid_stac":
        False,
        "error_type":
        "ValidationError",
        "error_message":
        "'id' is a required property of the root of the STAC object",
    }]
Exemple #26
0
def test_assets_v100():
    stac_file = "tests/test_data/v100/core-item.json"
    stac = stac_validator.StacValidate(stac_file, assets=True)
    stac.run()
    assert stac.message == [{
        "version":
        "1.0.0",
        "path":
        "tests/test_data/v100/core-item.json",
        "schema": [
            "https://schemas.stacspec.org/v1.0.0/item-spec/json-schema/item.json"
        ],
        "valid_stac":
        True,
        "asset_type":
        "ITEM",
        "validation_method":
        "default",
        "assets_validated": {
            "format_valid": [
                "https://storage.googleapis.com/open-cogs/stac-examples/20201211_223832_CS2_analytic.tif",
                "https://storage.googleapis.com/open-cogs/stac-examples/20201211_223832_CS2.jpg",
                "https://storage.googleapis.com/open-cogs/stac-examples/20201211_223832_CS2.tif",
                "https://storage.googleapis.com/open-cogs/stac-examples/20201211_223832_CS2_analytic_udm.tif",
                "http://remotedata.io/catalog/20201211_223832_CS2/extended-metadata.json",
                "http://cool-sat.com/catalog/20201211_223832_CS2/20201211_223832_CS2.EPH",
            ],
            "format_invalid": [],
            "request_valid": [
                "https://storage.googleapis.com/open-cogs/stac-examples/20201211_223832_CS2_analytic.tif",
                "https://storage.googleapis.com/open-cogs/stac-examples/20201211_223832_CS2.jpg",
                "https://storage.googleapis.com/open-cogs/stac-examples/20201211_223832_CS2.tif",
                "https://storage.googleapis.com/open-cogs/stac-examples/20201211_223832_CS2_analytic_udm.tif",
                "http://remotedata.io/catalog/20201211_223832_CS2/extended-metadata.json",
            ],
            "request_invalid": [
                "http://cool-sat.com/catalog/20201211_223832_CS2/20201211_223832_CS2.EPH"
            ],
        },
    }]
Exemple #27
0
def test_default_v090():
    stac = stac_validator.StacValidate(
        "tests/test_data/v090/items/good_item_v090.json")
    stac.run()
    print(stac.message)
    assert stac.message == [{
        "version":
        "0.9.0",
        "path":
        "tests/test_data/v090/items/good_item_v090.json",
        "schema": [
            "https://cdn.staclint.com/v0.9.0/extension/eo.json",
            "https://cdn.staclint.com/v0.9.0/extension/view.json",
            "https://cdn.staclint.com/v0.9.0/item.json",
        ],
        "asset_type":
        "ITEM",
        "validation_method":
        "default",
        "valid_stac":
        True,
    }]
Exemple #28
0
def test_recursive_local_v090():
    stac_file = "tests/test_data/v090/catalog.json"
    stac = stac_validator.StacValidate(stac_file, recursive=True, max_depth=1)
    stac.run()
    assert stac.message == [
        {
            "version": "0.9.0",
            "path": "tests/test_data/v090/catalog.json",
            "schema": ["https://cdn.staclint.com/v0.9.0/catalog.json"],
            "asset_type": "CATALOG",
            "validation_method": "recursive",
            "valid_stac": True,
        },
        {
            "version": "0.9.0",
            "path": "tests/test_data/v090/items/sample.json",
            "schema": ["https://cdn.staclint.com/v0.9.0/item.json"],
            "asset_type": "ITEM",
            "validation_method": "recursive",
            "valid_stac": True,
        },
        {
            "version":
            "0.9.0",
            "path":
            "tests/test_data/v090/items/good_item_v090.json",
            "schema": [
                "https://cdn.staclint.com/v0.9.0/extension/eo.json",
                "https://cdn.staclint.com/v0.9.0/extension/view.json",
                "https://cdn.staclint.com/v0.9.0/item.json",
            ],
            "asset_type":
            "ITEM",
            "validation_method":
            "recursive",
            "valid_stac":
            True,
        },
    ]
Exemple #29
0
def test_default_proj_v1b2():
    stac_file = "https://earth-search.aws.element84.com/v0/collections/sentinel-s2-l1c/items/S2A_51SXT_20210415_0_L1C"
    stac = stac_validator.StacValidate(stac_file)
    stac.run()
    assert stac.message == [{
        "version":
        "1.0.0-beta.2",
        "path":
        "https://earth-search.aws.element84.com/v0/collections/sentinel-s2-l1c/items/S2A_51SXT_20210415_0_L1C",
        "schema": [
            "https://cdn.staclint.com/v1.0.0-beta.1/extension/eo.json",
            "https://cdn.staclint.com/v1.0.0-beta.1/extension/view.json",
            "https://cdn.staclint.com/v1.0.0-beta.1/extension/projection.json",
            "https://schemas.stacspec.org/v1.0.0-beta.2/item-spec/json-schema/item.json",
        ],
        "asset_type":
        "ITEM",
        "validation_method":
        "default",
        "valid_stac":
        True,
    }]
Exemple #30
0
def test_item_v100():
    stac_file = "tests/test_data/v100/extended-item.json"
    stac = stac_validator.StacValidate(stac_file, extensions=True)
    stac.run()
    assert stac.message == [{
        "version":
        "1.0.0",
        "path":
        "tests/test_data/v100/extended-item.json",
        "schema": [
            "https://stac-extensions.github.io/eo/v1.0.0/schema.json",
            "https://stac-extensions.github.io/projection/v1.0.0/schema.json",
            "https://stac-extensions.github.io/scientific/v1.0.0/schema.json",
            "https://stac-extensions.github.io/view/v1.0.0/schema.json",
            "https://stac-extensions.github.io/remote-data/v1.0.0/schema.json",
        ],
        "valid_stac":
        True,
        "asset_type":
        "ITEM",
        "validation_method":
        "extensions",
    }]