From c53c412c512699405a63e9ea28c7c33957f8a4ec Mon Sep 17 00:00:00 2001 From: Lennon McCartney Date: Wed, 13 Nov 2019 01:01:10 -0500 Subject: [PATCH] adding iterator to the Card class (#31) * adding iterator to the Card class * removing yaml file and updating a test * changing the fixture name --- mtgsdk/card.py | 6 ++++++ tests/test_card.py | 9 +++++++-- tests/test_type.py | 4 ++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/mtgsdk/card.py b/mtgsdk/card.py index fa4b8b8..c848aee 100644 --- a/mtgsdk/card.py +++ b/mtgsdk/card.py @@ -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() diff --git a/tests/test_card.py b/tests/test_card.py index 60d3133..40a595e 100644 --- a/tests/test_card.py +++ b/tests/test_card.py @@ -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) @@ -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) diff --git a/tests/test_type.py b/tests/test_type.py index 3b6139a..a796bfe 100644 --- a/tests/test_type.py +++ b/tests/test_type.py @@ -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)