Skip to content

Commit

Permalink
Switching from attrs to basemodel for patch operations.
Browse files Browse the repository at this point in the history
  • Loading branch information
rhysrevans3 committed Aug 28, 2024
1 parent 47a0b48 commit 13a2377
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 26 deletions.
12 changes: 3 additions & 9 deletions stac_fastapi/extensions/tests/test_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,7 @@ def test_merge_patch_item(client: TestClient, item: Item) -> None:


def test_json_patch_item(client: TestClient) -> None:
operations = [
{"op": "add", "path": "properties.new_prop", "value": "new_prop_value"}
]
operations = [{"op": "add", "path": "properties.new_prop", "value": "new_prop_value"}]
headers = {"Content-Type": "application/json-patch+json"}
response = client.patch(
"/collections/a-collection/items/an-item",
Expand Down Expand Up @@ -191,9 +189,7 @@ def test_merge_patch_collection(client: TestClient, collection: Collection) -> N


def test_json_patch_collection(client: TestClient) -> None:
operations = [
{"op": "add", "path": "summaries.new_prop", "value": "new_prop_value"}
]
operations = [{"op": "add", "path": "summaries.new_prop", "value": "new_prop_value"}]
headers = {"Content-Type": "application/json-patch+json"}
response = client.patch(
"/collections/a-collection/items/an-item",
Expand Down Expand Up @@ -273,9 +269,7 @@ def collection() -> Collection:
"description": "A test collection",
"extent": {
"spatial": {"bbox": [[-180, -90, 180, 90]]},
"temporal": {
"interval": [["2000-01-01T00:00:00Z", "2024-01-01T00:00:00Z"]]
},
"temporal": {"interval": [["2000-01-01T00:00:00Z", "2024-01-01T00:00:00Z"]]},
},
"links": [],
"assets": {},
Expand Down
3 changes: 1 addition & 2 deletions stac_fastapi/types/stac_fastapi/types/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
from stac_fastapi.types.requests import get_base_url
from stac_fastapi.types.rfc3339 import DateTimeType
from stac_fastapi.types.search import BaseSearchPostRequest
from stac_fastapi.types.stac import (PartialCollection, PartialItem,
PatchOperation)
from stac_fastapi.types.stac import PartialCollection, PartialItem, PatchOperation

__all__ = [
"NumType",
Expand Down
27 changes: 12 additions & 15 deletions stac_fastapi/types/stac_fastapi/types/stac.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from typing import Any, Dict, List, Literal, Optional, Union

import attr
from pydantic import BaseModel
from stac_pydantic.shared import BBox
from typing_extensions import TypedDict

Expand Down Expand Up @@ -110,31 +110,28 @@ class PartialItem(TypedDict, total=False):
collection: Optional[str]


@attr.s
class PatchAddReplaceTest:
class PatchAddReplaceTest(BaseModel):
"""Add, Replace or Test Operation."""

path: str = attr.ib()
op: Literal["add", "replace", "test"] = attr.ib()
value: Any = attr.ib()
path: str
op: Literal["add", "replace", "test"]
value: Any


@attr.s
class PatchRemove:
class PatchRemove(BaseModel):
"""Remove Operation."""

path: str = attr.ib()
op: Literal["remove"] = attr.ib()
path: str
op: Literal["remove"]


@attr.s
class PatchMoveCopy:
class PatchMoveCopy(BaseModel):
"""Move or Copy Operation."""

path: str = attr.ib()
op: Literal["move", "copy"] = attr.ib()
path: str
op: Literal["move", "copy"]

def __attrs_init__(self, *args, **kwargs):
def __init__(self, *args, **kwargs):
"""Init function to add 'from' field."""
super().__init__(*args, **kwargs)
self.__setattr__("from", kwargs["from"])
Expand Down

0 comments on commit 13a2377

Please sign in to comment.