def should_separate_type_and_subtypes(self): options = dict(type='land,dryad') request = SearchRequest(options) subt = SearchFilter('subtype', keywords=[SearchKeyword('dryad', 'and')]) type_ = SearchFilter('type', keywords=[SearchKeyword('land', 'and')]) self.assertEqual(request.get_filters(), {'type':type_, 'subtype': subt})
def should_separate_many_types_with_not_modifier(self): options = dict(type='legendary,artifact,!equipment,!creature') request = SearchRequest(options) type_keywords = [SearchKeyword('legendary', 'and'), SearchKeyword('artifact', 'and'), SearchKeyword('creature', 'not')] subtype_keywords = [SearchKeyword('equipment', 'not')] subt = SearchFilter('subtype', keywords=subtype_keywords) type_ = SearchFilter('type', keywords=type_keywords) self.assertEqual(request.get_filters(), [type_, subt])
def should_separate_many_types_with_not_modifier(self): options = dict(type='legendary,artifact,!equipment,!creature') request = SearchRequest(options) type_keywords = [SearchKeyword('legendary', 'and'), SearchKeyword('artifact', 'and'), SearchKeyword('creature', 'not')] subtype_keywords = [SearchKeyword('equipment', 'not')] subt = SearchFilter('subtype', keywords=subtype_keywords) type_ = SearchFilter('type', keywords=type_keywords) self.assertEqual(request.get_filters(), {'type': type_, 'subtype': subt})
def should_allow_color_exclusion(self): request = SearchRequest({'color': 'wu'}, exclude_others=['color']) self.assertTrue(request.get_filters()[0].exclude_others)
def should_recognize_creature_type_as_subtype(self): options = dict(type='dryad') request = SearchRequest(options) fl = SearchFilter('subtype', keywords=[SearchKeyword('dryad', 'and')]) self.assertEqual(request.get_filters(), [fl])
# coding: utf-8 from mtglib.gatherer_request import SearchRequest from mtglib.card_extractor import CardExtractor from django.utils.encoding import smart_str # ~ sets = [('Return to Ravnica', 'RTR'), ('Gatecrash', 'GTC'), ("Dragon's Maze", 'DGM'), ('Magic 2014 Core Set', 'M14')] # sets = [('Theros', 'THS'),] # sets = [('Commander 2013', 'C13'),] sets = [ # ('Magic 2015 Core Set', 'M15'), # ('Khans of Tarkir', 'KTK'), ("Fate Reforged", "FRF"), ] for s in sets: # request = SearchRequest({"set": s[0]}) cards = [] oldcards = [] for i in range(20): tmp = CardExtractor(request.url + "&page=%s" % i).cards if len(oldcards) > 0 and tmp[0].name == oldcards[0].name: break else: cards.extend(tmp) oldcards = tmp with open("%s.pot" % s[1], "wb") as dumpfile: dumpfile.write("#. Please leave mana costs and tap symbol intact!\n") for card in cards: dumpfile.write("#: %s\n" % smart_str(card.name)) lines = (smart_str(card.rules_text).replace(" ; ", ";").replace(
def setUp(self): self.request = SearchRequest({'text': 'first strike'})
def should_include_special_option_in_url(self): request = SearchRequest({'name': 'only,blood,ends,your,nightmares'}, special=True) assert request.special_fragment in request.url
def setUp(self): self.request = SearchRequest({'name': 'only,blood,ends,your,nightmares'}, special=True)
def should_allow_type_and_subtype_exclusion(self): request = SearchRequest({'type': 'dryad,creature'}, exclude_others=['type']) self.assertTrue(request.get_filters()['type'].exclude_others) self.assertTrue(request.get_filters()['subtype'].exclude_others)
def should_allow_type_exclusion(self): request = SearchRequest({'type': 'elemental'}, exclude_others=['type']) self.assertTrue(request.get_filters()['subtype'].exclude_others)
def should_allow_color_exclusion(self): request = SearchRequest({'color': 'wu'}, exclude_others=['color']) self.assertTrue(request.get_filters()['color'].exclude_others)
def should_allow_type_exclusion(self): request = SearchRequest({'type': 'elemental'}, exclude_others=['type']) self.assertTrue(request.get_filters()[0].exclude_others)
def should_assume_special_if_looking_for_a_special_type(self): request = SearchRequest({'type': 'plane'}) self.assertIn('&special=true', request.url)
def should_allow_type_and_subtype_exclusion(self): request = SearchRequest({'type': 'dryad,creature'}, exclude_others=['type']) self.assertTrue(request.get_filters()[0].exclude_others) self.assertTrue(request.get_filters()[1].exclude_others)
def should_recognize_creature_type_as_subtype(self): options = dict(type='dryad') request = SearchRequest(options) fl = SearchFilter('subtype', keywords=[SearchKeyword('dryad', 'and')]) self.assertEqual(request.get_filters(), {'subtype': fl})