From 8188542ca2687d5ee065de52c0f4cfbb0a8a6089 Mon Sep 17 00:00:00 2001 From: Aaron <7063649+ahcodedev@users.noreply.github.com> Date: Sun, 8 Nov 2026 14:26:13 -0800 Subject: [PATCH 1/2] Add Pricecharting routes --- src/pypricecharting/route.py | 35 ++++++++++++++++++++++ tests/test_route.py | 57 ++++++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 src/pypricecharting/route.py create mode 100644 tests/test_route.py diff --git a/src/pypricecharting/route.py b/src/pypricecharting/route.py new file mode 100644 index 0000000..69dbb87 --- /dev/null +++ b/src/pypricecharting/route.py @@ -0,0 +1,35 @@ +from enum import Enum, unique + +# Source: https://www.pricecharting.com/api-documentation + + +BASE_URL = "https://www.pricecharting.com" + + +@unique +class Prices(Enum): + """PriceCharting Prices API Routes""" + + PRODUCT = "/api/product" + PRODUCTS = "/api/products" + + +@unique +class MarketPlace(Enum): + """PriceCharting MarketPlace API Routes""" + + OFFERS = "/api/offers" + OFFER_PUBLISH = "/api/offer-publish" + OFFER_DETAILS = "/api/offer-details" + OFFER_FEEDBACK = "/api/offer-feedback" + OFFER_SHIP = "/api/offer-ship" + OFFER_END = "/api/offer-end" + OFFER_REFUND = "/api/offer-refund" + + +@unique +class Route(Enum): + """PriceCharting API Routes""" + + PRICES = Prices + MARKETPLACE = MarketPlace diff --git a/tests/test_route.py b/tests/test_route.py new file mode 100644 index 0000000..916b017 --- /dev/null +++ b/tests/test_route.py @@ -0,0 +1,57 @@ +import pytest + +from pypricecharting.route import MarketPlace, Prices, Route + +# Source: https://www.pricecharting.com/api-documentation + + +def test_prices_route(): + assert len(Prices) == 2 + assert Prices.PRODUCT.value == "/api/product" + assert Prices.PRODUCTS.value == "/api/products" + + +def test_prices_lookup_by_value(): + for member in Prices: + assert Prices(member.value) is member + + +def test_prices_unknown_value_raises(): + with pytest.raises(ValueError, match="is not a valid"): + Prices("Invalid Route") + + +def test_marketplace_route(): + assert len(MarketPlace) == 7 + assert MarketPlace.OFFERS.value == "/api/offers" + assert MarketPlace.OFFER_PUBLISH.value == "/api/offer-publish" + assert MarketPlace.OFFER_DETAILS.value == "/api/offer-details" + assert MarketPlace.OFFER_FEEDBACK.value == "/api/offer-feedback" + assert MarketPlace.OFFER_SHIP.value == "/api/offer-ship" + assert MarketPlace.OFFER_END.value == "/api/offer-end" + + +def test_marketplace_lookup_by_value(): + for member in MarketPlace: + assert MarketPlace(member.value) is member + + +def test_marketplace_unknown_value_raises(): + with pytest.raises(ValueError, match="is not a valid"): + MarketPlace("Invalid Route") + + +def test_route_routes(): + assert len(Route) == 2 + assert Route.MARKETPLACE.value is MarketPlace + assert Route.PRICES.value is Prices + + +def test_genre_lookup_by_value(): + for member in Route: + assert Route(member.value) is member + + +def test_route_unknown_value_raises(): + with pytest.raises(ValueError, match="is not a valid"): + Route("Invalid Route") From 9e1a5b8e5b6ae3c66a82cc0ee9b05e29a385ed08 Mon Sep 17 00:00:00 2001 From: Aaron <7063649+ahcodedev@users.noreply.github.com> Date: Sun, 8 Nov 2026 14:59:23 -0800 Subject: [PATCH 2/2] Add Pricecharting API routes, add initial client template code --- pyproject.toml | 3 + src/pypricecharting/asyncpricecharting.py | 66 ++++++++++++++ src/pypricecharting/pypricecharting.py | 66 ++++++++++++++ tests/test_asyncpricecharting.py | 103 ++++++++++++++++++++++ tests/test_pricecharting.py | 102 +++++++++++++++++++++ uv.lock | 14 +++ 6 files changed, 354 insertions(+) create mode 100644 src/pypricecharting/asyncpricecharting.py create mode 100644 src/pypricecharting/pypricecharting.py create mode 100644 tests/test_asyncpricecharting.py create mode 100644 tests/test_pricecharting.py diff --git a/pyproject.toml b/pyproject.toml index e6b5408..babaab9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -18,6 +18,7 @@ dev = [ "codespell>=2.4.3", "prek>=0.5.10", "pytest", + "pytest-asyncio>=1.4.1.post1", "pytest-cov", "ruff>=0.16.0", "ty>=0.0.96", @@ -29,6 +30,8 @@ ignore-words-list = "gameboy" [tool.pytest.ini_options] addopts = "--cov=src --cov-report=term-missing --cov-fail-under 98" +asyncio_mode = "auto" +asyncio_default_fixture_loop_scope = "function" [tool.ruff] line-length = 100 diff --git a/src/pypricecharting/asyncpricecharting.py b/src/pypricecharting/asyncpricecharting.py new file mode 100644 index 0000000..41d70a2 --- /dev/null +++ b/src/pypricecharting/asyncpricecharting.py @@ -0,0 +1,66 @@ +from types import TracebackType +from typing import Self + +from httpx2 import AsyncClient + + +class AsyncPyPriceCharting: + """Asynchronous PriceCharting API client.""" + + def __init__(self, credential: str): + """Create a client authenticated with a PriceCharting API token.""" + self.credential = credential + self.client = AsyncClient() + + async def aclose(self): + """Close the underlying HTTP client.""" + await self.client.aclose() + + async def __aenter__(self) -> Self: + """Enter the async context and return the client.""" + return self + + async def __aexit__( + self, + exc_type: type[BaseException] | None, + exc_value: BaseException | None, + traceback: TracebackType | None, + ) -> None: + """Close the underlying HTTP client on exit.""" + await self.aclose() + + async def product(self): + """Get a single product.""" + pass + + async def products(self): + """Search for products.""" + pass + + async def offers(self): + """List marketplace offers.""" + pass + + async def offer_details(self): + """Get the details of a marketplace offer.""" + pass + + async def offer_publish(self): + """Publish a new marketplace offer.""" + pass + + async def offer_feedback(self): + """Leave feedback on a marketplace offer.""" + pass + + async def offer_ship(self): + """Mark a marketplace offer as shipped.""" + pass + + async def offer_end(self): + """End a marketplace offer.""" + pass + + async def offer_refund(self): + """Refund a marketplace offer.""" + pass diff --git a/src/pypricecharting/pypricecharting.py b/src/pypricecharting/pypricecharting.py new file mode 100644 index 0000000..6bf374b --- /dev/null +++ b/src/pypricecharting/pypricecharting.py @@ -0,0 +1,66 @@ +from types import TracebackType +from typing import Self + +from httpx2 import Client + + +class PyPriceCharting: + """Synchronous PriceCharting API client.""" + + def __init__(self, credential: str): + """Create a client authenticated with a PriceCharting API token.""" + self.credential = credential + self.client = Client() + + def close(self): + """Close the underlying HTTP client.""" + self.client.close() + + def __enter__(self) -> Self: + """Enter the context and return the client.""" + return self + + def __exit__( + self, + exc_type: type[BaseException] | None, + exc_value: BaseException | None, + traceback: TracebackType | None, + ) -> None: + """Close the underlying HTTP client on exit.""" + self.close() + + def product(self): + """Get a single product.""" + pass + + def products(self): + """Search for products.""" + pass + + def offers(self): + """List marketplace offers.""" + pass + + def offer_details(self): + """Get the details of a marketplace offer.""" + pass + + def offer_publish(self): + """Publish a new marketplace offer.""" + pass + + def offer_feedback(self): + """Leave feedback on a marketplace offer.""" + pass + + def offer_ship(self): + """Mark a marketplace offer as shipped.""" + pass + + def offer_end(self): + """End a marketplace offer.""" + pass + + def offer_refund(self): + """Refund a marketplace offer.""" + pass diff --git a/tests/test_asyncpricecharting.py b/tests/test_asyncpricecharting.py new file mode 100644 index 0000000..df47431 --- /dev/null +++ b/tests/test_asyncpricecharting.py @@ -0,0 +1,103 @@ +import pytest +from httpx2 import AsyncClient + +from pypricecharting.asyncpricecharting import AsyncPyPriceCharting + +# Template tests: the API methods are placeholders, so these only check they can be called. +# Replace the `is None` assertions once each method is implemented. + +TOKEN = "test-token" + + +async def test_init_stores_credential(): + client = AsyncPyPriceCharting(TOKEN) + assert client.credential == TOKEN + await client.aclose() + + +async def test_init_creates_http_client(): + client = AsyncPyPriceCharting(TOKEN) + assert isinstance(client.client, AsyncClient) + assert not client.client.is_closed + await client.aclose() + + +async def test_aclose_closes_http_client(): + client = AsyncPyPriceCharting(TOKEN) + await client.aclose() + assert client.client.is_closed + + +async def test_async_with_returns_client(): + client = AsyncPyPriceCharting(TOKEN) + async with client as entered: + assert entered is client + assert not client.client.is_closed + + +async def test_async_with_closes_http_client(): + async with AsyncPyPriceCharting(TOKEN) as client: + pass + assert client.client.is_closed + + +async def test_async_with_closes_http_client_on_error(): + client = AsyncPyPriceCharting(TOKEN) + with pytest.raises(ValueError, match="boom"): + async with client: + raise ValueError("boom") + assert client.client.is_closed + + +async def test_product(): + client = AsyncPyPriceCharting(TOKEN) + assert await client.product() is None + await client.aclose() + + +async def test_products(): + client = AsyncPyPriceCharting(TOKEN) + assert await client.products() is None + await client.aclose() + + +async def test_offers(): + client = AsyncPyPriceCharting(TOKEN) + assert await client.offers() is None + await client.aclose() + + +async def test_offer_details(): + client = AsyncPyPriceCharting(TOKEN) + assert await client.offer_details() is None + await client.aclose() + + +async def test_offer_publish(): + client = AsyncPyPriceCharting(TOKEN) + assert await client.offer_publish() is None + await client.aclose() + + +async def test_offer_feedback(): + client = AsyncPyPriceCharting(TOKEN) + assert await client.offer_feedback() is None + await client.aclose() + + +async def test_offer_ship(): + client = AsyncPyPriceCharting(TOKEN) + assert await client.offer_ship() is None + await client.aclose() + + +async def test_offer_end(): + client = AsyncPyPriceCharting(TOKEN) + assert await client.offer_end() is None + await client.aclose() + + +async def test_offer_refund(): + client = AsyncPyPriceCharting(TOKEN) + assert await client.offer_refund() is None + await client.aclose() diff --git a/tests/test_pricecharting.py b/tests/test_pricecharting.py new file mode 100644 index 0000000..f0bd18a --- /dev/null +++ b/tests/test_pricecharting.py @@ -0,0 +1,102 @@ +import pytest +from httpx2 import Client + +from pypricecharting.pypricecharting import PyPriceCharting + +# Template tests: the API methods are placeholders, so these only check they can be called. +# Replace the `is None` assertions once each method is implemented. + +TOKEN = "test-token" + + +def test_init_stores_credential(): + client = PyPriceCharting(TOKEN) + assert client.credential == TOKEN + client.close() + + +def test_init_creates_http_client(): + client = PyPriceCharting(TOKEN) + assert isinstance(client.client, Client) + assert not client.client.is_closed + client.close() + + +def test_close_closes_http_client(): + client = PyPriceCharting(TOKEN) + client.close() + assert client.client.is_closed + + +def test_with_returns_client(): + client = PyPriceCharting(TOKEN) + with client as entered: + assert entered is client + assert not client.client.is_closed + + +def test_with_closes_http_client(): + with PyPriceCharting(TOKEN) as client: + pass + assert client.client.is_closed + + +def test_with_closes_http_client_on_error(): + client = PyPriceCharting(TOKEN) + with pytest.raises(ValueError, match="boom"), client: + raise ValueError("boom") + assert client.client.is_closed + + +def test_product(): + client = PyPriceCharting(TOKEN) + assert client.product() is None + client.close() + + +def test_products(): + client = PyPriceCharting(TOKEN) + assert client.products() is None + client.close() + + +def test_offers(): + client = PyPriceCharting(TOKEN) + assert client.offers() is None + client.close() + + +def test_offer_details(): + client = PyPriceCharting(TOKEN) + assert client.offer_details() is None + client.close() + + +def test_offer_publish(): + client = PyPriceCharting(TOKEN) + assert client.offer_publish() is None + client.close() + + +def test_offer_feedback(): + client = PyPriceCharting(TOKEN) + assert client.offer_feedback() is None + client.close() + + +def test_offer_ship(): + client = PyPriceCharting(TOKEN) + assert client.offer_ship() is None + client.close() + + +def test_offer_end(): + client = PyPriceCharting(TOKEN) + assert client.offer_end() is None + client.close() + + +def test_offer_refund(): + client = PyPriceCharting(TOKEN) + assert client.offer_refund() is None + client.close() diff --git a/uv.lock b/uv.lock index 6ca90b7..f0ef9cd 100644 --- a/uv.lock +++ b/uv.lock @@ -263,6 +263,7 @@ dev = [ { name = "codespell" }, { name = "prek" }, { name = "pytest" }, + { name = "pytest-asyncio" }, { name = "pytest-cov" }, { name = "ruff" }, { name = "ty" }, @@ -279,6 +280,7 @@ dev = [ { name = "codespell", specifier = ">=2.4.3" }, { name = "prek", specifier = ">=0.5.10" }, { name = "pytest" }, + { name = "pytest-asyncio", specifier = ">=1.4.1.post1" }, { name = "pytest-cov" }, { name = "ruff", specifier = ">=0.16.0" }, { name = "ty", specifier = ">=0.0.96" }, @@ -300,6 +302,18 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/51/39/1f5d8c8877a0fa327db959c19341d4be61660de1ab6b7391f9eb805bcd67/pytest-9.2.0-py3-none-any.whl", hash = "sha256:07acdcf88ec174f907dc01af70bf52d49b014bbab03faeeade31c96b18c2e588", size = 411776, upload-time = "2026-10-27T21:30:19.131Z" }, ] +[[package]] +name = "pytest-asyncio" +version = "1.4.1.post1" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "pytest" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/73/7f/c60a4338420b33453d4f814ac0c930abd399f162b9bdd21af4b9e363037f/pytest_asyncio-1.4.1.post1.tar.gz", hash = "sha256:f582d9ea4a1c082195abe8bd29a1fe106aeb1cd435e3dad2d3bc2749935c36a2", size = 145360, upload-time = "2026-11-01T18:26:03.732Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/e3/de/adbc7578959cfab07e5e7c05cf6d54224a51e7667ea2c07458b6bc571e75/pytest_asyncio-1.4.1.post1-py3-none-any.whl", hash = "sha256:0755e488cc0a2b9bd2eab7292cc6390d4cbb8390f1020745647bae5a708e0165", size = 17140, upload-time = "2026-11-01T18:26:02.168Z" }, +] + [[package]] name = "pytest-cov" version = "7.1.0"