Skip to content

Commit 858f3ea

Browse files
authored
fix: other languages not working (#2)
1 parent 4eef4dd commit 858f3ea

File tree

3 files changed

+63
-7
lines changed

3 files changed

+63
-7
lines changed

src/tcgdexsdk/endpoints/Endpoint.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,8 @@ def __init__(self,
2626
self.endpoint = endpoint
2727

2828
async def get(self, id: str) -> Optional[Item]:
29-
return fetch(self.tcgdex, f"https://api.tcgdex.net/v2/en/{self.endpoint}/{id}", self.item_model)
29+
print(self.tcgdex.language)
30+
return fetch(self.tcgdex, f"https://api.tcgdex.net/v2/{self.tcgdex.language}/{self.endpoint}/{id}", self.item_model)
3031

3132
async def list(self, query: Optional[Query] = None) -> List[ListModel]:
32-
return fetch_list(self.tcgdex, f"https://api.tcgdex.net/v2/en/{self.endpoint}", self.list_model)
33-
34-
# Usage example (you'd replace with actual implementations):
35-
# endpoint = Endpoint(tcgdex_instance, ItemModel, ListModel, 'cards')
36-
# item = await endpoint.get('some_id')
37-
# items_list = await endpoint.list(some_query)
33+
return fetch_list(self.tcgdex, f"https://api.tcgdex.net/v2/{self.tcgdex.language}/{self.endpoint}", self.list_model)

tests/.fixtures/test_fr.yaml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
interactions:
2+
- request:
3+
body: null
4+
headers:
5+
Connection:
6+
- close
7+
Host:
8+
- api.tcgdex.net
9+
User-Agent:
10+
- '@tcgdex/python-sdk@0.1.0'
11+
method: GET
12+
uri: https://api.tcgdex.net/v2/fr/cards/swsh3-136
13+
response:
14+
body:
15+
string: "{\"category\":\"Pok\xE9mon\",\"id\":\"swsh3-136\",\"illustrator\":\"tetsuya
16+
koizumi\",\"image\":\"https://assets.tcgdex.net/fr/swsh/swsh3/136\",\"localId\":\"136\",\"name\":\"Fouinar\",\"rarity\":\"Peu
17+
Commune\",\"set\":{\"cardCount\":{\"official\":189,\"total\":201},\"id\":\"swsh3\",\"logo\":\"https://assets.tcgdex.net/fr/swsh/swsh3/logo\",\"name\":\"T\xE9n\xE8bres
18+
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
19+
1\",\"attacks\":[{\"cost\":[\"Incolore\"],\"name\":\"Mode Cool\",\"effect\":\"Piochez
20+
3 cartes.\"},{\"cost\":[\"Incolore\"],\"name\":\"\xC9clate-Queue\",\"effect\":\"Lancez
21+
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\"}"
22+
headers:
23+
Access-Control-Allow-Headers:
24+
- DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range
25+
Access-Control-Allow-Methods:
26+
- GET,POST,OPTIONS
27+
Access-Control-Allow-Origin:
28+
- '*'
29+
Access-Control-Expose-Headers:
30+
- Content-Length,Content-Range
31+
Alt-Svc:
32+
- h3=":443"; ma=2592000
33+
Cache-Control:
34+
- no-cache, no-store, must-revalidate
35+
Connection:
36+
- close
37+
Content-Length:
38+
- '941'
39+
Content-Type:
40+
- application/json; charset=utf-8
41+
Date:
42+
- Sat, 19 Oct 2024 10:11:27 GMT
43+
Etag:
44+
- W/"3ad-GxFMqSJRz7F04mM69E8WZDa57k0"
45+
X-Powered-By:
46+
- Express
47+
status:
48+
code: 200
49+
message: OK
50+
version: 1

tests/tests.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@ class APITest(unittest.IsolatedAsyncioTestCase):
2121
def setUp(self):
2222
self.api = TCGdex(Language.EN)
2323

24+
@_use_cassette
25+
async def test_fr(self):
26+
tcg = TCGdex(Language.FR)
27+
res = await tcg.card.get('swsh3-136')
28+
self.assertEqual(res.name, 'Fouinar')
29+
tcg2 = TCGdex('fr')
30+
res = await tcg2.card.get('swsh3-136')
31+
self.assertEqual(res.name, 'Fouinar')
32+
33+
2434
@_use_cassette
2535
async def test_card_resume(self):
2636
res = await self.api.card.list()

0 commit comments

Comments
 (0)