class MockParser: blocks = [ Block(name='Mana block', category=Block.CATEGORY_MTGO), ] sets = {} sets['Mana block'] = [ Set(code='MS', name='Mana set'), ] setentries = {} setentries['MS'] = [ ( CardEdition(number=1, number_suffix='', rarity=CardEdition.RARITY_UNCOMMON), Card(name='Mana card 1', types='Mana test', cmc=8), Artist(first_name='Some', last_name='Artist'), [], '3WUBRG', ), ( CardEdition(number=2, number_suffix='', rarity=CardEdition.RARITY_UNCOMMON), Card(name='Mana card 2', types='Mana test', cmc=4), Artist(first_name='Some', last_name='Artist'), [], 'XX{2/W}{BP}{BP}', ), ( CardEdition(number=3, number_suffix='', rarity=CardEdition.RARITY_UNCOMMON), Card(name='Mana card 3', types='Mana test', cmc=3), Artist(first_name='Some', last_name='Artist'), [], 'XX{2/W}{BP}', ), ( CardEdition(number=4, number_suffix='', rarity=CardEdition.RARITY_UNCOMMON), Card(name='Mana card 4', types='Mana test', cmc=5), Artist(first_name='Some', last_name='Artist'), [], '1UBBB', ), ] def parse_blocks_sets(): for block in MockParser.blocks: yield block, MockParser.sets[block.name] def parse_cards_by_set(setcode): for edition, card, artist, rulings, mana in MockParser.setentries[ setcode]: card.set_mana(mana) yield edition, card, artist, rulings
def _parse_sets(ul, block): """Parse all sets in the list.""" sets = [] for li in ul.find_all('li', recursive=False): name = li.a.string code = li.small.string.upper() set_ = Set(name=name, code=code, block=block) sets.append(set_) return sets
def test_update_set(self, block, set_): """Test updating an existing set.""" block.save() assert block.id is not None set_ = insert_set(block, set_) assert set_.id is not None b = Block(name='New block', category=Block.CATEGORY_MTGO) b.save() assert b.id is not None new_set = Set(code=set_.code, name='New set', release_date=datetime.date(1, 1, 1)) s = insert_set(b, new_set, update=True) assert s.id == set_.id assert s.code == set_.code assert s.block.id == b.id assert s.name == new_set.name assert s.release_date == new_set.release_date
class MockParser: blocks = [ Block(name='Test block', category=Block.CATEGORY_NONE), ] sets = [ Set(code='ORI', name='Magic Origins', release_date=datetime.date(2015, 7, 17)), Set(code='DKA', name='Dark Ascension', release_date=datetime.date(2012, 2, 3)), ] setentries = {} setentries['ORI'] = [ ( CardEdition(number=80, number_suffix='', rarity=CardEdition.RARITY_UNCOMMON), Card(name='Tower Geist', types='Creature — Spirit'), Artist(first_name='', last_name='Izzy'), [], ), ( CardEdition(number=60, number_suffix='a', rarity=CardEdition.RARITY_MYTHIC_RARE), Card(name="Jace, Vryn's Prodigy", types='Legendary Creature — Human Wizard', multi_type=Card.MULTI_FLIP), Artist(first_name='Jaime', last_name='Jones'), [], ), ( CardEdition(number=60, number_suffix='b', rarity=CardEdition.RARITY_MYTHIC_RARE), Card(name='Jace, Telepath Unbound', types='Planeswalker — Jace', multi_type=Card.MULTI_FLIP), Artist(first_name='Jaime', last_name='Jones'), [], ), (CardEdition(number=261, number_suffix='', rarity=CardEdition.RARITY_LAND), Card(name='Swamp', types='Basic Land — Swamp'), Artist(first_name='Larry', last_name='Elmore'), []), (CardEdition(number=262, number_suffix='', rarity=CardEdition.RARITY_LAND), Card(name='Swamp', types='Basic Land — Swamp'), Artist(first_name='Dan', last_name='Frazier'), []), (CardEdition(number=264, number_suffix='', rarity=CardEdition.RARITY_LAND), Card(name='Swamp', types='Basic Land — Swamp'), Artist(first_name='Jung', last_name='Park'), []), ] setentries['DKA'] = [ ( CardEdition(number=53, number_suffix='', rarity=CardEdition.RARITY_UNCOMMON), Card(name='Tower Geist', types='Creature — Spirit'), Artist(first_name='', last_name='Izzy'), [], ), ( CardEdition(number=3457, number_suffix='no', rarity=CardEdition.RARITY_SPECIAL), Card(name='No card', types='None'), Artist(first_name='', last_name='Izzy'), [], ), ] def parse_blocks_sets(): for block in MockParser.blocks: yield block, MockParser.sets def parse_cards_by_set(setcode): for edition, card, artist, rulings in MockParser.setentries[setcode]: yield edition, card, artist, rulings
class MockParser: blocks = [ Block(name='The first block', category=Block.CATEGORY_MTGO), Block(name='second block', category=Block.CATEGORY_SPECIAL_SET), Block(name='final Block', category=Block.CATEGORY_CORE_SET), ] sets = {} sets['The first block'] = [ Set(code='SMS', name='Some set'), Set(code='SIFB', name='set in first block'), ] sets['second block'] = [ Set(code='SBS', name='second block set'), ] sets['final Block'] = [ Set(code='FBS', name='final block set'), ] setentries = {} setentries['SMS'] = [ (CardEdition(number=5, number_suffix='a', rarity=CardEdition.RARITY_RARE), Card(name='Song (Song/Ice/Fire)', types='Sorcery', multi_type=Card.MULTI_SPLIT), Artist(first_name='George R. R.', last_name='Martin'), [ Ruling(ruling='Lannisters lose!', date=datetime.date(1, 1, 1)), Ruling(ruling='Starks rule!', date=datetime.date(2, 1, 1)), ]), (CardEdition(number=5, number_suffix='b', rarity=CardEdition.RARITY_RARE), Card(name='Ice (Song/Ice/Fire)', types='Sorcery', multi_type=Card.MULTI_SPLIT), Artist(first_name='George R. R.', last_name='Martin'), [ Ruling(ruling='Lannisters lose!', date=datetime.date(1, 1, 1)), Ruling(ruling='Starks rule!', date=datetime.date(2, 1, 1)), ]), (CardEdition(number=5, number_suffix='c', rarity=CardEdition.RARITY_RARE), Card(name='Fire (Song/Ice/Fire)', types='Sorcery', multi_type=Card.MULTI_SPLIT), Artist(first_name='George R. R.', last_name='Martin'), [ Ruling(ruling='Lannisters lose!', date=datetime.date(1, 1, 1)), Ruling(ruling='Starks rule!', date=datetime.date(2, 1, 1)), ]), (CardEdition(number=13, number_suffix='a', rarity=CardEdition.RARITY_RARE), Card(name='Wheel (Wheel/Time)', types='Legendary Creature', multi_type=Card.MULTI_FLIP), Artist(first_name='Robert', last_name='Jordan'), []), (CardEdition(number=13, number_suffix='b', rarity=CardEdition.RARITY_RARE), Card(name='Time (Wheel/Time)', types='Legendary Creature', multi_type=Card.MULTI_FLIP), Artist(first_name='Brandon', last_name='Sanderson'), []), ] setentries['SIFB'] = [ (CardEdition(number=1, number_suffix='', rarity=CardEdition.RARITY_COMMON), Card(name='Card with multiple editions', types='Reprint'), Artist(first_name='Model', last_name='Artist'), [ Ruling(ruling='This card has multiple editions.', date=datetime.date(1, 1, 1)), Ruling(ruling='No really, check it out.', date=datetime.date(1, 1, 2)), ]), ] setentries['SBS'] = [ (CardEdition(number=1, number_suffix='', rarity=CardEdition.RARITY_COMMON), Card(name='Card with multiple editions', types='Reprint'), Artist(first_name='Lone', last_name='Artist'), []), ] setentries['FBS'] = [ (CardEdition(number=3, number_suffix='', rarity=CardEdition.RARITY_UNCOMMON), Card(name='Card with multiple editions', types='Reprint'), Artist(first_name='Model', last_name='Artist'), []), ] def parse_blocks_sets(): for block in MockParser.blocks: yield block, MockParser.sets[block.name] def parse_cards_by_set(setcode): for edition, card, artist, rulings in MockParser.setentries[setcode]: yield edition, card, artist, rulings
class TestInsertSet: """All tests for :func:`cardbox.utils.db.insert_set`.""" blocksets = [ (Block(name='A block', category=Block.CATEGORY_EXPANSION), Set(code='A', name='A set', release_date=datetime.date(1587, 3, 8))), (Block(name='block AB', category=Block.CATEGORY_PROMO_CARD), Set(code='AB', name='set AB', release_date=datetime.date(2017, 5, 18))), (Block(name='MTG Testblock', category=Block.CATEGORY_SPECIAL_SET), Set(code='ACODE', name='MTG Testset')), ] @pytest.mark.parametrize('block,set_', blocksets) def test_insert_set(self, block, set_): """Test inserting a set.""" block.save() assert block.id is not None s = insert_set(block, set_) assert s.id is not None @pytest.mark.parametrize('block,set_', blocksets) def test_skip_set(self, block, set_): """Test skipping an existing set.""" block.save() assert block.id is not None set_ = insert_set(block, set_) assert set_.id is not None b = Block(name='New block', category=Block.CATEGORY_MTGO) b.save() assert b.id is not None new_set = Set(code=set_.code, name='New set', release_date=datetime.date(1, 1, 1)) s = insert_set(b, new_set, update=False) assert s.id == set_.id assert s.code == set_.code assert s.block.id == block.id assert s.name == set_.name assert s.release_date == set_.release_date @pytest.mark.parametrize('block,set_', blocksets) def test_update_set(self, block, set_): """Test updating an existing set.""" block.save() assert block.id is not None set_ = insert_set(block, set_) assert set_.id is not None b = Block(name='New block', category=Block.CATEGORY_MTGO) b.save() assert b.id is not None new_set = Set(code=set_.code, name='New set', release_date=datetime.date(1, 1, 1)) s = insert_set(b, new_set, update=True) assert s.id == set_.id assert s.code == set_.code assert s.block.id == b.id assert s.name == new_set.name assert s.release_date == new_set.release_date