def test_read_single(self):
        """Check read_single_works"""
        self.maxDiff = None
        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()

        oHandler = SutekhCountLogHandler()
        oZipFile.do_dump_all_to_zip(oHandler)

        oHolder = oZipFile.read_single_card_set('My_Collection.xml')
        self.assertEqual(oHolder.name, oMyCollection.name)

        delete_physical_card_set(oMyCollection.name)
        oHolder.create_pcs()
        oMyCollection = IPhysicalCardSet('My Collection')

        self.assertEqual(
            sorted([x.abstractCard.name for x in oMyCollection.cards]),
            sorted([x.abstractCard.name for x in aPhysCards]))
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 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 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)
    def test_physical_card_set(self):
        """Test physical card set object"""
        # pylint: disable=too-many-statements, too-many-locals
        # Want a long, sequential test case to minimise
        # repeated setups, so it has lots of lines + variables
        aAddedPhysCards = get_phys_cards()
        # We have a physical card list, so create some physical card sets

        oPhysCardSet1 = PhysicalCardSet(name=CARD_SET_NAMES[2])

        # Add cards to the physical card sets

        for iLoop in range(5):
            # pylint: disable=no-member
            # SQLObect confused pylint
            oPhysCardSet1.addPhysicalCard(aAddedPhysCards[iLoop].id)
        oPhysCardSet1.syncUpdate()

        self.assertEqual(len(oPhysCardSet1.cards), 5)
        # Because we repeat .44 Magnum 3 times
        self.assertEqual(
            MapPhysicalCardToPhysicalCardSet.selectBy(
                physicalCardID=aAddedPhysCards[0].id).count(), 3)
        self.assertEqual(
            MapPhysicalCardToPhysicalCardSet.selectBy(
                physicalCardID=aAddedPhysCards[4].id).count(), 1)
        self.assertEqual(
            MapPhysicalCardToPhysicalCardSet.selectBy(
                physicalCardID=aAddedPhysCards[7].id).count(), 0)

        oPhysCardSet2 = PhysicalCardSet(name=CARD_SET_NAMES[1],
                                        comment='Test 2',
                                        author=oPhysCardSet1.author)

        self.assertEqual(oPhysCardSet2.name, CARD_SET_NAMES[1])
        self.assertEqual(oPhysCardSet2.author, oPhysCardSet1.author)
        self.assertEqual(oPhysCardSet2.comment, 'Test 2')

        for iLoop in range(3, 8):
            # pylint: disable=no-member
            # SQLObect confused pylint
            oPhysCardSet2.addPhysicalCard(aAddedPhysCards[iLoop].id)
        oPhysCardSet2.syncUpdate()

        self.assertEqual(len(oPhysCardSet2.cards), 5)
        self.assertEqual(
            MapPhysicalCardToPhysicalCardSet.selectBy(
                physicalCardID=aAddedPhysCards[0].id).count(), 3)
        self.assertEqual(
            MapPhysicalCardToPhysicalCardSet.selectBy(
                physicalCardID=aAddedPhysCards[4].id).count(), 2)
        self.assertEqual(
            MapPhysicalCardToPhysicalCardSet.selectBy(
                physicalCardID=aAddedPhysCards[7].id).count(), 1)

        oPhysCardSet3 = make_set_1()
        self.assertEqual(len(oPhysCardSet3.cards), len(aAddedPhysCards))

        self.assertEqual(oPhysCardSet3.name, CARD_SET_NAMES[0])
        self.assertEqual(oPhysCardSet3.comment, 'A test comment')

        oPhysCardSet4 = IPhysicalCardSet(CARD_SET_NAMES[0])

        self.assertEqual(oPhysCardSet3, oPhysCardSet4)

        # pylint: disable=no-member
        # SQLObject confuses pylint
        oPhysCardSet5 = PhysicalCardSet.byName(CARD_SET_NAMES[1])
        self.assertEqual(oPhysCardSet2, oPhysCardSet5)

        # Check Deletion

        # pylint: disable=not-an-iterable
        # SQLOBject confuses pylint
        for oCard in oPhysCardSet3.cards:
            oPhysCardSet3.removePhysicalCard(oCard.id)
        # pylint: enable=not-an-iterable

        self.assertEqual(len(oPhysCardSet3.cards), 0)
        PhysicalCardSet.delete(oPhysCardSet3.id)

        self.assertRaises(SQLObjectNotFound, PhysicalCardSet.byName,
                          CARD_SET_NAMES[0])

        delete_physical_card_set(CARD_SET_NAMES[1])

        self.assertRaises(SQLObjectNotFound, PhysicalCardSet.byName,
                          CARD_SET_NAMES[1])
        # pylint: enable=no-member

        self.assertEqual(
            MapPhysicalCardToPhysicalCardSet.selectBy(
                physicalCardID=aAddedPhysCards[0].id).count(), 3)
        self.assertEqual(
            MapPhysicalCardToPhysicalCardSet.selectBy(
                physicalCardID=aAddedPhysCards[4].id).count(), 1)

        delete_physical_card_set(CARD_SET_NAMES[2])

        self.assertEqual(
            MapPhysicalCardToPhysicalCardSet.selectBy(
                physicalCardID=aAddedPhysCards[0].id).count(), 0)
        self.assertEqual(
            MapPhysicalCardToPhysicalCardSet.selectBy(
                physicalCardID=aAddedPhysCards[4].id).count(), 0)
