def make_set_3(): """Copy of the second card set with Abebe dropped""" aAddedPhysCards = get_phys_cards() oPhysCardSet3 = PhysicalCardSet(name=CARD_SET_NAMES[2]) oPhysCardSet3.comment = ('A formatted test comment\nA second line\n' 'A third line') oPhysCardSet3.author = 'A test author' oPhysCardSet3.annotations = 'Some Annotations' for iLoop in range(5, 10): # pylint: disable=no-member # SQLObect confused pylint oPC = aAddedPhysCards[iLoop] if IAbstractCard(oPC).name == 'Abebe (Group 4)': continue oPhysCardSet3.addPhysicalCard(oPC.id) for sName, sExpansion, iCount in SET_2_ONLY_CARDS: # pylint: disable=no-member # SQLObect confused pylint oPC = make_card(sName, sExpansion) for _iNum in range(iCount): oPhysCardSet3.addPhysicalCard(oPC.id) for sName, sExpansion, iCount in SET_3_ONLY_CARDS: # pylint: disable=no-member # SQLObect confused pylint oPC = make_card(sName, sExpansion) for _iNum in range(iCount): oPhysCardSet3.addPhysicalCard(oPC.id) oPhysCardSet3.syncUpdate() return oPhysCardSet3
def make_set_1(): """Make the first card set. Function as this is also used in the io tests. """ aAddedPhysCards = get_phys_cards() oPhysCardSet1 = PhysicalCardSet(name=CARD_SET_NAMES[0]) oPhysCardSet1.comment = 'A test comment' oPhysCardSet1.author = 'A test author' for oCard in aAddedPhysCards: # pylint: disable=no-member # SQLObect confused pylint oPhysCardSet1.addPhysicalCard(oCard.id) oPhysCardSet1.syncUpdate() return oPhysCardSet1
def make_set_2(): """Make a second card set""" aAddedPhysCards = get_phys_cards() oPhysCardSet2 = PhysicalCardSet(name=CARD_SET_NAMES[1]) oPhysCardSet2.comment = ('A formatted test comment\nA second line\n' 'A third line') oPhysCardSet2.author = 'A test author' oPhysCardSet2.annotations = 'Some Annotations' for iLoop in range(5, 10): # pylint: disable=no-member # SQLObect confused pylint oPhysCardSet2.addPhysicalCard(aAddedPhysCards[iLoop].id) for sName, sExpansion, iCount in SET_2_ONLY_CARDS: oPC = make_card(sName, sExpansion) for _iNum in range(iCount): # pylint: disable=no-member # SQLObect confused pylint oPhysCardSet2.addPhysicalCard(oPC.id) oPhysCardSet2.syncUpdate() return oPhysCardSet2
def test_zip_file(self): """Test zip file handling""" self.maxDiff = None # pylint: disable=too-many-statements # Want a single test case to avoid re-initialising the database sTempFileName = self._create_tmp_file() oZipFile = ZipFileWrapper(sTempFileName) aPhysCards = get_phys_cards() oMyCollection = PhysicalCardSet(name='My Collection') for oCard in aPhysCards: # pylint: disable=no-member # SQLObject confuses pylint oMyCollection.addPhysicalCard(oCard.id) oMyCollection.syncUpdate() oPhysCardSet1 = PhysicalCardSet(name=CARD_SET_NAMES[0], parent=oMyCollection) oPhysCardSet1.comment = 'A test comment' oPhysCardSet1.author = 'A test author' self.assertNotEqual(oPhysCardSet1.parent, None) self.assertEqual(oPhysCardSet1.parent.id, oMyCollection.id) for iLoop in range(5): # pylint: disable=no-member # SQLObject confuses pylint oPhysCardSet1.addPhysicalCard(aPhysCards[iLoop].id) oPhysCardSet1.syncUpdate() if iLoop > 3: # Add a duplicate oPhysCardSet1.addPhysicalCard(aPhysCards[iLoop].id) oPhysCardSet1.syncUpdate() oPhysCardSet2 = PhysicalCardSet(name=CARD_SET_NAMES[1]) oPhysCardSet2.comment = 'Test 2 comment' oPhysCardSet2.author = 'A different author' for iLoop in range(2, 7): # pylint: disable=no-member # SQLObject confuses pylint oPhysCardSet2.addPhysicalCard(aPhysCards[iLoop].id) oPhysCardSet2.syncUpdate() oHandler = SutekhCountLogHandler() oZipFile.do_dump_all_to_zip(oHandler) self.assertEqual(oHandler.fTot, 3) dEntries = oZipFile.get_all_entries() self.assertEqual(len(dEntries), 3) self.assertTrue(oPhysCardSet2.name in dEntries) self.assertTrue(oPhysCardSet1.name in dEntries) self.assertTrue(oMyCollection.name in dEntries) self.assertEqual(dEntries[oPhysCardSet1.name][2], oMyCollection.name) # Check it loads correctly # Destroy some existing data # pylint: disable=not-an-iterable # SQLObject confuses pylint aCardSet1 = sorted([x.abstractCard.name for x in oPhysCardSet1.cards]) aCardSet2 = sorted([x.abstractCard.name for x in oPhysCardSet2.cards]) # pylint: enable=not-an-iterable delete_physical_card_set(oMyCollection.name) delete_physical_card_set(oPhysCardSet1.name) self.assertEqual(PhysicalCardSet.select().count(), 1) oZipFile.do_restore_from_zip(oLogHandler=oHandler) self.assertEqual(oZipFile.get_warnings(), []) self.assertEqual(oHandler.fTot, 3) self.assertEqual(PhysicalCardSet.select().count(), 3) oMyCollection = IPhysicalCardSet('My Collection') oPhysCardSet1 = IPhysicalCardSet(CARD_SET_NAMES[0]) oPhysCardSet2 = IPhysicalCardSet(CARD_SET_NAMES[1]) self.assertEqual(oPhysCardSet1.comment, 'A test comment') self.assertEqual(oPhysCardSet2.author, 'A different author') self.assertNotEqual(oPhysCardSet1.parent, None) self.assertEqual(oPhysCardSet1.parent.id, oMyCollection.id) self.assertEqual( sorted([x.abstractCard.name for x in oPhysCardSet1.cards]), aCardSet1) self.assertEqual(oPhysCardSet2.parent, None) self.assertEqual( sorted([x.abstractCard.name for x in oPhysCardSet2.cards]), aCardSet2) self.assertEqual( sorted([x.abstractCard.name for x in oMyCollection.cards]), sorted([x.abstractCard.name for x in aPhysCards])) self.assertEqual(len(oPhysCardSet1.cards), 6) self.assertEqual(len(oPhysCardSet2.cards), 5)