Esempio n. 1
0
    def assert_month_iteration(start: datetime, end: datetime,
                               expected_months: List[datetime]):
        __tracebackhide__ = operator.methodcaller("errisinstance",
                                                  AssertionError)

        product = ProductSummary("test_product", 5, start, end, [], [], {},
                                 datetime.now())
        got_months = list(product.iter_months())
        assert got_months == expected_months, "Incorrect set of iterated months"
Esempio n. 2
0
def test_add_no_periods(summary_store: SummaryStore):
    """
    All the get/update methods should work on products with no datasets.
    """
    summary_store._set_product_extent(
        ProductSummary("test_empty_product", 0, None, None, [], []))
    summary_store.get_or_update("test_empty_product", 2015, 7, 4)
    summary_store.get_or_update("test_empty_product", 2015, 7, None)
    summary_store.get_or_update("test_empty_product", 2015, None, None)
    summary_store.get_or_update("test_empty_product", None, None, None)
def test_put_get_summaries(summary_store: SummaryStore):
    """
    Test the serialisation/deserialisation from postgres
    """
    o = _overview()
    assert o.summary_gen_time is None, "Generation time should be set by server"

    product_name = "some_product"
    summary_store._set_product_extent(
        ProductSummary(
            product_name, 4321, datetime(2017, 1, 1), datetime(2017, 4, 1), [], [], {}
        )
    )

    summary_store._put(product_name, 2017, None, None, o)
    loaded = summary_store.get(product_name, 2017, None, None)

    assert o is not loaded, (
        "Store should not return the original objects " "(they may change)"
    )
    assert (
        o.summary_gen_time is not None
    ), "Summary-gen-time should have been added by the server"
    original_gen_time = o.summary_gen_time

    assert o.footprint_geometry.area == pytest.approx(4.857_924_619_872)

    assert loaded.dataset_count == 4
    assert (
        sum(loaded.region_dataset_counts.values()) == 4
    ), "Region dataset counts don't match total count"
    assert sorted(loaded.region_dataset_counts.keys()) == [
        "1_2",
        "3_4",
        "4_5",
    ], "Incorrect set of regions"
    assert o.footprint_crs == loaded.footprint_crs
    assert loaded.footprint_crs == "EPSG:3577"
    assert loaded.footprint_srid == 3577
    assert loaded.footprint_geometry.area == pytest.approx(o.footprint_geometry.area)

    o.dataset_count = 4321
    o.newest_dataset_creation_time = datetime(2018, 2, 2, 2, 2, 2, tzinfo=tz.tzutc())
    time.sleep(1)
    summary_store._put(product_name, 2017, None, None, o)
    assert o.summary_gen_time != original_gen_time

    loaded = summary_store.get(product_name, 2017, None, None)
    assert loaded.dataset_count == 4321
    assert loaded.newest_dataset_creation_time == datetime(
        2018, 2, 2, 2, 2, 2, tzinfo=tz.tzutc()
    )
    assert (
        loaded.summary_gen_time != original_gen_time
    ), "An update should update the generation time"