Exemplo n.º 7
0
    def test_basic(self):
        """Set of simple tests of the CardSetFrame"""
        # pylint: disable=too-many-statements, too-many-locals
        # Want a long, sequential test case to minimise
        # repeated setups, so it has lots of lines + variables

        # Add card sets needed for the tests
        # pylint: disable=unsupported-membership-test, not-an-iterable
        # Checks on RelatedJoins confuse pylint
        oPhysCardSet = PhysicalCardSet(name='My Collection')
        oPCS2 = PhysicalCardSet(name='Test Set 1', parent=oPhysCardSet)
        # Add some cards
        aCards = [('AK-47', None), ('Bronwen', 'SW'), ('Cesewayo', None),
                  ('Anna "Dictatrix11" Suljic', 'NoR'),
                  ('Ablative Skin', 'Sabbat')] + [('Alexandra', 'CE'),
                                                  ('Alexandra', None),
                                                  ('Ablative Skin', None)] * 5
        aPhysCards = []
        for sName, sExp in aCards:
            oCard = make_card(sName, sExp)
            aPhysCards.append(oCard)
        for oCard in aPhysCards:
            # pylint: disable=no-member
            # SQLObject confuses pylint
            oPhysCardSet.addPhysicalCard(oCard.id)
            oPhysCardSet.syncUpdate()
        self.oWin.setup(self.oConfig)
        # Remove the unneeded panes
        for oPane in self.oWin.aOpenFrames[:]:
            if oPane.title in ('Card Text', 'Card Set List'):
                self.oWin.remove_frame(oPane)
            if oPane.title == 'Full Card List':
                oWWList = oPane
            if oPane.title == 'My Collection':
                oMyColl = oPane
        # Add a set, not opened editable
        oNewFrame = self.oWin.add_new_physical_card_set('Test Set 1', False)
        # Add one of the new card sets, as an empty, editable set
        # Create selection of cards from the WW card list and
        # paste it into the new card set
        oFrame = oWWList
        self._select_cards(oFrame, [(u'AK-47', None),
                                    (u'AK-47', u'Lords of the Night')])
        self.assertEqual(oFrame.view.get_selection().count_selected_rows(), 2)
        # Copy
        oFrame.view.copy_selection()
        oNewFrame.view.do_paste()
        self.assertEqual(len(oPCS2.cards), 0)
        self.oWin.remove_frame(oNewFrame)
        # Reopen the card set, only editable this time
        oNewFrame = self.oWin.add_new_physical_card_set('Test Set 1', True)
        oNewFrame.view.do_paste()
        self.assertEqual(len(oPCS2.cards), 2)
        # Check we've pasted the right cards
        self.assertTrue(make_card(u'AK-47', None) in oPCS2.cards)
        self.assertTrue(
            make_card(u'AK-47', u'Lords of the Night') in oPCS2.cards)
        # Select cards in new card set and change numbers
        self._select_cards(oNewFrame, [(u'AK-47', None),
                                       (u'AK-47', u'Lords of the Night')])
        # Generate key_press event
        oEvent = Gdk.Event()
        oEvent.type = Gdk.EventType.KEY_PRESS
        oEvent.key.keyval = int(Gdk.keyval_from_name('4'))
        oNewFrame.view.key_press(oNewFrame, oEvent.key)
        self.assertEqual(len(oPCS2.cards), 8)
        oNewFrame.view.key_press(oNewFrame, oEvent.key)
        self.assertEqual(len(oPCS2.cards), 8)
        oEvent.key.keyval = int(Gdk.keyval_from_name('1'))
        oNewFrame.view.key_press(oNewFrame, oEvent.key)
        self.assertEqual(len(oPCS2.cards), 2)
        oEvent.key.keyval = int(Gdk.keyval_from_name('plus'))
        oNewFrame.view.key_press(oNewFrame, oEvent.key)
        self.assertEqual(len(oPCS2.cards), 4)
        oEvent.key.keyval = int(Gdk.keyval_from_name('minus'))
        oNewFrame.view.key_press(oNewFrame, oEvent.key)
        self.assertEqual(len(oPCS2.cards), 2)
        oNewFrame.view.key_press(oNewFrame, oEvent.key)
        self.assertEqual(len(oPCS2.cards), 0)
        # Select all and delete it from the new card set
        oNewFrame.view.do_paste()
        self.assertEqual(len(oPCS2.cards), 2)
        self._select_cards(oNewFrame, [(u'AK-47', u'Lords of the Night')])
        oNewFrame.view.del_selection()
        self.assertEqual(len(oPCS2.cards), 1)
        self._select_cards(oNewFrame, [(u'AK-47', None)])
        oEvent.key.keyval = int(Gdk.keyval_from_name('plus'))
        oNewFrame.view.key_press(oNewFrame, oEvent.key)
        self.assertEqual(len(oPCS2.cards), 2)
        oNewFrame.view.del_selection()
        self.assertEqual(len(oPCS2.cards), 0)
        oNewFrame.view.do_paste()
        self.assertEqual(len(oPCS2.cards), 2)
        # Select card from My Collection and paste it into the card set
        oFrame = oMyColl
        # set editable off
        oNewFrame.view.toggle_editable(False)
        # Verify that trying to paste the selection does nothing
        self._select_cards(oFrame,
                           [(u'AK-47', None), ('Ablative Skin', 'Sabbat'),
                            ('Alexandra (Group 2)', 'Camarilla Edition')])
        oFrame.view.copy_selection()
        oNewFrame.view.do_paste()
        self.assertEqual(len(oPCS2.cards), 2)
        # set editable on and verify that we can change the numbers
        oNewFrame.view.toggle_editable(True)
        oNewFrame.view.do_paste()
        # We should get 5 copies of Alexandra from My Collection
        self.assertEqual(len(oPCS2.cards), 9)
        self.assertEqual(
            len([
                x for x in oPCS2.cards
                if IAbstractCard(x).name == 'Alexandra (Group 2)'
            ]), 5)
        # Tests involving the top level selection
        oFrame = oWWList
        self._select_cards(oFrame, [(u'AK-47', ), (u'Ablative Skin', )])
        oFrame.view.copy_selection()
        oNewFrame.view.do_paste()
        self.assertEqual(len(oPCS2.cards), 11)
        self.assertEqual(
            len([
                x for x in oPCS2.cards
                if IAbstractCard(x).name == 'Alexandra (Group 2)'
            ]), 5)
        self.assertEqual(
            len([x for x in oPCS2.cards if IAbstractCard(x).name == 'AK-47']),
            4)
        aCardNames = [oCard.abstractCard.name for oCard in oPCS2.cards]
        self._select_cards(oNewFrame, [(sName, ) for sName in aCardNames])
        oNewFrame.view.del_selection()
        self.assertEqual(len(oPCS2.cards), 0)
        oFrame = oMyColl
        self._select_cards(oFrame, [(u'AK-47', ), (u'Ablative Skin', )])
        oFrame.view.copy_selection()
        oNewFrame.view.do_paste()
        self.assertEqual(len(oPCS2.cards), 7)
        self.assertEqual(
            len([x for x in oPCS2.cards if IAbstractCard(x).name == 'AK-47']),
            1)
        self.assertEqual(
            len([
                x for x in oPCS2.cards
                if IAbstractCard(x).name == 'Ablative Skin'
            ]), 6)
        self.assertEqual(
            len([
                x for x in oPCS2.cards
                if IAbstractCard(x).name == 'Ablative Skin'
                and IPhysicalCard(x).printingID is None
            ]), 5)
        # Test involving top level and sublevel selections
        # Top level should override the sub selections, as being
        # most consitent behaviour
        self._select_cards(oNewFrame, [(u'AK-47', ), (u'AK-47', None),
                                       (u'AK-47', 'Lords of the Night')])
        oEvent = Gdk.Event()
        oEvent.type = Gdk.EventType.KEY_PRESS
        oEvent.key.keyval = int(Gdk.keyval_from_name('4'))
        oNewFrame.view.key_press(oNewFrame, oEvent.key)
        self.assertEqual(len(oPCS2.cards), 10)
        oNewFrame.view.key_press(oNewFrame, oEvent.key)
        self.assertEqual(len(oPCS2.cards), 10)
        oEvent.key.keyval = int(Gdk.keyval_from_name('1'))
        oNewFrame.view.key_press(oNewFrame, oEvent.key)
        self.assertEqual(len(oPCS2.cards), 7)
        oEvent.key.keyval = int(Gdk.keyval_from_name('plus'))
        oNewFrame.view.key_press(oNewFrame, oEvent.key)
        self.assertEqual(len(oPCS2.cards), 8)
        oEvent.key.keyval = int(Gdk.keyval_from_name('minus'))
        oNewFrame.view.key_press(oNewFrame, oEvent.key)
        self.assertEqual(len(oPCS2.cards), 7)
        # We should copy all the ones from My Collection
        # rename card set, and verify that everything gets updated properly

        # Check reload keep expanded works
        aExp1 = self.get_expanded(oFrame.view)
        oFrame.reload()
        aExp2 = self.get_expanded(oFrame.view)
        self.assertEqual(aExp1, aExp2)
        # Change some paths
        oFrame.view.collapse_all()
        for oPath in aExp1[::4]:
            oFrame.view.expand_to_path(oPath)
        aExp1 = self.get_expanded(oFrame.view)
        self.assertNotEqual(aExp1, aExp2)  # We have changed the paths
        oFrame.reload()
        aExp2 = self.get_expanded(oFrame.view)
        self.assertEqual(aExp1, aExp2)  # But reload has retained the new state
