Skip to content

Commit 3221382

Browse files
authored
feat: add OrderStatus.new (#116)
## What I'm changing - Adds `OrderStatus.new` - Closes #115 ## Checklist - [x] Tests pass: `uv run pytest` - [x] Checks pass: `uv run pre-commit run --all-files` - [x] CHANGELOG is updated (if necessary)
1 parent 33c205c commit 3221382

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

stapi-pydantic/CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ All notable changes to this project will be documented in this file.
66

77
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).
88

9+
## [Unreleased]
10+
11+
### Added
12+
13+
- `OrderStatus.new` ([#116](https://github.com/stapi-spec/pystapi/pull/116))
14+
915
## [0.0.3] - 2025-04-24
1016

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

2935
Initial release.
3036

31-
<!-- [unreleased]: https://github.com/stapi-spec/pystapi/compare/stac-pydantic/stapi-pydantic%2Fv0.0.2...main -->
37+
[unreleased]: https://github.com/stapi-spec/pystapi/compare/stac-pydantic/stapi-pydantic%2Fv0.0.3...main
3238
[0.0.3]: https://github.com/stapi-spec/pystapi/compare/stac-pydantic/stapi-pydantic%2Fv0.0.2...stapi-pydantic%2Fv0.0.3
3339
[0.0.2]: https://github.com/stapi-spec/pystapi/compare/stac-pydantic/stapi-pydantic%2Fv0.0.1...stapi-pydantic%2Fv0.0.2
3440
[0.0.1]: https://github.com/stapi-spec/pystapi/releases/tag/stapi-pydantic%2Fv0.0.1

stapi-pydantic/src/stapi_pydantic/order.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
from __future__ import annotations
2+
3+
import datetime
14
from collections.abc import Iterator
25
from enum import StrEnum
36
from typing import Any, Generic, Literal, TypeVar
@@ -56,6 +59,18 @@ class OrderStatus(BaseModel):
5659

5760
model_config = ConfigDict(extra="allow")
5861

62+
@classmethod
63+
def new(
64+
cls, status_code: OrderStatusCode, reason_code: str | None = None, reason_text: str | None = None
65+
) -> OrderStatus:
66+
"""Creates a new order status with timestamp set to now in UTC."""
67+
return OrderStatus(
68+
timestamp=datetime.datetime.now(tz=datetime.UTC),
69+
status_code=status_code,
70+
reason_code=reason_code,
71+
reason_text=reason_text,
72+
)
73+
5974

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

stapi-pydantic/tests/test_order.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import datetime
2+
3+
from stapi_pydantic import OrderStatus, OrderStatusCode
4+
5+
6+
def test_order_status_new() -> None:
7+
status = OrderStatus.new(OrderStatusCode.accepted)
8+
assert status.timestamp.tzinfo == datetime.UTC
9+
assert status.status_code == OrderStatusCode.accepted
10+
assert status.reason_code is None
11+
assert status.reason_text is None
12+
assert status.links == []

0 commit comments

Comments
 (0)