Skip to content
This repository was archived by the owner on Apr 2, 2025. It is now read-only.

Commit 436a6b5

Browse files
author
Phil Varner
committed
rename classes
1 parent f87b225 commit 436a6b5

File tree

9 files changed

+31
-31
lines changed

9 files changed

+31
-31
lines changed

bin/server.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
from stapi_fastapi.exceptions import ConstraintsException, NotFoundException
66
from stapi_fastapi.models.opportunity import (
77
Opportunity,
8-
OpportunityPropertiesBase,
8+
OpportunityProperties,
99
OpportunityRequest,
1010
)
11-
from stapi_fastapi.models.order import Order, OrderParametersBase, OrderRequest
11+
from stapi_fastapi.models.order import Order, OrderParameters, OrderRequest
1212
from stapi_fastapi.models.product import (
1313
Product,
1414
Provider,
@@ -81,11 +81,11 @@ async def create_order(
8181
raise ConstraintsException("not allowed")
8282

8383

84-
class TestSpotlightProperties(OpportunityPropertiesBase):
84+
class TestSpotlightProperties(OpportunityProperties):
8585
off_nadir: int
8686

8787

88-
class TestOrderParameters(OrderParametersBase):
88+
class TestOrderParameters(OrderParameters):
8989
s3_path: str
9090

9191

src/stapi_fastapi/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from .backends import ProductBackend, RootBackend
22
from .models import (
33
Link,
4-
OpportunityPropertiesBase,
4+
OpportunityProperties,
55
Product,
66
Provider,
77
ProviderRole,
@@ -10,7 +10,7 @@
1010

1111
__all__ = [
1212
"Link",
13-
"OpportunityPropertiesBase",
13+
"OpportunityProperties",
1414
"Product",
1515
"ProductBackend",
1616
"ProductRouter",

src/stapi_fastapi/models/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
from .opportunity import OpportunityPropertiesBase
1+
from .opportunity import OpportunityProperties
22
from .product import Product, Provider, ProviderRole
33
from .shared import Link
44

55
__all__ = [
66
"Link",
7-
"OpportunityPropertiesBase",
7+
"OpportunityProperties",
88
"Product",
99
"Provider",
1010
"ProviderRole",

src/stapi_fastapi/models/opportunity.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111

1212
# Copied and modified from https://github.com/stac-utils/stac-pydantic/blob/main/stac_pydantic/item.py#L11
13-
class OpportunityPropertiesBase(BaseModel):
13+
class OpportunityProperties(BaseModel):
1414
datetime: DatetimeInterval
1515
model_config = ConfigDict(extra="allow")
1616

@@ -24,7 +24,7 @@ class OpportunityRequest(BaseModel):
2424

2525

2626
G = TypeVar("G", bound=Geometry)
27-
P = TypeVar("P", bound=OpportunityPropertiesBase)
27+
P = TypeVar("P", bound=OpportunityProperties)
2828

2929

3030
class Opportunity(Feature[G, P]):

src/stapi_fastapi/models/order.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
from geojson_pydantic.geometries import Geometry
55
from pydantic import BaseModel, ConfigDict, Field, StrictInt, StrictStr
66

7-
from stapi_fastapi.models.opportunity import OpportunityRequest, OpportunityPropertiesBase
7+
from stapi_fastapi.models.opportunity import OpportunityRequest, OpportunityProperties
88
from stapi_fastapi.models.shared import Link
99

1010

11-
class OrderParametersBase(BaseModel):
12-
model_config = ConfigDict(extra="forbid")
11+
class OrderParameters(BaseModel):
12+
model_config = ConfigDict(extra="allow")
1313

14-
P = TypeVar("P", bound=OrderParametersBase)
15-
O = TypeVar("O", bound=OpportunityPropertiesBase)
14+
P = TypeVar("P", bound=OrderParameters)
15+
O = TypeVar("O", bound=OpportunityProperties)
1616

1717
class OrderRequest(OpportunityRequest, Generic[P]):
1818
order_parameters: P

src/stapi_fastapi/models/product.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
from pydantic import AnyHttpUrl, BaseModel, Field
88

9-
from stapi_fastapi.models.opportunity import OpportunityPropertiesBase
10-
from stapi_fastapi.models.order import OrderParametersBase
9+
from stapi_fastapi.models.opportunity import OpportunityProperties
10+
from stapi_fastapi.models.order import OrderParameters
1111
from stapi_fastapi.models.shared import Link
1212

1313
if TYPE_CHECKING:
@@ -45,16 +45,16 @@ class Product(BaseModel):
4545
links: list[Link] = Field(default_factory=list)
4646

4747
# we don't want to include these in the model fields
48-
_constraints: type[OpportunityPropertiesBase]
49-
_order_parameters: OrderParametersBase
48+
_constraints: type[OpportunityProperties]
49+
_order_parameters: type[OrderParameters]
5050
_backend: ProductBackend
5151

5252
def __init__(
5353
self,
5454
*args,
5555
backend: ProductBackend,
56-
constraints: type[OpportunityPropertiesBase],
57-
order_parameters: type[OrderParametersBase],
56+
constraints: type[OpportunityProperties],
57+
order_parameters: type[OrderParameters],
5858
**kwargs,
5959
) -> None:
6060
super().__init__(*args, **kwargs)
@@ -67,11 +67,11 @@ def backend(self: Self) -> ProductBackend:
6767
return self._backend
6868

6969
@property
70-
def constraints(self: Self) -> type[OpportunityPropertiesBase]:
70+
def constraints(self: Self) -> type[OpportunityProperties]:
7171
return self._constraints
7272

7373
@property
74-
def order_parameters(self: Self) -> type[OrderParametersBase]:
74+
def order_parameters(self: Self) -> type[OrderParameters]:
7575
return self._order_parameters
7676

7777
def with_links(self: Self, links: list[Link] | None = None) -> Self:

tests/backends.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ async def create_order(
5555
"""
5656
Create a new order.
5757
"""
58-
allowed = any(allowed == payload for allowed in self._allowed_payloads)
59-
if allowed:
58+
if any(allowed == payload for allowed in self._allowed_payloads):
6059
order = Order(
6160
id=str(uuid4()),
6261
geometry=payload.geometry,
@@ -70,4 +69,5 @@ async def create_order(
7069
)
7170
self._orders[order.id] = order
7271
return order
73-
raise ConstraintsException("not allowed")
72+
else:
73+
raise ConstraintsException(f"not allowed: payload {payload.model_dump_json()} not in {[p.model_dump_json() for p in self._allowed_payloads]}")

tests/conftest.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,20 @@
1111
from geojson_pydantic.types import Position2D
1212
from stapi_fastapi.models.opportunity import (
1313
Opportunity,
14-
OpportunityPropertiesBase,
14+
OpportunityProperties,
1515
)
16-
from stapi_fastapi.models.order import OrderParametersBase, OrderRequest
16+
from stapi_fastapi.models.order import OrderParameters, OrderRequest
1717
from stapi_fastapi.models.product import Product, Provider, ProviderRole
1818
from stapi_fastapi.routers.root_router import RootRouter
1919

2020
from .backends import MockOrderDB, MockProductBackend, MockRootBackend
2121

2222

23-
class TestSpotlightProperties(OpportunityPropertiesBase):
23+
class TestSpotlightProperties(OpportunityProperties):
2424
off_nadir: int
2525

2626

27-
class TestSpotlightOrderProperties(OrderParametersBase):
27+
class TestSpotlightOrderProperties(OrderParameters):
2828
s3_path: str | None = None
2929

3030

tests/order_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def new_order_response(
2828
json=allowed_payloads[0].model_dump(),
2929
)
3030

31-
assert res.status_code == status.HTTP_201_CREATED
31+
assert res.status_code == status.HTTP_201_CREATED, res.text
3232
assert res.headers["Content-Type"] == "application/geo+json"
3333
return res
3434

0 commit comments

Comments
 (0)