Exemplo n.º 8
0
    def test_paste_form_card_set(self):
        """Test selecting and pasting with the different display modes"""

        # pylint: disable=too-many-statements, too-many-locals
        # Want a long, sequential test case to minimise
        # repeated setups, so it has lots of lines + variables
        # Add card sets needed for the tests
        # pylint: disable=unsupported-membership-test, not-an-iterable
        # Checks on RelatedJoins confuse pylint

        def clear_cardset(oPCS, oFrame):
            """Clear the cards from a card set and reload the model"""
            for oCard in oPCS.cards:
                oPCS.removePhysicalCard(oCard)
            oFrame.view.get_model().load()

        oCollSet = PhysicalCardSet(name='My Collection')
        oTest1 = PhysicalCardSet(name='Test Set 1',
                                 parent=oCollSet,
                                 inuse=True)
        # Add some cards
        aCards = [('AK-47', None), ('Bronwen', 'SW'), ('Cesewayo', None),
                  ('AK-47', 'Lords of the Night'),
                  ('AK-47', 'Lords of the Night'),
                  ('Anna "Dictatrix11" Suljic', 'NoR'),
                  ('Ablative Skin', 'Sabbat')] + [('Alexandra', 'CE'),
                                                  ('Alexandra', None),
                                                  ('Ablative Skin', None)] * 5
        aPhysCards = []
        for sName, sExp in aCards:
            oCard = make_card(sName, sExp)
            aPhysCards.append(oCard)
        for oCard in aPhysCards:
            # pylint: disable=no-member
            # SQLObject confuses pylint
            oCollSet.addPhysicalCard(oCard.id)
            oCollSet.syncUpdate()
        oAKLotN = make_card(u'AK-47', u'Lords of the Night')
        oAKNone = make_card(u'AK-47', None)
        oAblative = make_card(u'Ablative Skin', None)
        oAlex = make_card(u'Alexandra', u'CE')
        for oCard in [
                oAKLotN, oAKLotN, oAKLotN, oAKNone, oAKNone,
                make_card(u'Ablative Skin', 'Sabbat'), oAblative, oAblative,
                oAblative, oAblative, oAblative, oAlex, oAlex, oAlex
        ]:
            # pylint: disable=no-member
            # SQLObject confuses pylint
            oTest1.addPhysicalCard(oCard.id)
            oTest1.syncUpdate()
        self.oWin.setup(self.oConfig)
        # Remove the unneeded panes
        for oPane in self.oWin.aOpenFrames[:]:
            if oPane.title in ('Card Text', 'Card Set List', 'Full Card List'):
                self.oWin.remove_frame(oPane)
            if oPane.title == 'My Collection':
                oMyColl = oPane
        # Create the test profile and use it to set "My Collection"
        # to 'No Children'
        self.oConfig.set_profile_option(CARDSET, "test", EXTRA_LEVEL_OPTION,
                                        "none")
        self.oConfig.set_profile(CARDSET,
                                 oMyColl.view.get_model().cardset_id, 'test')
        self.oWin.do_all_queued_reloads()
        # Create a new set to paste into
        oTest2 = PhysicalCardSet(name='Test Set 2')
        oCS2Frame = self.oWin.add_new_physical_card_set('Test Set 2', True)
        # Select 2 cards and paste them
        self._select_cards(oMyColl, [(u'AK-47', ), (u'Ablative Skin', )])
        oMyColl.view.copy_selection()
        oCS2Frame.view.do_paste()
        # 3 x AK + 6 x Ablative
        self.assertEqual(len(oTest2.cards), 9)
        # Selecting these should match the expansions in My Collection
        self.assertEqual(len([x for x in oTest2.cards if x == oAKLotN]), 2)
        self.assertEqual(len([x for x in oTest2.cards if x == oAKNone]), 1)
        self.assertEqual(len([x for x in oTest2.cards if x == oAblative]), 5)
        self.assertTrue(make_card(u'Ablative Skin', 'Sabbat') in oTest2.cards)
        # Remove cards from test card set
        clear_cardset(oTest2, oCS2Frame)
        self.assertEqual(len(oTest2.cards), 0)
        # Change mode to expansions
        self.oConfig.set_profile_option(CARDSET, "test", EXTRA_LEVEL_OPTION,
                                        "expansions")
        self.oWin.do_all_queued_reloads()
        self._select_cards(oMyColl,
                           [(u'AK-47', u'Lords of the Night'),
                            (u'Ablative Skin', ),
                            (u'Alexandra (Group 2)', u'Camarilla Edition')])
        oMyColl.view.copy_selection()
        oCS2Frame.view.do_paste()
        # 2 x AK + 6 x Ablative + 5 x Alexandra
        self.assertEqual(len(oTest2.cards), 13)
        self.assertTrue(make_card(u'Ablative Skin', 'Sabbat') in oTest2.cards)
        self.assertEqual(len([x for x in oTest2.cards if x == oAKLotN]), 2)
        self.assertEqual(len([x for x in oTest2.cards if x == oAblative]), 5)
        self.assertEqual(len([x for x in oTest2.cards if x == oAlex]), 5)
        clear_cardset(oTest2, oCS2Frame)
        self.assertEqual(len(oTest2.cards), 0)
        # Change mode to card sets
        self.oConfig.set_profile_option(CARDSET, "test", EXTRA_LEVEL_OPTION,
                                        "card sets")
        self.oWin.do_all_queued_reloads()
        oMyColl.view.get_model().load()
        self._select_cards(oMyColl, [(u'AK-47', u'Test Set 1'),
                                     (u'Ablative Skin', ),
                                     (u'Alexandra (Group 2)', u'Test Set 1')])
        oMyColl.view.copy_selection()
        oCS2Frame.view.do_paste()
        # 5 x AK + 6 x Ablative + 3 x Alexandra
        self.assertEqual(len(oTest2.cards), 14)
        self.assertTrue(make_card(u'Ablative Skin', 'Sabbat') in oTest2.cards)
        self.assertEqual(len([x for x in oTest2.cards if x == oAKLotN]), 3)
        self.assertEqual(len([x for x in oTest2.cards if x == oAKNone]), 2)
        self.assertEqual(len([x for x in oTest2.cards if x == oAblative]), 5)
        self.assertEqual(len([x for x in oTest2.cards if x == oAlex]), 3)
        clear_cardset(oTest2, oCS2Frame)
        self.assertEqual(len(oTest2.cards), 0)
        # Change mode to card sets & expansions
        self.oConfig.set_profile_option(CARDSET, "test", EXTRA_LEVEL_OPTION,
                                        "card sets then expansions")
        self.oWin.do_all_queued_reloads()
        self._select_cards(oMyColl,
                           [(u'AK-47', u'Test Set 1', u'Lords of the Night'),
                            (u'Ablative Skin', ),
                            (u'Alexandra (Group 2)', u'Test Set 1')])
        oMyColl.view.copy_selection()
        oCS2Frame.view.do_paste()
        # 3 x AK + 6 x Ablative + 3 x Alexandra
        self.assertEqual(len(oTest2.cards), 12)
        self.assertTrue(make_card(u'Ablative Skin', 'Sabbat') in oTest2.cards)
        self.assertEqual(len([x for x in oTest2.cards if x == oAKLotN]), 3)
        self.assertEqual(len([x for x in oTest2.cards if x == oAblative]), 5)
        self.assertEqual(len([x for x in oTest2.cards if x == oAlex]), 3)

        clear_cardset(oTest2, oCS2Frame)
        self.assertEqual(len(oTest2.cards), 0)
        # Change mode to expansions & card sets
        self.oConfig.set_profile_option(CARDSET, "test", EXTRA_LEVEL_OPTION,
                                        "expansions then card sets")
        self.oWin.do_all_queued_reloads()
        self._select_cards(
            oMyColl,
            [(u'AK-47', u'Lords of the Night'), (u'Ablative Skin', ),
             (u'Alexandra (Group 2)', u'Camarilla Edition', u'Test Set 1')])
        oMyColl.view.copy_selection()
        oCS2Frame.view.do_paste()
        # 2 x AK + 6 x Ablative + 3 x Alexandra
        self.assertEqual(len(oTest2.cards), 11)
        self.assertTrue(make_card(u'Ablative Skin', 'Sabbat') in oTest2.cards)
        self.assertEqual(len([x for x in oTest2.cards if x == oAKLotN]), 2)
        self.assertEqual(len([x for x in oTest2.cards if x == oAblative]), 5)
        self.assertEqual(len([x for x in oTest2.cards if x == oAlex]), 3)
