diff --git a/CHANGELOG.md b/CHANGELOG.md index b661e56..18858f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## unreleased +### Fixed + +- Add parameter method as "POST" to create-order link + ## Added - Add constants for route names to be used in link href generation diff --git a/src/stapi_fastapi/routers/product_router.py b/src/stapi_fastapi/routers/product_router.py index 0d98753..633c033 100644 --- a/src/stapi_fastapi/routers/product_router.py +++ b/src/stapi_fastapi/routers/product_router.py @@ -210,6 +210,7 @@ def get_product(self, request: Request) -> Product: ), rel="create-order", type=TYPE_JSON, + method="POST", ), ] diff --git a/tests/conftest.py b/tests/conftest.py index d9b80a8..2b6d659 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -143,11 +143,14 @@ def _assert_link( rel: str, path: str, media_type: str = "application/json", + method: str | None = None, ): link = find_link(body["links"], rel) assert link, f"{req} Link[rel={rel}] should exist" assert link["type"] == media_type assert link["href"] == url_for(path) + if method: + assert link["method"] == method return _assert_link diff --git a/tests/test_opportunity.py b/tests/test_opportunity.py index e22a614..9e93a20 100644 --- a/tests/test_opportunity.py +++ b/tests/test_opportunity.py @@ -27,7 +27,13 @@ def test_search_opportunities_response( except Exception as _: pytest.fail("response is not an opportunity collection") - assert_link(f"POST {url}", body, "create-order", f"/products/{product_id}/orders") + assert_link( + f"POST {url}", + body, + "create-order", + f"/products/{product_id}/orders", + method="POST", + ) @pytest.mark.parametrize("limit", [0, 1, 2, 4]) diff --git a/tests/test_opportunity_async.py b/tests/test_opportunity_async.py index a3bba17..b594898 100644 --- a/tests/test_opportunity_async.py +++ b/tests/test_opportunity_async.py @@ -205,6 +205,7 @@ def test_async_opportunity_search_to_completion( rel="create-order", href=url_for(f"/products/{product_id}/orders"), body=search_record.opportunity_request.model_dump(), + method="POST", ) ) collection.links.append( diff --git a/tests/test_product.py b/tests/test_product.py index 20c3316..b9e400b 100644 --- a/tests/test_product.py +++ b/tests/test_product.py @@ -38,7 +38,9 @@ def test_product_response_self_link( url, body, "order-parameters", f"/products/{product_id}/order-parameters" ) assert_link(url, body, "opportunities", f"/products/{product_id}/opportunities") - assert_link(url, body, "create-order", f"/products/{product_id}/orders") + assert_link( + url, body, "create-order", f"/products/{product_id}/orders", method="POST" + ) @pytest.mark.parametrize("product_id", ["test-spotlight"]) @@ -100,6 +102,7 @@ def test_get_products_pagination( "href": f"http://stapiserver/products/{product_id}/orders", "rel": "create-order", "type": "application/json", + "method": "POST", }, { "href": f"http://stapiserver/products/{product_id}/opportunities",