Beispiel #1
0
def test_load_items_incompatible_version(loader: Loader) -> None:
    """Test pypgstac items loader raises an exception for incompatible version."""
    with mock.patch("pypgstac.db.PgstacDB.version",
                    new_callable=mock.PropertyMock) as mock_version:
        mock_version.return_value = "dummy"
        with pytest.raises(Exception):
            loader.load_items(
                str(TEST_ITEMS),
                insert_mode=Methods.insert,
            )
Beispiel #2
0
def test_load_items_succeeds(loader: Loader) -> None:
    """Test pypgstac items loader."""
    loader.load_collections(
        str(TEST_COLLECTIONS),
        insert_mode=Methods.upsert,
    )

    loader.load_items(
        str(TEST_ITEMS),
        insert_mode=Methods.insert,
    )
Beispiel #3
0
 def load(
     self,
     table: Tables,
     file: str,
     method: Optional[Methods] = Methods.insert,
     dehydrated: Optional[bool] = False,
     chunksize: Optional[int] = 10000,
 ) -> None:
     """Load collections or items into PGStac."""
     loader = Loader(db=self._db)
     if table == "collections":
         loader.load_collections(file, method)
     if table == "items":
         loader.load_items(file, method, dehydrated, chunksize)
Beispiel #4
0
def test_load_items_dehydrated_ignore_succeeds(loader: Loader) -> None:
    """Test pypgstac items ignore loader."""
    loader.load_collections(
        str(TEST_COLLECTIONS),
        insert_mode=Methods.ignore,
    )

    loader.load_items(str(TEST_DEHYDRATED_ITEMS),
                      insert_mode=Methods.insert,
                      dehydrated=True)

    loader.load_items(str(TEST_DEHYDRATED_ITEMS),
                      insert_mode=Methods.ignore,
                      dehydrated=True)
Beispiel #5
0
def test_load_items_duplicates_fails(loader: Loader) -> None:
    """Test pypgstac collections loader."""
    loader.load_collections(
        str(TEST_COLLECTIONS),
        insert_mode=Methods.insert,
    )
    loader.load_items(
        str(TEST_ITEMS),
        insert_mode=Methods.insert,
    )

    with pytest.raises(UniqueViolation):
        loader.load_items(
            str(TEST_ITEMS),
            insert_mode=Methods.insert,
        )
Beispiel #6
0
def test_partition_loads_default(loader: Loader) -> None:
    """Test pypgstac items ignore loader."""
    loader.load_collections(
        str(TEST_COLLECTIONS_JSON),
        insert_mode=Methods.ignore,
    )

    loader.load_items(
        str(TEST_ITEMS),
        insert_mode=Methods.insert,
    )

    partitions = loader.db.query_one("""
        SELECT count(*) from partitions;
    """)

    assert partitions == 1
Beispiel #7
0
def test_load_dehydrated(loader: Loader) -> None:
    """Test loader for items dumped directly out of item table."""
    collections = [
        HERE / "data-files" / "hydration" / "collections" /
        "chloris-biomass.json",
    ]

    for collection in collections:
        loader.load_collections(
            str(collection),
            insert_mode=Methods.ignore,
        )

    dehydrated_items = HERE / "data-files" / "load" / "dehydrated.txt"

    loader.load_items(str(dehydrated_items),
                      insert_mode=Methods.insert,
                      dehydrated=True)
Beispiel #8
0
def test_s1_grd_load_and_query(loader: Loader) -> None:
    """Test pypgstac items ignore loader."""
    loader.load_collections(
        str(S1_GRD_COLLECTION),
        insert_mode=Methods.ignore,
    )

    loader.load_items(str(S1_GRD_ITEM), insert_mode=Methods.insert)

    search_body = {
        "filter-lang": "cql2-json",
        "filter": {
            "op":
            "and",
            "args": [
                {
                    "op": "=",
                    "args": [{
                        "property": "collection"
                    }, "sentinel-1-grd"],
                },
                {
                    "op":
                    "=",
                    "args": [
                        {
                            "property": "id"
                        },
                        "S1A_IW_GRDH_1SDV_20220428T034417_20220428T034442_042968_05213C",  # noqa: E501
                    ],
                },
            ],
        },
    }

    res = next(loader.db.func(
        "search",
        search_body,
    ))[0]
    item = res["features"][0]
    pystac.Item.from_dict(item).validate()
Beispiel #9
0
def test_partition_loads_year(loader: Loader) -> None:
    """Test pypgstac items ignore loader."""
    loader.load_collections(
        str(TEST_COLLECTIONS_JSON),
        insert_mode=Methods.ignore,
    )
    if loader.db.connection is not None:
        loader.db.connection.execute("""
            UPDATE collections SET partition_trunc='year';
        """)

    loader.load_items(
        str(TEST_ITEMS),
        insert_mode=Methods.insert,
    )

    partitions = loader.db.query_one("""
        SELECT count(*) from partitions;
    """)

    assert partitions == 1