Skip to content

Commit

Permalink
adding iterator to the Card class (#31)
Browse files Browse the repository at this point in the history
* adding iterator to the Card class

* removing yaml file and updating a test

* changing the fixture name
  • Loading branch information
lmccartney authored and adback03 committed Nov 13, 2019
1 parent d9d1231 commit c53c412
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
6 changes: 6 additions & 0 deletions mtgsdk/card.py
Expand Up @@ -45,4 +45,10 @@ def where(**kwargs):

@staticmethod
def all():
"""Returns a list of all Card instances"""
return QueryBuilder(__class__).all()

@staticmethod
def iter():
"""Iterate over all Card instances"""
return QueryBuilder(__class__).iter()
9 changes: 7 additions & 2 deletions tests/test_card.py
Expand Up @@ -42,7 +42,7 @@ def test_find_returns_card(self):
self.assertTrue({"name":"Scelta della Dannazione","text" : "L'avversario bersaglio sceglie un numero. Puoi far perdere a quel giocatore un ammontare di punti vita pari a quel numero. Se non lo fai, quel giocatore sacrifica tutti i permanenti tranne un numero di permanenti pari al numero scelto.","flavor" : "\"La vita è una sequela di scelte tra male e peggio.\"\n—Toshiro Umezawa","imageUrl":"http://gatherer.wizards.com/Handlers/Image.ashx?multiverseid=105393&type=card","language":"Italian","multiverseid":105393} in card.foreign_names)
self.assertTrue('SOK' in card.printings)
self.assertEqual("Target opponent chooses a number. You may have that player lose that much life. If you don't, that player sacrifices all but that many permanents.", card.original_text)
self.assertEqual('Sorcery - Arcane', card.original_type)
self.assertEqual('Sorcery - Arcane', card.original_type)
self.assertTrue({"format":"Commander","legality":"Legal"} in card.legalities)
self.assertEqual('224a2a63-7be6-5e06-bf6b-e667727bf80b', card.id)

Expand All @@ -63,5 +63,10 @@ def test_all_with_page_returns_cards(self):
def test_all_with_page_and_page_size_returns_card(self):
with vcr.use_cassette('fixtures/all_first_page_one_card.yaml'):
cards = Card.where(page=1).where(pageSize=1).all()

self.assertEqual(1, len(cards))

def test_iter_with_no_where_returns_card(self):
with vcr.use_cassette('fixtures/cards_no_args.yaml'):
card = next(Card.iter())
self.assertIsInstance(card, Card)
4 changes: 2 additions & 2 deletions tests/test_type.py
Expand Up @@ -19,5 +19,5 @@ def test_all_returns_types(self):

#API returns some erroneous values, but this line is correct
#Remove temporary line and uncomment this line when API is updated
#self.assertEqual(["Artifact","Card","Conspiracy","Creature","Emblem","Enchantment","Host","Instant","Land","Phenomenon","Plane","Planeswalker","Scheme","Sorcery","Summon","Tribal","Vanguard","You'll"], types)
self.assertEqual(["Artifact","Card","Conspiracy","Creature","Emblem","Enchantment","Hero","instant","Instant","Land","Phenomenon","Plane","Planeswalker","Scheme","Sorcery","Summon","Tribal","Vanguard","You’ll"], types)
# self.assertEqual(["Artifact","Card","Conspiracy","Creature","Emblem","Enchantment","Host","Instant","Land","Phenomenon","Plane","Planeswalker","Scheme","Sorcery","Summon","Tribal","Vanguard","You'll"], types)
self.assertEqual(["Artifact","Conspiracy","Creature","Enchantment","Hero","instant","Instant","Land","Phenomenon","Plane","Planeswalker","Scheme","Sorcery","Summon","Tribal","Vanguard","You’ll"], types)

0 comments on commit c53c412

Please sign in to comment.