Skip to content

Commit 2ce9e54

Browse files
committed
Adding default None to partials.
1 parent 53bfe47 commit 2ce9e54

File tree

2 files changed

+49
-28
lines changed

2 files changed

+49
-28
lines changed

stac_fastapi/extensions/tests/test_transaction.py

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import json
2-
from typing import Iterator, Union
2+
from typing import Iterator, List, Union
33

44
import pytest
55
from stac_pydantic import Collection
@@ -51,7 +51,7 @@ def patch_item(
5151
self,
5252
collection_id: str,
5353
item_id: str,
54-
patch: Union[PartialItem, PatchOperation],
54+
patch: Union[PartialItem, List[PatchOperation]],
5555
**kwargs,
5656
):
5757
return {
@@ -75,7 +75,7 @@ def update_collection(self, collection_id: str, collection: Collection, **kwargs
7575
def patch_collection(
7676
self,
7777
collection_id: str,
78-
patch: Union[PartialCollection, PatchOperation],
78+
patch: Union[PartialCollection, List[PatchOperation]],
7979
**kwargs,
8080
):
8181
return {
@@ -113,7 +113,7 @@ def test_update_item(client: TestClient, item: Item) -> None:
113113
assert response.json()["type"] == "Feature"
114114

115115

116-
def test_patch_item(client: TestClient) -> None:
116+
def test_patch_operation_item(client: TestClient) -> None:
117117
response = client.patch(
118118
"/collections/a-collection/items/an-item",
119119
content='[{"op": "add", "path": "/properties/foo", "value": "bar"}]',
@@ -126,6 +126,17 @@ def test_patch_item(client: TestClient) -> None:
126126
]
127127

128128

129+
def test_patch_merge_item(client: TestClient, item: Item) -> None:
130+
response = client.patch(
131+
"/collections/a-collection/items/an-item",
132+
content=json.dumps(item),
133+
)
134+
assert response.is_success, response.text
135+
assert response.json()["path_collection_id"] == "a-collection"
136+
assert response.json()["path_item_id"] == "an-item"
137+
assert response.json()["patch"]["type"] == "Feature"
138+
139+
129140
def test_delete_item(client: TestClient) -> None:
130141
response = client.delete("/collections/a-collection/items/an-item")
131142
assert response.is_success, response.text
@@ -146,7 +157,7 @@ def test_update_collection(client: TestClient, collection: Collection) -> None:
146157
assert response.json()["type"] == "Collection"
147158

148159

149-
def test_patch_collection(client: TestClient) -> None:
160+
def test_patch_operation_collection(client: TestClient) -> None:
150161
response = client.patch(
151162
"/collections/a-collection",
152163
content='[{"op": "add", "path": "/properties/foo", "value": "bar"}]',
@@ -158,6 +169,16 @@ def test_patch_collection(client: TestClient) -> None:
158169
]
159170

160171

172+
def test_patch_merge_collection(client: TestClient, collection: Collection) -> None:
173+
response = client.patch(
174+
"/collections/a-collection",
175+
content=json.dumps(collection),
176+
)
177+
assert response.is_success, response.text
178+
assert response.json()["path_collection_id"] == "a-collection"
179+
assert response.json()["patch"]["type"] == "Collection"
180+
181+
161182
def test_delete_collection(client: TestClient, collection: Collection) -> None:
162183
response = client.delete("/collections/a-collection")
163184
assert response.is_success, response.text

stac_fastapi/types/stac_fastapi/types/stac.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -198,33 +198,33 @@ def operations(self) -> List[PatchOperation]:
198198
class PartialCollection(BasePartial):
199199
"""Partial STAC Collection."""
200200

201-
type: Optional[str]
202-
stac_version: Optional[str]
203-
stac_extensions: Optional[List[str]]
204-
id: Optional[str]
205-
title: Optional[str]
206-
description: Optional[str]
207-
links: List[Dict[str, Any]]
208-
keywords: Optional[List[str]]
209-
license: Optional[str]
210-
providers: Optional[List[Dict[str, Any]]]
211-
extent: Optional[Dict[str, Any]]
212-
summaries: Optional[Dict[str, Any]]
213-
assets: Optional[Dict[str, Any]]
201+
type: Optional[str] = None
202+
stac_version: Optional[str] = None
203+
stac_extensions: Optional[List[str]] = None
204+
id: Optional[str] = None
205+
title: Optional[str] = None
206+
description: Optional[str] = None
207+
links: List[Dict[str, Any]] = None
208+
keywords: Optional[List[str]] = None
209+
license: Optional[str] = None
210+
providers: Optional[List[Dict[str, Any]]] = None
211+
extent: Optional[Dict[str, Any]] = None
212+
summaries: Optional[Dict[str, Any]] = None
213+
assets: Optional[Dict[str, Any]] = None
214214
numberMatched: Optional[int] = None
215215
numberReturned: Optional[int] = None
216216

217217

218218
class PartialItem(BasePartial):
219219
"""Partial STAC Item."""
220220

221-
type: Optional[Literal["Feature"]]
222-
stac_version: Optional[str]
223-
stac_extensions: Optional[List[str]]
224-
id: Optional[str]
225-
geometry: Optional[Dict[str, Any]]
226-
bbox: Optional[BBox]
227-
properties: Optional[Dict[str, Any]]
228-
links: Optional[List[Dict[str, Any]]]
229-
assets: Optional[Dict[str, Any]]
230-
collection: Optional[str]
221+
type: Optional[Literal["Feature"]] = None
222+
stac_version: Optional[str] = None
223+
stac_extensions: Optional[List[str]] = None
224+
id: Optional[str] = None
225+
geometry: Optional[Dict[str, Any]] = None
226+
bbox: Optional[BBox] = None
227+
properties: Optional[Dict[str, Any]] = None
228+
links: Optional[List[Dict[str, Any]]] = None
229+
assets: Optional[Dict[str, Any]] = None
230+
collection: Optional[str] = None

0 commit comments

Comments
 (0)