def test_refetching_unicode_names_searched_with_ascii(self): # searches with ascii names sometimes return non-ascii results # and we want to make sure that's not a problem for ascii_name, unicode_name in [ ("AEther Vial", u'Æther Vial'), ("Juzam Djinn", u'Juzám Djinn'), ("Jotun Grunt", u'Jötun Grunt') ]: # fetch self.assertEqual(Card.get(unicode_name).name, unicode_name) # re-fetch self.assertEqual(Card.get(ascii_name).name, unicode_name)
def test_who_what_when_where_why(self): wwwww = Card.get('Who/What/When/Where/Why') self.assertIsInstance(wwwww, Card) self.assertEqual(wwwww.name, 'Who/What/When/Where/Why') self.assertEqual(wwwww.colors, {'White', 'Blue', 'Black', 'Red', 'Green'})
def _fix_pg_array_fields_in_serialized(serialized_card): card = None for field in ('_color_indicator', 'types', 'subtypes'): if isinstance(field, basestring): if card is None: card = Card.get(serialized_card['pk']) serialized_card['fields'][field] = getattr(card, field) return serialized_card
def test_unicode_in_weird_spots(self): # weird unicode apostrophes from copying and pasting a cube list from # some random website for name, fixed_name in ((u'Moment\u2019s Peace', "Moment's Peace"), (u'Æther Adept', u'Æther Adept'), (u"Gideon’s Lawkeeper", "Gideon's Lawkeeper"), (u"Night’s Whisper", "Night's Whisper")): self.assertEqual(Card.get(name).name, fixed_name)
def test_create_cards_given_names(self): for name, card_type in (('Zealous Conscripts', 'Creature'), ('Shelldock Isle', 'Land'), ('Sylvan Library', 'Enchantment')): fetched_card = Card.get(name) self.assertIsInstance(fetched_card, Card) self.assertIn(card_type, fetched_card.types) self.assertIn(fetched_card, Card.objects.all())
def assertHeuristicsArePresent(self, name, expected_subset, keys_that_are_not_present=()): actual = Card.get(name).heuristics try: for k in keys_that_are_not_present: self.assertNotIn(k, actual) self.assertDictContainsSubset(expected_subset, actual) except AssertionError as e: raise AssertionError(e.message + ' problem with %s' % name)
def assert_split_card_matches(self, search_name, name, colors): """ assert that the expectation matches for a given split card :param search_name: the string to search with :param name: the expected card name :param colors: the expected card colors :raise AssertionError: if the card doesn't match expectations """ fetched_card = Card.get(search_name) self.assertIsInstance(fetched_card, Card) self.assertEqual(name, fetched_card.name) self.assertEqual(colors, fetched_card.colors)
def test_handle_apostrophe_names(self): for name in ("Moment's Peace", "Sensei's Divining Top"): self.assertEqual(Card.get(name).name, name)
def test_fetching_unicode_names_with_ascii_text(self): self.assertEqual(Card.get("AEther Vial").name, u'Æther Vial') self.assertEqual(Card.get("Juzam Djinn").name, u'Juzám Djinn')
def test_handle_null_color_indicator(self): self.assertEqual(set(), Card.get('Ghostfire').colors)
def test_handle_color_indicator(self): self.assertEqual({'Blue'}, Card.get('Ancestral Vision').colors) self.assertEqual({'Green'}, Card.get('Dryad Arbor').colors) self.assertEqual({'White', 'Blue', 'Black', 'Red', 'Green'}, Card.get('Transguild Courier').colors)
def test_activated_abilities(self): self.assertEqual(['{1}{U}{B}'], Card.get('Creeping Tar Pit').activated_ability_mana_costs) self.assertEqual(['{W}', '{B}'], Card.get('Stormscape Apprentice').activated_ability_mana_costs) self.assertEqual(['{1}{G/P}'], Card.get('Birthing Pod').activated_ability_mana_costs) self.assertEqual(['{3}', '{U}'], Card.get('Crystal Shard').activated_ability_mana_costs)
def test_parse_mana_cost(self): self.assertEqual(['5'], parse_mana_cost("{5}")) self.assertEqual(['5'], Card.get('Batterskull').parsed_mana_cost) self.assertEqual(['3', 'U/R', 'B'], Card.get('Slave of Bolas').parsed_mana_cost) self.assertEqual(['3', 'U/P'], Card.get('Phyrexian Metamorph').parsed_mana_cost)
def test_getting_version_info(self): self.assertIn('60', Card.get('Demonic Tutor').versions) # split Cards take the left side self.assertIn('27165', Card.get('Fire//Ice').versions)