Esempio n. 1
0
    def test_merge(self):
        cat1 = create_catalog(1, include_href=False)
        cat2 = create_catalog(2)
        cat3 = create_catalog(3, include_href=False)
        cat4 = create_catalog(4)

        identical_cat1 = create_catalog(1, include_href=False)
        identical_cat2 = create_catalog(2)

        cached_ids_1 = {cat1.id: cat1}
        cached_hrefs_1 = {cat2.get_self_href(): cat2}
        cached_ids_2 = {cat3.id: cat3, cat1.id: identical_cat1}
        cached_hrefs_2 = {
            cat4.get_self_href(): cat4,
            cat2.get_self_href(): identical_cat2
        }
        cache1 = ResolvedObjectCollectionCache(ResolvedObjectCache(),
                                               cached_ids=cached_ids_1,
                                               cached_hrefs=cached_hrefs_1)
        cache2 = ResolvedObjectCollectionCache(ResolvedObjectCache(),
                                               cached_ids=cached_ids_2,
                                               cached_hrefs=cached_hrefs_2)

        merged = ResolvedObjectCollectionCache.merge(ResolvedObjectCache(),
                                                     cache1, cache2)

        self.assertEqual(set(merged.cached_ids.keys()),
                         set([cat.id for cat in [cat1, cat3]]))
        self.assertIs(merged.get_by_id(cat1.id), cat1)
        self.assertEqual(set(merged.cached_hrefs.keys()),
                         set([cat.get_self_href() for cat in [cat2, cat4]]))
        self.assertIs(merged.get_by_href(cat2.get_self_href()), cat2)
Esempio n. 2
0
    def test_cache(self):
        cache = ResolvedObjectCache().as_collection_cache()
        collection = TestCases.test_case_8()
        collection_json = collection.to_dict()
        cache.cache(collection_json, collection.get_self_href())

        self.assertEqual(cache.get_by_id(collection.id)['id'], collection.id)
Esempio n. 3
0
    def __init__(
        self,
        id: str,
        description: str,
        title: Optional[str] = None,
        stac_extensions: Optional[List[str]] = None,
        extra_fields: Optional[Dict[str, Any]] = None,
        href: Optional[str] = None,
        catalog_type: CatalogType = CatalogType.ABSOLUTE_PUBLISHED,
    ):
        super().__init__(stac_extensions or [])

        self.id = id
        self.description = description
        self.title = title
        if extra_fields is None:
            self.extra_fields = {}
        else:
            self.extra_fields = extra_fields

        self._resolved_objects = ResolvedObjectCache()

        self.add_link(Link.root(self))

        if href is not None:
            self.set_self_href(href)

        self.catalog_type: CatalogType = catalog_type

        self._resolved_objects.cache(self)
Esempio n. 4
0
    def __init__(self,
                 id,
                 description,
                 title=None,
                 stac_extensions=None,
                 extra_fields=None,
                 href=None,
                 catalog_type=None):
        super().__init__(stac_extensions)

        self.id = id
        self.description = description
        self.title = title
        if extra_fields is None:
            self.extra_fields = {}
        else:
            self.extra_fields = extra_fields

        self._resolved_objects = ResolvedObjectCache()

        self.add_link(Link.root(self))

        if href is not None:
            self.set_self_href(href)

        self.catalog_type = catalog_type

        self._resolved_objects.cache(self)
Esempio n. 5
0
 def test_cache(self) -> None:
     cache = ResolvedObjectCache().as_collection_cache()
     collection = TestCases.test_case_8()
     collection_json = collection.to_dict()
     cache.cache(collection_json, collection.get_self_href())
     cached = cache.get_by_id(collection.id)
     assert isinstance(cached, dict)
     self.assertEqual(cached["id"], collection.id)
Esempio n. 6
0
    def test_get_or_cache_returns_previously_cached_id(self):
        cache = ResolvedObjectCache()
        cat = create_catalog(1, include_href=False)
        cache_result_1 = cache.get_or_cache(cat)
        self.assertIs(cache_result_1, cat)

        identical_cat = create_catalog(1, include_href=False)
        cache_result_2 = cache.get_or_cache(identical_cat)
        self.assertIs(cache_result_2, cat)
Esempio n. 7
0
    def tests_get_or_cache_returns_previously_cached_href(self) -> None:
        cache = ResolvedObjectCache()
        cat = create_catalog(1)
        cache_result_1 = cache.get_or_cache(cat)
        self.assertIs(cache_result_1, cat)

        identical_cat = create_catalog(1)
        cache_result_2 = cache.get_or_cache(identical_cat)
        self.assertIs(cache_result_2, cat)
Esempio n. 8
0
    def __init__(self, id, description, title=None, stac_extensions=None, href=None):
        self.id = id
        self.description = description
        self.title = title
        self.stac_extensions = stac_extensions
        self.links = []
        self.add_link(Link.root(self))

        if href is not None:
            self.set_self_href(href)

        self._resolved_objects = ResolvedObjectCache()
        self._resolved_objects.cache(self)