Skip to content
Merged
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
8 changes: 7 additions & 1 deletion stapi-pydantic/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added

- `OrderStatus.new` ([#116](https://github.com/stapi-spec/pystapi/pull/116))

## [0.0.3] - 2025-04-24

### Added
Expand All @@ -28,7 +34,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),

Initial release.

<!-- [unreleased]: https://github.com/stapi-spec/pystapi/compare/stac-pydantic/stapi-pydantic%2Fv0.0.2...main -->
[unreleased]: https://github.com/stapi-spec/pystapi/compare/stac-pydantic/stapi-pydantic%2Fv0.0.3...main
[0.0.3]: https://github.com/stapi-spec/pystapi/compare/stac-pydantic/stapi-pydantic%2Fv0.0.2...stapi-pydantic%2Fv0.0.3
[0.0.2]: https://github.com/stapi-spec/pystapi/compare/stac-pydantic/stapi-pydantic%2Fv0.0.1...stapi-pydantic%2Fv0.0.2
[0.0.1]: https://github.com/stapi-spec/pystapi/releases/tag/stapi-pydantic%2Fv0.0.1
15 changes: 15 additions & 0 deletions stapi-pydantic/src/stapi_pydantic/order.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from __future__ import annotations

import datetime
from collections.abc import Iterator
from enum import StrEnum
from typing import Any, Generic, Literal, TypeVar
Expand Down Expand Up @@ -56,6 +59,18 @@ class OrderStatus(BaseModel):

model_config = ConfigDict(extra="allow")

@classmethod
def new(
cls, status_code: OrderStatusCode, reason_code: str | None = None, reason_text: str | None = None
) -> OrderStatus:
"""Creates a new order status with timestamp set to now in UTC."""
return OrderStatus(
timestamp=datetime.datetime.now(tz=datetime.UTC),
status_code=status_code,
reason_code=reason_code,
reason_text=reason_text,
)


T = TypeVar("T", bound=OrderStatus)

Expand Down
12 changes: 12 additions & 0 deletions stapi-pydantic/tests/test_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import datetime

from stapi_pydantic import OrderStatus, OrderStatusCode


def test_order_status_new() -> None:
status = OrderStatus.new(OrderStatusCode.accepted)
assert status.timestamp.tzinfo == datetime.UTC
assert status.status_code == OrderStatusCode.accepted
assert status.reason_code is None
assert status.reason_text is None
assert status.links == []