Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TO BE DISCUSSED] refactor factories to enable more customization #83

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,25 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/).

Note: Minor version `0.X.0` update might break the API, It's recommended to pin `tipg` to minor version: `tipg>=0.1,<0.2`

## unreleased
## [unreleased]

### Added

* `type` query parameter to filter collections based on their type (`Function` or `Table`)

* `catalog_dependency` to retrieve the list of collections (defaults to `tipg.dependencies.CatalogParams`)

* `additional_collection_links` and `additional_item_links` to be able to infer links

### Changed

* `tipg.factory.Endpoints` is now created directly from both `OGCFeaturesFactory` and `OGCTilesFactory` classes

* factory's `links` method now uses `common|features|tiles_links` sub-methods

* `conforms_to` use module's variables


## [0.2.0] - 2023-06-22

### Changed
Expand Down
18 changes: 8 additions & 10 deletions tests/test_factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def test_features_factory():
assert endpoints.with_common
assert endpoints.title == "OGC API"
assert len(endpoints.router.routes) == 7
assert len(endpoints.conforms_to) == 6
assert len(endpoints.conforms_to) == 13

app = FastAPI()
app.include_router(endpoints.router)
Expand Down Expand Up @@ -90,7 +90,7 @@ def test_features_factory():
assert not endpoints.with_common
assert endpoints.title == "OGC Features API"
assert len(endpoints.router.routes) == 5
assert len(endpoints.conforms_to) == 6
assert len(endpoints.conforms_to) == 13

app = FastAPI()
app.include_router(endpoints.router)
Expand All @@ -113,7 +113,7 @@ def test_tiles_factory():
assert endpoints.with_common
assert endpoints.title == "OGC API"
assert len(endpoints.router.routes) == 14
assert len(endpoints.conforms_to) == 5
assert len(endpoints.conforms_to) == 12

app = FastAPI()
app.include_router(endpoints.router)
Expand Down Expand Up @@ -177,7 +177,7 @@ def test_tiles_factory():
assert not endpoints.with_common
assert endpoints.title == "OGC Tiles API"
assert len(endpoints.router.routes) == 12
assert len(endpoints.conforms_to) == 5
assert len(endpoints.conforms_to) == 12

app = FastAPI()
app.include_router(endpoints.router)
Expand All @@ -200,7 +200,9 @@ def test_endpoints_factory():
assert endpoints.with_common
assert endpoints.title == "OGC API"
assert len(endpoints.router.routes) == 19
assert len(endpoints.conforms_to) == 11 # 5 from tiles + 6 from features
assert (
len(endpoints.conforms_to) == 18
) # 5 from tiles + 6 from features + 7 from common

app = FastAPI()
app.include_router(endpoints.router)
Expand Down Expand Up @@ -239,10 +241,6 @@ def test_endpoints_factory():
assert endpoints.with_common
assert endpoints.title == "OGC Full API"
assert len(endpoints.router.routes) == 19
assert not endpoints.ogc_features.with_common
assert endpoints.ogc_features.router_prefix == "/ogc"
assert not endpoints.ogc_tiles.with_common
assert endpoints.ogc_tiles.router_prefix == "/ogc"

app = FastAPI()
app.include_router(endpoints.router, prefix="/ogc")
Expand Down Expand Up @@ -281,7 +279,7 @@ def test_endpoints_factory():
assert not endpoints.with_common
assert endpoints.title == "Tiles and Features API"
assert len(endpoints.router.routes) == 17 # 10 from tiles + 5 from features
assert len(endpoints.conforms_to) == 11 # 4 from tiles + 6 from features
assert len(endpoints.conforms_to) == 18 # 4 from tiles + 6 from features

app = FastAPI()
app.include_router(endpoints.router)
Expand Down
9 changes: 9 additions & 0 deletions tipg/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ def CollectionParams(
)


def CatalogParams(request: Request) -> Catalog:
"""Return Collections Catalog."""
collection_catalog: Catalog = getattr(request.app.state, "collection_catalog", None)
if not collection_catalog:
raise MissingCollectionCatalog("Could not find collections catalog.")

return collection_catalog


def accept_media_type(
accept: str, mediatypes: List[enums.MediaType]
) -> Optional[enums.MediaType]:
Expand Down
Loading