From 2fa1fde9ea2ad3bcb32bce9749d251de6253fa78 Mon Sep 17 00:00:00 2001 From: Avior Date: Sat, 19 Oct 2024 12:13:12 +0200 Subject: [PATCH] fix: other languages not working Signed-off-by: Avior --- src/tcgdexsdk/endpoints/Endpoint.py | 10 ++---- tests/.fixtures/test_fr.yaml | 50 +++++++++++++++++++++++++++++ tests/tests.py | 10 ++++++ 3 files changed, 63 insertions(+), 7 deletions(-) create mode 100644 tests/.fixtures/test_fr.yaml diff --git a/src/tcgdexsdk/endpoints/Endpoint.py b/src/tcgdexsdk/endpoints/Endpoint.py index 8cdb2e3..e6fa7ee 100644 --- a/src/tcgdexsdk/endpoints/Endpoint.py +++ b/src/tcgdexsdk/endpoints/Endpoint.py @@ -26,12 +26,8 @@ def __init__(self, self.endpoint = endpoint async def get(self, id: str) -> Optional[Item]: - return fetch(self.tcgdex, f"https://api.tcgdex.net/v2/en/{self.endpoint}/{id}", self.item_model) + print(self.tcgdex.language) + return fetch(self.tcgdex, f"https://api.tcgdex.net/v2/{self.tcgdex.language}/{self.endpoint}/{id}", self.item_model) async def list(self, query: Optional[Query] = None) -> List[ListModel]: - return fetch_list(self.tcgdex, f"https://api.tcgdex.net/v2/en/{self.endpoint}", self.list_model) - -# Usage example (you'd replace with actual implementations): -# endpoint = Endpoint(tcgdex_instance, ItemModel, ListModel, 'cards') -# item = await endpoint.get('some_id') -# items_list = await endpoint.list(some_query) + return fetch_list(self.tcgdex, f"https://api.tcgdex.net/v2/{self.tcgdex.language}/{self.endpoint}", self.list_model) diff --git a/tests/.fixtures/test_fr.yaml b/tests/.fixtures/test_fr.yaml new file mode 100644 index 0000000..7cee3e2 --- /dev/null +++ b/tests/.fixtures/test_fr.yaml @@ -0,0 +1,50 @@ +interactions: +- request: + body: null + headers: + Connection: + - close + Host: + - api.tcgdex.net + User-Agent: + - '@tcgdex/python-sdk@0.1.0' + method: GET + uri: https://api.tcgdex.net/v2/fr/cards/swsh3-136 + response: + body: + string: "{\"category\":\"Pok\xE9mon\",\"id\":\"swsh3-136\",\"illustrator\":\"tetsuya + koizumi\",\"image\":\"https://assets.tcgdex.net/fr/swsh/swsh3/136\",\"localId\":\"136\",\"name\":\"Fouinar\",\"rarity\":\"Peu + Commune\",\"set\":{\"cardCount\":{\"official\":189,\"total\":201},\"id\":\"swsh3\",\"logo\":\"https://assets.tcgdex.net/fr/swsh/swsh3/logo\",\"name\":\"T\xE9n\xE8bres + Embras\xE9es\",\"symbol\":\"https://assets.tcgdex.net/univ/swsh/swsh3/symbol\"},\"variants\":{\"firstEdition\":false,\"holo\":false,\"normal\":true,\"reverse\":true,\"wPromo\":false},\"dexId\":[162],\"hp\":110,\"types\":[\"Incolore\"],\"evolveFrom\":\"Fouinette\",\"stage\":\"Niveau + 1\",\"attacks\":[{\"cost\":[\"Incolore\"],\"name\":\"Mode Cool\",\"effect\":\"Piochez + 3 cartes.\"},{\"cost\":[\"Incolore\"],\"name\":\"\xC9clate-Queue\",\"effect\":\"Lancez + une pi\xE8ce. Si c'est pile, cette attaque ne fait rien.\",\"damage\":90}],\"weaknesses\":[{\"type\":\"Combat\",\"value\":\"\xD72\"}],\"retreat\":1,\"regulationMark\":\"D\",\"legal\":{\"standard\":false,\"expanded\":true},\"updated\":\"2024-06-18T00:34:39+02:00\"}" + headers: + Access-Control-Allow-Headers: + - DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range + Access-Control-Allow-Methods: + - GET,POST,OPTIONS + Access-Control-Allow-Origin: + - '*' + Access-Control-Expose-Headers: + - Content-Length,Content-Range + Alt-Svc: + - h3=":443"; ma=2592000 + Cache-Control: + - no-cache, no-store, must-revalidate + Connection: + - close + Content-Length: + - '941' + Content-Type: + - application/json; charset=utf-8 + Date: + - Sat, 19 Oct 2024 10:11:27 GMT + Etag: + - W/"3ad-GxFMqSJRz7F04mM69E8WZDa57k0" + X-Powered-By: + - Express + status: + code: 200 + message: OK +version: 1 diff --git a/tests/tests.py b/tests/tests.py index a09a829..d91f88d 100644 --- a/tests/tests.py +++ b/tests/tests.py @@ -21,6 +21,16 @@ class APITest(unittest.IsolatedAsyncioTestCase): def setUp(self): self.api = TCGdex(Language.EN) + @_use_cassette + async def test_fr(self): + tcg = TCGdex(Language.FR) + res = await tcg.card.get('swsh3-136') + self.assertEqual(res.name, 'Fouinar') + tcg2 = TCGdex('fr') + res = await tcg2.card.get('swsh3-136') + self.assertEqual(res.name, 'Fouinar') + + @_use_cassette async def test_card_resume(self): res = await self.api.card.list()