Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: other languages not working #2

Merged
merged 1 commit into from
Oct 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions src/tcgdexsdk/endpoints/Endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
50 changes: 50 additions & 0 deletions tests/.fixtures/test_fr.yaml
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Loading