Exemplo n.º 9
0
 def test_delete_with_physical_filters(self):
     """Test deleting cards with physical filters in play."""
     oColl = PhysicalCardSet(name='My Collection')
     # Add some cards
     aCards = [("Ghoul Retainer", "Jyhad", None)] * 2 + \
         [("Ghoul Retainer", "Jyhad", "Variant Printing")] * 3 + \
         [("Off Kilter", "HttB", None)] * 3 + \
         [("Off Kilter", "HttB", "No Draft Text")] * 4
     aPhysCards = []
     for (sName, sExp, sPrint) in aCards:
         oCard = make_card(sName, sExp, sPrint)
         aPhysCards.append(oCard)
     for oCard in aPhysCards:
         # pylint: disable=no-member
         # SQLObject confuses pylint
         oColl.addPhysicalCard(oCard.id)
         oColl.syncUpdate()
     self.assertEqual(len(oColl.cards), 12)
     self.oWin.setup(self.oConfig)
     # Remove the unneeded panes
     for oPane in self.oWin.aOpenFrames[:]:
         if oPane.title in ('Card Text', 'Card Set List', 'Full Card List'):
             self.oWin.remove_frame(oPane)
         if oPane.title == 'My Collection':
             oMyColl = oPane
     oMyColl.view.toggle_editable(True)
     # Test deleting with no filter works as expected
     self._select_cards(oMyColl, [(u'Ghoul Retainer', ), (u'Off Kilter', )])
     oEvent = Gdk.Event()
     oEvent.type = Gdk.EventType.KEY_PRESS
     oEvent.key.keyval = int(Gdk.keyval_from_name('minus'))
     # Check that we can delete all the way
     # We should remove 2 cards each time until we've removed
     # 5 Ghoul Retainers
     for iExpected in range(10, 0, -2):
         oMyColl.view.key_press(oMyColl, oEvent.key)
         self.assertEqual(len(oColl.cards), iExpected)
     # Then remove 1 card for the last 2
     for iExpected in range(1, -1, -1):
         oMyColl.view.key_press(oMyColl, oEvent.key)
         self.assertEqual(len(oColl.cards), iExpected)
     oColl.syncUpdate()
     for oCard in aPhysCards:
         # pylint: disable=no-member
         # SQLObject confuses pylint
         oColl.addPhysicalCard(oCard.id)
         oColl.syncUpdate()
     self.assertEqual(len(oColl.cards), 12)
     oMyColl.reload()
     # Test deleting with physical printing filter works as expected
     oFilter = BaseFilters.PhysicalPrintingFilter(
         'Jyhad (Variant Printing)')
     oMyColl.view.set_filter(oFilter)
     oMyColl.reload()
     self._select_cards(oMyColl, [(u'Ghoul Retainer', )])
     # Each removal should remove 1 card
     for iExpected in range(11, 8, -1):
         oMyColl.view.key_press(oMyColl, oEvent.key)
         self.assertEqual(len(oColl.cards), iExpected)
     # Further removals have no effect
     oMyColl.view.key_press(oMyColl, oEvent.key)
     self.assertEqual(len(oColl.cards), 9)
     oMyColl.view.key_press(oMyColl, oEvent.key)
     self.assertEqual(len(oColl.cards), 9)
     # Test deleting with physical expansion filter works as expected
     oFilter = BaseFilters.PhysicalExpansionFilter('Heirs to the Blood')
     oMyColl.view.set_filter(oFilter)
     oMyColl.reload()
     self._select_cards(oMyColl, [(u'Off Kilter', )])
     for iExpected in range(8, 1, -1):
         oMyColl.view.key_press(oMyColl, oEvent.key)
         self.assertEqual(len(oColl.cards), iExpected)
     # Asset that all the remaining 2 cards are both Jyhad (No variant)
     # Ghoul retainers
     # pylint: disable=not-an-iterable
     # SQLObject confuses pylint here
     for oCard in oColl.cards:
         self.assertEqual(oCard.abstractCard.name, "Ghoul Retainer")
         self.assertEqual(IPrintingName(oCard), "Jyhad")