Example #1
0
def print_qt(num, ch):
    _c = False
    _qt = None
    try:
        # Load Qtable from file
        with np.load('Qtable/qtablenpc.npz') as data:
            _qt = data['qtable']
        _c = True
    except IOError:
        print("error loading qtable")
    if not _c:
        exit(0)
    _h = Hand()
    _res = np.zeros(8, dtype=int)
    for i in range(num):
        print(
            "Cards  --  big blind  --  money ranges  --  small blind  -- money ranges"
        )
        for j in range(i + 1, num):
            _h.add_card(Card.decode(i))
            _h.add_card(Card.decode(j))
            for i1 in range(2):
                for j1 in range(4):
                    _res[i1 * 4 + j1] = PokerEnv.encode(
                        _h, i1, 1 + (j1 * (ch / 2)), ch)
            _s = _h.__str__() + " - "
            for i2 in range(8):
                _s += str.format('{:.2f}', _qt[_res[i2]][0])
                _s += "|"
                _s += str.format('{:.2f}', _qt[_res[i2]][1])
                _s += " -- "
            print(_s)
            _h.clear_hand()
Example #2
0
def generate_tp(val=15, val2=15, val3=15):
    """Generate two pairs 5 cards hand"""
    suits = ["Spade", "Club", "Diamond", "Heart"]
    h = Hand()
    # First Pair
    choice = random.choice(suits)
    choice2 = random.choice(suits)
    while choice == choice2:
        choice2 = random.choice(suits)
    if val == 15:
        val = random.choice(range(2, 15))
    for su in suits:
        if not (su.__eq__(choice) or su.__eq__(choice2)):
            h.add_card(Card(su, val))
    # Second Pair
    choice = random.choice(suits)
    choice2 = random.choice(suits)
    while choice == choice2:
        choice2 = random.choice(suits)
    while val2 == 15 or val2 == val:
        val2 = random.choice(range(2, 15))
    for su in suits:
        if not (su.__eq__(choice) or su.__eq__(choice2)):
            h.add_card(Card(su, val2))
    # Last Card
    while val3 == 15 or val3 == val or val3 == val2:
        val3 = random.choice(range(2, 15))
    h.add_card(Card(random.choice(suits), val3))
    return h
 def test_gamestate_all_answers_done(self):
     state = GameState(2)
     card = Card(2,Suit.DIAMOND)
     state.add_answer(card)
     self.assertFalse(state.all_answers_done())
     card2 = Card(3,Suit.CLUB)
     state.add_answer(card2)
     self.assertTrue(state.all_answers_done())
 def test_gamestate_add_answer(self):
     state = GameState(2)
     card = Card(2,Suit.DIAMOND)
     state.add_answer(card)
     self.assertEqual(len(state.get_answers()),1)
     self.assertEqual(state.get_answers()[0],card)
     card2 = Card(3,Suit.CLUB)
     state.add_answer(card2)
     self.assertEqual(len(state.get_answers()),2)
     self.assertEqual(state.get_answers()[1],card2)
    def create_card_entity(self, cardname):
        """ Creates a new card.
        Args:
            cardname: [String] The name of the card.
        Returns:
            [Card] Created Card entity.
        """

        card = Card(cardname)
        card.add_cube(self._cube.get_id())
        return card
Example #6
0
    def setUp(self):
        card_repository.delete_all()
        self.card1 = Card('Teemu Kerppu')
        self.card2 = Creature('Kana')
        self.card3 = Instant('Kortti')
        self.card4 = Creature('Kana2')

        self.card1.set_cubes(["id1"])
        self.card2.set_cubes(["id1"])
        self.card3.set_cubes(["id2"])
        self.card4.set_cubes(["id1"])
Example #7
0
 def next(self):
     """ takes the players guess and adds it to list.
     Takes next guess of goes to resultpage if all guesses are made. """
     suit = Suit(self.suit_var.get())
     card = Card( self.num_var.get(),suit)
     print("going to next page with card: ", card.card_id())
     self.gamestate.add_answer(card)
     if self.gamestate.all_answers_done():
         self.handle_show_result_view(self.gamestate)
         return
     self.destroy()
     self.initialize()
     self.pack()
Example #8
0
def get_deck():
    _deck = []
    for _suit in pull_suit():
        for v in range(2, 15):
            _new_card = Card(suit=_suit, rank=v)
            _deck.append(_new_card)
    return _deck
Example #9
0
 def setUp(self):
     self.kks = KorttikubeService(FakeCardRepository([]),
                                  FakeCubeRepository([]),
                                  FakeUserRepository([]))
     self.card = Card("Testi")
     self.cube = Cube("Testikube")
     self.user = User("Testaaja", "testo")
     self.card_db = ('ac9a8253-5b78-4010-9aab-516dd1b00879', 'Peruna', \
                       '7132ac94-3e63-4fc8-9d33-5b8e7a2280cd', 'Instant', \
                       1, 0, 'Pottu', 'Valkoinen', '2U', None, \
                       'Peruna on pyöreä.', 'Peruna on soikea.', \
                       None, None, 'kuva', 'tunnus', 'rare', 'Tekijä', 'joku')
     self.cube_db = ('ac9a8253-5b78-4010-9aab-516dd1b00879', 'Kube', \
                     '7132ac94-3e63-4fc8-9d33-5b8e7a2280cd', 'kuva', \
                     'tunnus')
     self.user_db = ('Käyttäjä', 'salasana')
Example #10
0
 def fulldeck(self):
     """Helper function to return full deck (52 cards) that is in order"""
     deck = []
     for suit in [Suit.CLUB, Suit.DIAMOND, Suit.HEART, Suit.SPADE]:
         for i in range(1, 14):
             deck.append(Card(i, suit))
     return deck
Example #11
0
def generate_tok(val=15, val2=15, val3=15):
    """Generate three of a kind 5 cards hand"""
    suits = ["Spade", "Club", "Diamond", "Heart"]
    choice = random.choice(suits)
    if val == 15:
        val = random.choice(range(2, 15))
    h = Hand()
    for su in suits:
        if not su.__eq__(choice):
            h.add_card(Card(su, val))
    while val2 == 15 or val2 == val:
        val2 = random.choice(range(2, 15))
    h.add_card(Card(random.choice(suits), val2))
    while val3 == 15 or val3 == val or val3 == val2:
        val3 = random.choice(range(2, 15))
    h.add_card(Card(random.choice(suits), val3))
    return h
Example #12
0
 def generate_deck(self):
     """
     Generates the deck of 40 cards
     """
     for card_type in Card.CARD_TYPES:
         for i in range(10):
             card = Card(i + 1, card_type)
             self.deck.append(card)
Example #13
0
def generate_fh(val=15, val2=15):
    """Generate Full house 5 cards hand"""
    suits = ["Spade", "Club", "Diamond", "Heart"]
    choice = random.choice(suits)
    if val == 15:
        val = random.choice(range(2, 15))
    h = Hand()
    for su in suits:
        if not su.__eq__(choice):
            h.add_card(Card(su, val))
    choice, choice2 = random.choice(suits), random.choice(suits)
    while choice2 == choice:
        choice2 = random.choice(suits)
    while val2 == 15 or val2 == val:
        val2 = random.choice(range(2, 15))
    for su in suits:
        if not (su.__eq__(choice) or su.__eq__(choice2)):
            h.add_card(Card(su, val2))
    return h
Example #14
0
    def getStraight(self, cards, player):

        if cards[0].value == 14:
            cards = cards + [Card(1, cards[0].suit)]

        seqCards = []
        for c in cards:
            if not seqCards or seqCards[-1].value - c.value == 1:
                seqCards.append(c)
            elif seqCards[-1].value - c.value > 1:
                seqCards = [c]

            if len(seqCards) == 5:
                if seqCards[-1].value == 1:
                    seqCards[-1] = Card(14, seqCards[-1].suit)

                return Hand(name=Hands.straight,
                            owner=player.id,
                            cards=seqCards)
        return None
Example #15
0
    def __init__(self, playerCount):
        for i in range(playerCount):
            p = Player()
            self.players.append(p)

        for i in range(2, 15):
            for j in range(4):
                self.deck.append(Card(i, {0: Suits.Clubs,
                                          1: Suits.Diamonds,
                                          2: Suits.Spades,
                                          3: Suits.Hearts}[j]))
Example #16
0
    def getStraightFlush(self, suits, player):
        for key, val in suits.items():
            if len(val) >= 5:
                cards = val[:]

                if cards[0].value == 14:
                    cards = cards + [Card(1, cards[0].suit)]

                seqCards = []
                for c in cards:
                    if not seqCards or seqCards[-1].value - c.value == 1:
                        seqCards.append(c)
                    elif seqCards[-1].value - c.value > 1:
                        seqCards = [c]

                    if len(seqCards) == 5:
                        if seqCards[-1].value == 1:
                            seqCards[-1] = Card(14, seqCards[-1].suit)

                        return Hand(name=Hands.straightFlush,
                                    owner=player.id,
                                    cards=seqCards)
        return None
Example #17
0
 def setUp(self):
     self.card = Card('Graduated friend')
     self.creature = Creature('Teemu K')
    def create_card_entity_from_db(self, card_row):
        """ Creates a Card entity from the given database row.
        Args:
            card_row: [List Tuple] List of tuples including the attributes
                       of one card in database.
        Returns:
            [Card] Created Card entity.
        """

        name = card_row[1]
        maintype = card_row[3]
        if maintype == "":
            card = Card(name)
        elif maintype == "Creature":
            card = Creature(name)
        elif maintype == "Artifact":
            card = Artifact(name)
        elif maintype == "Enchantment":
            card = Enchantment(name)
        elif maintype == "Land":
            card = Land(name)
        elif maintype == "Instant":
            card = Instant(name)
        elif maintype == "Sorcery":
            card = Sorcery(name)
        elif maintype == "Planeswalker":
            card = Planeswalker(name)
        elif maintype == "Artifact Creature":
            card = ArtifactCreature(name)
        elif maintype == "Enchantment Creature":
            card = EnchantmentCreature(name)

        card.set_id(card_row[0])
        card.set_cubes(card_row[2])
        card.set_legendary(card_row[4])
        card.set_tribal(card_row[5])
        card.set_subtype(card_row[6])
        card.set_colour(card_row[7])
        card.set_manacost(card_row[8])
        card.set_feature(card_row[9])
        card.set_ruletext(card_row[10])
        card.set_flavourtext(card_row[11])
        card.set_power(card_row[12])
        card.set_toughness(card_row[13])
        card.set_image(card_row[14])
        card.set_seticon(card_row[15])
        card.set_rarity(card_row[16])
        card.set_creator(card_row[17])
        card.set_picture(card_row[18])

        return card
Example #19
0
class TestCard(unittest.TestCase):
    def setUp(self):
        self.card = Card('Graduated friend')
        self.creature = Creature('Teemu K')
        ###

    def set_card(self):
        self.card.set_id("1234567")
        self.card.set_name("Party Tutor")
        self.card.set_cubes(["123", "234"])
        self.card.set_maintype("Creature")
        self.card.set_legendary(False)
        self.card.set_tribal(True)
        self.card.set_subtype("Teekkari ISO")
        self.card.set_colour("Vihreä")
        self.card.set_manacost("2U")
        self.card.set_power(3)
        self.card.set_toughness(2)
        self.card.set_feature("Haste, Trample")
        self.card.set_ruletext("Party Tutor rule")
        self.card.set_flavourtext("Party")
        self.card.set_image("img/partytutor")
        self.card.set_creator("Masa")
        self.card.set_seticon("img/seticon1")
        self.card.set_rarity("Common")

    def test_set_attributes(self):
        self.set_card()
        self.assertEqual(self.card.get_id(), "1234567")
        self.assertEqual(self.card.get_name(), "Party Tutor")
        self.assertEqual(self.card.get_cubes(), ["123", "234"])
        self.assertEqual(self.card.get_maintype(), "Creature")
        self.assertEqual(self.card.get_legendary(), False)
        self.card.set_legendary(None)
        self.assertEqual(self.card.get_legendary(), False)
        self.assertEqual(self.card.get_tribal(), True)
        self.assertEqual(self.card.get_subtype(), ["Teekkari", "ISO"])
        self.card.set_subtype(None)
        self.assertEqual(self.card.get_subtype(), ["Teekkari", "ISO"])
        self.assertEqual(self.card.get_colour(), ["Vihreä"])
        self.card.set_colour("Väritön")
        self.assertEqual(self.card.get_colour(), [])
        self.assertEqual(self.card.get_manacost(), "2U")
        self.assertEqual(self.card.get_power(), 3)
        self.assertEqual(self.card.get_toughness(), 2)
        self.assertEqual(self.card.get_feature(), ["Haste", "Trample"])
        self.assertEqual(self.card.get_ruletext(), "Party Tutor rule")
        self.assertEqual(self.card.get_flavourtext(), "Party")
        self.assertEqual(self.card.get_image(), "img/partytutor")
        self.assertEqual(self.card.get_creator(), "Masa")
        self.assertEqual(self.card.get_seticon(), "img/seticon1")
        self.assertEqual(self.card.get_rarity(), "Common")

    def test_get_cubes_print(self):
        self.assertEqual(self.card.get_cubes_print(), "")
        self.card.set_cubes(["1234", "2345"])
        self.assertEqual(self.card.get_cubes_print(), "1234, 2345")
        self.card.set_cubes("9876")
        self.assertEqual(self.card.get_cubes_print(), "9876")

    def test_get_legendary_print(self):
        self.assertEqual(self.card.get_legendary_print(), "")
        self.card.set_legendary(True)
        self.assertEqual(self.card.get_legendary_print(), "Legendary ")
        self.card.set_legendary(False)
        self.assertEqual(self.card.get_legendary_print(), "")

    def test_get_tribal_print(self):
        self.assertEqual(self.card.get_tribal_print(), "")
        self.card.set_tribal(True)
        self.assertEqual(self.card.get_tribal_print(), "Tribal ")
        self.card.set_tribal(False)
        self.assertEqual(self.card.get_tribal_print(), "")

    def test_get_subtype_print(self):
        self.assertEqual(self.card.get_subtype_print(), "")
        self.card.set_subtype("Beast Bird")
        self.assertEqual(self.card.get_subtype_print(), "Beast Bird")
        self.card.set_subtype("Bird")
        self.assertEqual(self.card.get_subtype_print(), "Bird")

    def test_add_cube(self):
        self.assertEqual(self.card.get_cubes(), [])
        self.card.add_cube("999")
        self.assertEqual(self.card.get_cubes(), ["999"])
        self.card.add_cube("777")
        self.assertEqual(self.card.get_cubes(), ["999", "777"])
        self.card.add_cube("999")
        self.assertEqual(self.card.get_cubes(), ["999", "777"])
        self.card.add_cube("111")
        self.assertEqual(self.card.get_cubes(), ["999", "777", "111"])

    def test_add_colour(self):
        self.card.add_colour("Punainen")
        self.assertEqual(self.card.get_colour(), ["Punainen"])
        self.card.add_colour("Valkoinen")
        self.assertEqual(self.card.get_colour(), ["Punainen", "Valkoinen"])
        self.card.add_colour("Valkoinen")
        self.assertEqual(self.card.get_colour(), ["Punainen", "Valkoinen"])
        self.card.add_colour("Sininen")
        self.assertEqual(self.card.get_colour(),
                         ["Punainen", "Valkoinen", "Sininen"])

    def test_remove_cube(self):
        self.card.remove_cube("123")
        self.assertEqual(self.card.get_cubes(), [])
        self.card.add_cube("123")
        self.card.add_cube("4321")
        self.card.remove_cube("1234")
        self.assertEqual(self.card.get_cubes(), ["123", "4321"])
        self.card.remove_cube("123")
        self.assertEqual(self.card.get_cubes(), ["4321"])
        self.card.remove_cube("1")
        self.assertEqual(self.card.get_cubes(), ["4321"])
        self.card.remove_cube("4321")
        self.assertEqual(self.card.get_cubes(), [])
        self.card.remove_cube("4321")
        self.assertEqual(self.card.get_cubes(), [])

    def test_remove_colour(self):
        self.card.add_colour("Punainen")
        self.card.add_colour("Valkoinen")
        self.card.remove_colour("Vihreä")
        self.assertEqual(self.card.get_colour(), ["Punainen", "Valkoinen"])
        self.card.remove_colour("Punainen")
        self.assertEqual(self.card.get_colour(), ["Valkoinen"])
        self.card.remove_colour("Valkoinen")
        self.assertEqual(self.card.get_colour(), [])
        self.card.remove_colour("Valkoinen")
        self.assertEqual(self.card.get_colour(), [])

    def test_get_card_colour(self):
        self.assertEqual(self.card.get_card_colour(), "Väritön")
        self.card.add_colour("Punainen")
        self.assertEqual(self.card.get_card_colour(), "Punainen")
        self.card.add_colour("Vihreä")
        self.assertEqual(self.card.get_card_colour(), "Kulta")
        self.card.remove_colour("Punainen")
        self.assertEqual(self.card.get_card_colour(), "Vihreä")
        self.card.remove_colour("Vihreä")
        self.assertEqual(self.card.get_card_colour(), "Väritön")

    def test_get_colour_print(self):
        self.assertEqual(self.card.get_colour_print(), "Väritön")
        self.card.add_colour("Punainen")
        self.assertEqual(self.card.get_colour_print(), "Punainen")
        self.card.add_colour("Vihreä")
        self.assertEqual(self.card.get_colour_print(), "Punainen, Vihreä")

    def test_check_if_multicolour(self):
        self.assertNotEqual(self.card.get_card_colour(), "Kulta")
        self.card.add_colour("Punainen")
        self.assertNotEqual(self.card.get_card_colour(), "Kulta")
        self.card.add_colour("Vihreä")
        self.assertEqual(self.card.get_card_colour(), "Kulta")
        self.card.add_colour("Musta")
        self.assertEqual(self.card.get_card_colour(), "Kulta")
        self.card.remove_colour("Punainen")
        self.card.remove_colour("Musta")
        self.assertNotEqual(self.card.get_card_colour(), "Kulta")

    def test_get_power_print(self):
        self.assertEqual(self.card.get_power_print(), 0)
        self.card.set_power(4)
        self.assertEqual(self.card.get_power_print(), 4)
        self.card.set_power(2)
        self.assertEqual(self.card.get_power_print(), 2)

    def test_get_toughness_print(self):
        self.assertEqual(self.card.get_toughness_print(), 0)
        self.card.set_toughness(10)
        self.assertEqual(self.card.get_toughness_print(), 10)
        self.card.set_toughness(1)
        self.assertEqual(self.card.get_toughness_print(), 1)

    def test_add_feature(self):
        self.assertEqual(self.card.get_feature(), [])
        self.card.add_feature("Flying")
        self.assertEqual(self.card.get_feature(), ["Flying"])
        self.card.add_feature("Vigilance")
        self.assertEqual(self.card.get_feature(), ["Flying", "Vigilance"])
        self.card.add_feature("Vigilance")
        self.assertEqual(self.card.get_feature(), ["Flying", "Vigilance"])
        self.card.add_feature("Trample")
        self.assertEqual(self.card.get_feature(),
                         ["Flying", "Vigilance", "Trample"])

    def test_remove_feature(self):
        self.card.add_feature("Reach")
        self.card.add_feature("Deathtouch")
        self.card.remove_feature("Firststrike")
        self.assertEqual(self.card.get_feature(), ["Reach", "Deathtouch"])
        self.card.remove_feature("Deathtouch")
        self.assertEqual(self.card.get_feature(), ["Reach"])
        self.card.remove_feature("Reach")
        self.assertEqual(self.card.get_feature(), [])
        self.card.remove_feature("Reach")
        self.assertEqual(self.card.get_feature(), [])

    def test_get_feature_print(self):
        self.assertEqual(self.card.get_feature_print(), "")
        self.card.add_feature("Flying")
        self.card.add_feature("Vigilance")
        self.assertEqual(self.card.get_feature_print(), "Flying, Vigilance")
        self.card.add_feature("Trample")
        self.assertEqual(self.card.get_feature_print(),
                         "Flying, Vigilance, Trample")
        self.card.remove_feature("Vigilance")
        self.assertEqual(self.card.get_feature_print(), "Flying, Trample")

    def test_get_feature_list(self):
        self.assertEqual(self.card.get_feature_list(), [])
        self.card.add_feature("Flying")
        self.card.add_feature("Vigilance")
        self.assertEqual(self.card.get_feature_list(), ["Flying", "Vigilance"])
        self.card.add_feature("Trample")
        self.assertEqual(self.card.get_feature_list(),
                         ["Flying", "Vigilance", "Trample"])
        self.card.remove_feature("Vigilance")
        self.assertEqual(self.card.get_feature_list(), ["Flying", "Trample"])

    def test_show_card(self):
        self.set_card()
        self.card.add_colour("Punainen")
        #self.assertEqual(self.show_card(), )
        self.assertEqual(True, True)

    # Creature
    def set_creature(self):
        self.creature.set_id("891234")
        self.creature.set_name("Teemu Kerppu")
        self.creature.set_image("img/teemukerppu")
        self.creature.set_legendary(True)
        self.creature.set_subtype("DI Spirit")
        self.creature.set_manacost("2U2")
        self.creature.set_power(3)
        self.creature.set_toughness(4)
        self.creature.set_ruletext("Teemu Kerppu rule")
        self.creature.set_flavourtext("Imaginary")
        self.creature.set_creator("Peruna")
        self.creature.set_seticon("img/seticon1")
        self.creature.set_rarity("Rare")

    def test_set_creature(self):
        self.set_creature()
        self.assertEqual(self.creature.get_id(), "891234")
        self.assertEqual(self.creature.get_name(), "Teemu Kerppu")
        self.assertEqual(self.creature.get_image(), "img/teemukerppu")
        self.assertEqual(self.creature.get_maintype(), "Creature")
        self.assertEqual(self.creature.get_legendary(), True)
        self.assertEqual(self.creature.get_tribal(), None)
        self.assertEqual(self.creature.get_subtype(), ["DI", "Spirit"])
        self.assertEqual(self.creature.get_manacost(), "2U2")
        self.assertEqual(self.creature.get_power(), 3)
        self.assertEqual(self.creature.get_toughness(), 4)
        self.assertEqual(self.creature.get_ruletext(), "Teemu Kerppu rule")
        self.assertEqual(self.creature.get_flavourtext(), "Imaginary")
        self.assertEqual(self.creature.get_creator(), "Peruna")
        self.assertEqual(self.creature.get_seticon(), "img/seticon1")
        self.assertEqual(self.creature.get_rarity(), "Rare")

    def test_copy_creature(self):
        self.set_card()
        creature = Creature(self.card.get_name())
        creature.copy(self.card)
        self.assertEqual(creature.get_id(), "1234567")
        self.assertEqual(creature.get_name(), "Party Tutor")
        self.assertEqual(creature.get_image(), "img/partytutor")
        self.assertEqual(creature.get_maintype(), "Creature")
        self.assertEqual(creature.get_legendary(), False)
        self.assertEqual(creature.get_tribal(), None)
        self.assertEqual(creature.get_subtype(), ["Teekkari", "ISO"])
        self.assertEqual(creature.get_colour(), ["Vihreä"])
        self.assertEqual(creature.get_manacost(), "2U")
        self.assertEqual(creature.get_power(), 3)
        self.assertEqual(creature.get_toughness(), 2)
        self.assertEqual(creature.get_feature(), ["Haste", "Trample"])
        self.assertEqual(creature.get_feature2(), [])
        self.assertEqual(creature.get_ruletext(), "Party Tutor rule")
        self.assertEqual(creature.get_flavourtext(), "Party")
        self.assertEqual(creature.get_creator(), "Masa")
        self.assertEqual(creature.get_seticon(), "img/seticon1")
        self.assertEqual(creature.get_rarity(), "Common")

    # Artifact
    def test_copy_artifact(self):
        self.set_card()
        k = Artifact(self.card.get_name())
        k.copy(self.card)
        self.assertEqual(k.get_id(), "1234567")
        self.assertEqual(k.get_name(), "Party Tutor")
        self.assertEqual(k.get_image(), "img/partytutor")
        self.assertEqual(k.get_maintype(), "Artifact")
        self.assertEqual(k.get_legendary(), False)
        self.assertEqual(k.get_tribal(), True)
        self.assertEqual(k.get_subtype(), ["Teekkari", "ISO"])
        k.set_subtype(None)
        self.assertEqual(k.get_subtype(), ["Teekkari", "ISO"])
        self.assertEqual(k.get_colour(), ["Vihreä"])
        self.assertEqual(k.get_manacost(), "2U")
        self.assertEqual(k.get_power(), None)
        self.assertEqual(k.get_toughness(), None)
        self.assertEqual(k.get_feature(), [])
        k.set_feature(["Haste", "Flash"])
        self.assertEqual(k.get_feature(), ["Flash"])
        self.assertEqual(k.get_feature2(),
                         ["Hexproof", "Indestructible", "Flash"])
        self.assertEqual(k.get_ruletext(), "Party Tutor rule")
        self.assertEqual(k.get_flavourtext(), "Party")
        self.assertEqual(k.get_creator(), "Masa")
        self.assertEqual(k.get_seticon(), "img/seticon1")
        self.assertEqual(k.get_rarity(), "Common")

    def test_vehicle_artifact(self):
        self.set_card()
        k = Artifact(self.card.get_name())
        k.copy(self.card)
        k.set_subtype("Vehicle")
        self.assertEqual(k.get_id(), "1234567")
        self.assertEqual(k.get_name(), "Party Tutor")
        self.assertEqual(k.get_image(), "img/partytutor")
        self.assertEqual(k.get_maintype(), "Artifact")
        self.assertEqual(k.get_legendary(), False)
        self.assertEqual(k.get_tribal(), True)
        self.assertEqual(k.get_subtype(), ["Vehicle"])
        self.assertEqual(k.get_colour(), ["Vihreä"])
        self.assertEqual(k.get_manacost(), "2U")
        self.assertEqual(k.get_power(), 0)
        self.assertEqual(k.get_toughness(), 0)
        self.assertEqual(k.get_feature(), [])
        self.assertEqual(k.get_feature2(),
                         ["Hexproof", "Indestructible", "Flash"])
        self.assertEqual(k.get_ruletext(), "Party Tutor rule")
        self.assertEqual(k.get_flavourtext(), "Party")
        self.assertEqual(k.get_creator(), "Masa")
        self.assertEqual(k.get_seticon(), "img/seticon1")
        self.assertEqual(k.get_rarity(), "Common")
        k.set_subtype("Vehicle Bird")
        self.assertEqual(k.get_id(), "1234567")
        self.assertEqual(k.get_name(), "Party Tutor")
        self.assertEqual(k.get_image(), "img/partytutor")
        self.assertEqual(k.get_maintype(), "Artifact")
        self.assertEqual(k.get_legendary(), False)
        self.assertEqual(k.get_tribal(), True)
        self.assertEqual(k.get_subtype(), ["Vehicle", "Bird"])
        self.assertEqual(k.get_colour(), ["Vihreä"])
        self.assertEqual(k.get_manacost(), "2U")
        self.assertEqual(k.get_power(), None)
        self.assertEqual(k.get_toughness(), None)
        self.assertEqual(k.get_feature(), [])
        self.assertEqual(k.get_feature2(),
                         ["Hexproof", "Indestructible", "Flash"])
        self.assertEqual(k.get_ruletext(), "Party Tutor rule")
        self.assertEqual(k.get_flavourtext(), "Party")
        self.assertEqual(k.get_creator(), "Masa")
        self.assertEqual(k.get_seticon(), "img/seticon1")
        self.assertEqual(k.get_rarity(), "Common")

    def test_feature_artifact(self):
        self.set_card()
        k = Artifact(self.card.get_name())
        k.copy(self.card)
        k.add_feature("Trample")
        self.assertEqual(k.get_feature(), [])
        k.add_feature("Flash")
        self.assertEqual(k.get_feature(), ["Flash"])
        k.add_feature("Vigilance")
        self.assertEqual(k.get_feature(), ["Flash"])
        k.add_feature("Hexproof")
        self.assertEqual(k.get_feature(), ["Flash", "Hexproof"])

    # Artifact creature
    def test_copy_artifact_creature(self):
        self.set_card()
        k = ArtifactCreature(self.card.get_name())
        k.copy(self.card)
        self.assertEqual(k.get_id(), "1234567")
        self.assertEqual(k.get_name(), "Party Tutor")
        self.assertEqual(k.get_image(), "img/partytutor")
        self.assertEqual(k.get_maintype(), "Artifact Creature")
        self.assertEqual(k.get_legendary(), False)
        self.assertEqual(k.get_tribal(), None)
        self.assertEqual(k.get_subtype(), ["Teekkari", "ISO"])
        self.assertEqual(k.get_colour(), ["Vihreä"])
        self.assertEqual(k.get_manacost(), "2U")
        self.assertEqual(k.get_power(), 3)
        self.assertEqual(k.get_toughness(), 2)
        self.assertEqual(k.get_feature(), ["Haste", "Trample"])
        self.assertEqual(k.get_feature2(), [])
        self.assertEqual(k.get_ruletext(), "Party Tutor rule")
        self.assertEqual(k.get_flavourtext(), "Party")
        self.assertEqual(k.get_creator(), "Masa")
        self.assertEqual(k.get_seticon(), "img/seticon1")
        self.assertEqual(k.get_rarity(), "Common")

    # Enchantment
    def test_copy_enchantment(self):
        self.set_card()
        k = Enchantment(self.card.get_name())
        k.copy(self.card)
        self.assertEqual(k.get_id(), "1234567")
        self.assertEqual(k.get_name(), "Party Tutor")
        self.assertEqual(k.get_image(), "img/partytutor")
        self.assertEqual(k.get_maintype(), "Enchantment")
        self.assertEqual(k.get_legendary(), False)
        self.assertEqual(k.get_tribal(), True)
        self.assertEqual(k.get_subtype(), ["Teekkari", "ISO"])
        self.assertEqual(k.get_colour(), ["Vihreä"])
        self.assertEqual(k.get_manacost(), "2U")
        self.assertEqual(k.get_power(), None)
        self.assertEqual(k.get_toughness(), None)
        self.assertEqual(k.get_feature(), [])
        self.assertEqual(k.get_feature2(),
                         ["Hexproof", "Indestructible", "Flash"])
        self.assertEqual(k.get_ruletext(), "Party Tutor rule")
        self.assertEqual(k.get_flavourtext(), "Party")
        self.assertEqual(k.get_creator(), "Masa")
        self.assertEqual(k.get_seticon(), "img/seticon1")
        self.assertEqual(k.get_rarity(), "Common")

    # Enchantment creature
    def test_copy_enchantment_creature(self):
        self.set_card()
        k = EnchantmentCreature(self.card.get_name())
        k.copy(self.card)
        self.assertEqual(k.get_id(), "1234567")
        self.assertEqual(k.get_name(), "Party Tutor")
        self.assertEqual(k.get_image(), "img/partytutor")
        self.assertEqual(k.get_maintype(), "Enchantment Creature")
        self.assertEqual(k.get_legendary(), False)
        self.assertEqual(k.get_tribal(), None)
        self.assertEqual(k.get_subtype(), ["Teekkari", "ISO"])
        self.assertEqual(k.get_colour(), ["Vihreä"])
        self.assertEqual(k.get_manacost(), "2U")
        self.assertEqual(k.get_power(), 3)
        self.assertEqual(k.get_toughness(), 2)
        self.assertEqual(k.get_feature(), ["Haste", "Trample"])
        self.assertEqual(k.get_feature2(), [])
        self.assertEqual(k.get_ruletext(), "Party Tutor rule")
        self.assertEqual(k.get_flavourtext(), "Party")
        self.assertEqual(k.get_creator(), "Masa")
        self.assertEqual(k.get_seticon(), "img/seticon1")
        self.assertEqual(k.get_rarity(), "Common")

    # Instant
    def test_copy_instant(self):
        self.set_card()
        k = Instant(self.card.get_name())
        k.copy(self.card)
        self.assertEqual(k.get_id(), "1234567")
        self.assertEqual(k.get_name(), "Party Tutor")
        self.assertEqual(k.get_image(), "img/partytutor")
        self.assertEqual(k.get_maintype(), "Instant")
        self.assertEqual(k.get_legendary(), False)
        self.assertEqual(k.get_tribal(), True)
        self.assertEqual(k.get_subtype(), ["Teekkari", "ISO"])
        self.assertEqual(k.get_colour(), ["Vihreä"])
        self.assertEqual(k.get_manacost(), "2U")
        self.assertEqual(k.get_power(), None)
        self.assertEqual(k.get_toughness(), None)
        self.assertEqual(k.get_feature(), None)
        self.assertEqual(k.get_feature2(), [])
        self.assertEqual(k.get_ruletext(), "Party Tutor rule")
        self.assertEqual(k.get_flavourtext(), "Party")
        self.assertEqual(k.get_creator(), "Masa")
        self.assertEqual(k.get_seticon(), "img/seticon1")
        self.assertEqual(k.get_rarity(), "Common")
        self.assertEqual(k.get_feature_print(), "")
        k.remove_feature("Haste")
        self.assertEqual(k.get_feature_list(), [])

    # Land
    def test_copy_land(self):
        self.set_card()
        k = Land(self.card.get_name())
        k.copy(self.card)
        self.assertEqual(k.get_id(), "1234567")
        self.assertEqual(k.get_name(), "Party Tutor")
        self.assertEqual(k.get_image(), "img/partytutor")
        self.assertEqual(k.get_maintype(), "Land")
        self.assertEqual(k.get_legendary(), False)
        self.assertEqual(k.get_tribal(), None)
        self.assertEqual(k.get_subtype(), ["Teekkari", "ISO"])
        self.assertEqual(k.get_colour(), ["Vihreä"])
        self.assertEqual(k.get_manacost(), None)
        self.assertEqual(k.get_power(), None)
        self.assertEqual(k.get_toughness(), None)
        self.assertEqual(k.get_feature(), [])
        self.assertEqual(k.get_feature2(), ["Hexproof", "Indestructible"])
        self.assertEqual(k.get_ruletext(), "Party Tutor rule")
        self.assertEqual(k.get_flavourtext(), "Party")
        self.assertEqual(k.get_creator(), "Masa")
        self.assertEqual(k.get_seticon(), "img/seticon1")
        self.assertEqual(k.get_rarity(), "Common")

    # Planeswalker
    def test_copy_planeswalker(self):
        self.set_card()
        k = Planeswalker(self.card.get_name())
        k.copy(self.card)
        self.assertEqual(k.get_id(), "1234567")
        self.assertEqual(k.get_name(), "Party Tutor")
        self.assertEqual(k.get_image(), "img/partytutor")
        self.assertEqual(k.get_maintype(), "Planeswalker")
        self.assertEqual(k.get_legendary(), False)
        self.assertEqual(k.get_tribal(), None)
        self.assertEqual(k.get_subtype(), ["Teekkari", "ISO"])
        self.assertEqual(k.get_colour(), ["Vihreä"])
        self.assertEqual(k.get_manacost(), "2U")
        self.assertEqual(k.get_power(), 3)
        self.assertEqual(k.get_toughness(), 2)
        self.assertEqual(k.get_feature(), ["Haste", "Trample"])
        self.assertEqual(k.get_feature2(), [])
        self.assertEqual(k.get_ruletext(), "Party Tutor rule")
        self.assertEqual(k.get_flavourtext(), "Party")
        self.assertEqual(k.get_creator(), "Masa")
        self.assertEqual(k.get_seticon(), "img/seticon1")
        self.assertEqual(k.get_rarity(), "Common")

    # Sorcery
    def test_copy_sorcery(self):
        self.set_card()
        k = Sorcery(self.card.get_name())
        k.copy(self.card)
        self.assertEqual(k.get_id(), "1234567")
        self.assertEqual(k.get_name(), "Party Tutor")
        self.assertEqual(k.get_image(), "img/partytutor")
        self.assertEqual(k.get_maintype(), "Sorcery")
        self.assertEqual(k.get_legendary(), False)
        self.assertEqual(k.get_tribal(), True)
        self.assertEqual(k.get_subtype(), ["Teekkari", "ISO"])
        self.assertEqual(k.get_colour(), ["Vihreä"])
        self.assertEqual(k.get_manacost(), "2U")
        self.assertEqual(k.get_power(), None)
        self.assertEqual(k.get_toughness(), None)
        self.assertEqual(k.get_feature(), None)
        self.assertEqual(k.get_feature2(), [])
        self.assertEqual(k.get_ruletext(), "Party Tutor rule")
        self.assertEqual(k.get_flavourtext(), "Party")
        self.assertEqual(k.get_creator(), "Masa")
        self.assertEqual(k.get_seticon(), "img/seticon1")
        self.assertEqual(k.get_rarity(), "Common")
Example #20
0
class TestCardRepository(unittest.TestCase):
    def setUp(self):
        card_repository.delete_all()
        self.card1 = Card('Teemu Kerppu')
        self.card2 = Creature('Kana')
        self.card3 = Instant('Kortti')
        self.card4 = Creature('Kana2')

        self.card1.set_cubes(["id1"])
        self.card2.set_cubes(["id1"])
        self.card3.set_cubes(["id2"])
        self.card4.set_cubes(["id1"])

    def test_create(self):
        card_repository.create(self.card1)
        cards = card_repository.find_all()

        self.assertEqual(len(cards), 1)
        self.assertEqual(cards[0][1], self.card1.get_name())

    def test_save_create(self):
        card_repository.save(self.card1)
        cards = card_repository.find_all()

        self.assertEqual(len(cards), 1)
        self.assertEqual(cards[0][1], self.card1.get_name())

    def test_save_update(self):
        card_repository.create(self.card1)
        self.card1.set_name("Korppu")
        card_repository.save(self.card1)
        cards = card_repository.find_all()

        self.assertEqual(len(cards), 1)
        self.assertEqual(cards[0][1], "Korppu")

    def test_delete(self):
        card_repository.create(self.card1)
        cards = card_repository.find_all()
        self.assertEqual(len(cards), 1)
        self.assertEqual(cards[0][1], "Teemu Kerppu")
        
        card_repository.delete(self.card1.get_id())
        cards = card_repository.find_all()
        self.assertEqual(len(cards), 0)

    def test_delete_all(self):
        card_repository.create(self.card1)
        card_repository.create(self.card2)
        card_repository.create(self.card3)
        cards = card_repository.find_all()
        self.assertEqual(len(cards), 3)
        
        card_repository.delete_all()
        cards = card_repository.find_all()
        self.assertEqual(len(cards), 0)

    def test_find_all(self):
        card_repository.create(self.card1)
        card_repository.create(self.card2)
        cards = card_repository.find_all()

        self.assertEqual(len(cards), 2)
        self.assertEqual(cards[0][1], self.card1.get_name())
        self.assertEqual(cards[1][1], self.card2.get_name())

    def test_find_by_cube(self):
        card_repository.create(self.card1)
        card_repository.create(self.card2)
        card_repository.create(self.card3)
        cards = card_repository.find_by_cube("id1")

        self.assertEqual(len(cards), 2)
        self.assertEqual(cards[0][1], self.card1.get_name())
        self.assertEqual(cards[1][1], self.card2.get_name())

    def test_find_by_name_from_cube(self):
        card_repository.create(self.card1)
        card_repository.create(self.card2)
        card_repository.create(self.card3)
        cards = card_repository.find_by_name_from_cube("id1", "kana")

        self.assertEqual(len(cards), 1)
        self.assertEqual(cards[0][1], self.card2.get_name())

    def test_find_cards_from_cube_that_contains(self):
        card_repository.create(self.card1)
        card_repository.create(self.card2)
        card_repository.create(self.card3)
        card_repository.create(self.card4)
        cards = card_repository.find_cards_from_cube_that_contains("id1", "",
                                                "Creature", "", ["name", "ASC"])

        self.assertEqual(len(cards), 2)
        self.assertEqual(cards[0][1], self.card2.get_name())
        self.assertEqual(cards[1][1], self.card4.get_name())

    def test_create_csv_file(self):
        card_repository.create(self.card1)
        card_repository.create(self.card2)
        card_repository.create(self.card3)
        card_repository.create(self.card4)
        cursor = card_repository.create_csv_file("id1")
        cards = cursor.fetchall()

        self.assertEqual(len(cards), 3)
        self.assertEqual(cards[0][1], self.card1.get_name())
        self.assertEqual(cards[1][1], self.card2.get_name())
        self.assertEqual(cards[2][1], self.card4.get_name())
Example #21
0
 def remove_card(self, code):
     c = Card.decode(code)
     self._deck.remove(c)
Example #22
0
class TestKorttikubeService(unittest.TestCase):
    def setUp(self):
        self.kks = KorttikubeService(FakeCardRepository([]),
                                     FakeCubeRepository([]),
                                     FakeUserRepository([]))
        self.card = Card("Testi")
        self.cube = Cube("Testikube")
        self.user = User("Testaaja", "testo")
        self.card_db = ('ac9a8253-5b78-4010-9aab-516dd1b00879', 'Peruna', \
                          '7132ac94-3e63-4fc8-9d33-5b8e7a2280cd', 'Instant', \
                          1, 0, 'Pottu', 'Valkoinen', '2U', None, \
                          'Peruna on pyöreä.', 'Peruna on soikea.', \
                          None, None, 'kuva', 'tunnus', 'rare', 'Tekijä', 'joku')
        self.cube_db = ('ac9a8253-5b78-4010-9aab-516dd1b00879', 'Kube', \
                        '7132ac94-3e63-4fc8-9d33-5b8e7a2280cd', 'kuva', \
                        'tunnus')
        self.user_db = ('Käyttäjä', 'salasana')

    def set_user_and_cube(self):
        user = self.kks.create_user("Testuri", "sana")
        self.kks.save_to_database(user, "user")
        cube = self.kks.create_cube_entity("Testikube2")
        self.kks.save_to_database(cube, "cube")
        return user, cube

    # GET
    def test_get(self):
        self.assertEqual(self.kks.get_card(), None)
        self.assertEqual(self.kks.get_cube(), None)
        self.assertEqual(self.kks.get_user(), None)

    # SET
    def test_set(self):
        self.kks.set_card(self.card)
        self.assertEqual(self.kks.get_card(), self.card)
        self.kks.set_cube(self.cube)
        self.assertEqual(self.kks.get_cube(), self.cube)
        self.kks.set_user(self.user)
        self.assertEqual(self.kks.get_user(), self.user)

    # LOGIN AND LOGOUT
    def test_login_logout(self):
        self.kks.save_to_database(self.user, "user")
        user = self.kks.login("Testaaja", "testo")
        self.assertEqual(user.get_username(), "Testaaja")
        self.assertEqual(self.kks.get_user().get_username(), "Testaaja")
        self.kks.logout()
        self.assertEqual(self.kks.get_user(), None)

    def test_login_wrong_user(self):
        user = self.kks.login("Testaaja", "testo")
        self.assertEqual(user, False)

    def test_login_wrong_password(self):
        self.kks.save_to_database(self.user, "user")
        user = self.kks.login("Testaaja", "pesto")
        self.assertEqual(user, False)

    # SET ENTITIES
    def test_create_card_entity_db(self):
        db_row = self.card_db
        card = self.kks.create_card_entity_from_db(db_row)
        self.assertEqual(card.get_id(), db_row[0])
        self.assertEqual(card.get_name(), db_row[1])
        self.assertEqual(card.get_cubes(), [db_row[2]])
        self.assertEqual(card.get_maintype(), db_row[3])
        self.assertEqual(card.get_legendary(), db_row[4])
        self.assertEqual(card.get_tribal(), db_row[5])
        self.assertEqual(card.get_subtype(), [db_row[6]])
        self.assertEqual(card.get_colour(), [db_row[7]])
        self.assertEqual(card.get_manacost(), db_row[8])
        self.assertEqual(card.get_feature(), db_row[9])
        self.assertEqual(card.get_ruletext(), db_row[10])
        self.assertEqual(card.get_flavourtext(), db_row[11])
        self.assertEqual(card.get_power(), db_row[12])
        self.assertEqual(card.get_toughness(), db_row[13])
        self.assertEqual(card.get_image(), db_row[14])
        self.assertEqual(card.get_seticon(), db_row[15])
        self.assertEqual(card.get_rarity(), db_row[16])
        self.assertEqual(card.get_creator(), db_row[17])

    def test_create_card_entity_db_types(self):
        db_row = list(self.card_db)
        db_row[3] = ""
        card = self.kks.create_card_entity_from_db(tuple(db_row))
        self.assertEqual(card.get_maintype(), "")
        db_row[3] = "Creature"
        card = self.kks.create_card_entity_from_db(tuple(db_row))
        self.assertEqual(card.get_maintype(), "Creature")
        db_row[3] = "Artifact"
        card = self.kks.create_card_entity_from_db(tuple(db_row))
        self.assertEqual(card.get_maintype(), "Artifact")
        db_row[3] = "Enchantment"
        card = self.kks.create_card_entity_from_db(tuple(db_row))
        self.assertEqual(card.get_maintype(), "Enchantment")
        db_row[3] = "Land"
        card = self.kks.create_card_entity_from_db(tuple(db_row))
        self.assertEqual(card.get_maintype(), "Land")
        db_row[3] = "Sorcery"
        card = self.kks.create_card_entity_from_db(tuple(db_row))
        self.assertEqual(card.get_maintype(), "Sorcery")
        db_row[3] = "Planeswalker"
        card = self.kks.create_card_entity_from_db(tuple(db_row))
        self.assertEqual(card.get_maintype(), "Planeswalker")
        db_row[3] = "Artifact Creature"
        card = self.kks.create_card_entity_from_db(tuple(db_row))
        self.assertEqual(card.get_maintype(), "Artifact Creature")
        db_row[3] = "Enchantment Creature"
        card = self.kks.create_card_entity_from_db(tuple(db_row))
        self.assertEqual(card.get_maintype(), "Enchantment Creature")

    def test_create_cube_entity_db(self):
        db_row = self.cube_db
        cube = self.kks.create_cube_entity_from_db(db_row)
        self.assertEqual(cube.get_id(), db_row[0])
        self.assertEqual(cube.get_name(), db_row[1])
        self.assertEqual(cube.get_users(), [db_row[2]])
        self.assertEqual(cube.get_image(), db_row[3])
        self.assertEqual(cube.get_seticon(), db_row[4])

    def test_create_user_entity_db(self):
        db_row = self.user_db
        user = self.kks.create_user_entity_from_db(db_row)
        self.assertEqual(user.get_username(), db_row[0])
        self.assertEqual(user.get_password(), db_row[1])

    # ENTER AND EXIT
    def test_enter_exit_card(self):
        self.kks.enter_card(self.card_db)
        print(self.kks.get_card())
        self.assertEqual(self.kks.get_card().get_name(), "Peruna")
        self.kks.exit_card()
        self.assertEqual(self.kks.get_card(), None)

    def test_enter_exit_cube(self):
        self.kks.enter_cube(self.cube_db)
        self.assertEqual(self.kks.get_cube().get_name(), "Kube")
        self.kks.exit_cube()
        self.assertEqual(self.kks.get_cube(), None)

    # CREATE ENTITIES
    def test_create_card_entity(self):
        self.kks.set_user(self.user)
        self.kks.set_cube(self.cube)
        card = self.kks.create_card_entity("Kortti")
        self.assertEqual(card.get_name(), "Kortti")
        self.assertEqual(card.get_cubes(), [self.cube.get_id()])

    def test_create_cube_entity(self):
        self.kks.set_user(self.user)
        cube = self.kks.create_cube_entity("Kube2")
        self.assertEqual(cube.get_name(), "Kube2")
        self.assertEqual(cube.get_users(), [self.user.get_username()])

    def test_create_user_entity(self):
        user = self.kks.create_user("Kana", "sana")
        self.assertEqual(user.get_username(), "Kana")
        self.assertEqual(user.get_password(), "sana")

    def test_create_user_exists(self):
        user = self.kks.create_user("Kana", "sana2")
        self.kks.save_to_database(user, "user")
        user = self.kks.create_user("Kana", "sana")
        self.assertEqual(user, False)

    # OTHER
    def test_change_card_type(self):
        self.assertEqual(self.card.get_name(), "Testi")
        self.assertEqual(self.card.get_maintype(), "")
        self.assertEqual(self.card.get_power(), 0)
        new_card = self.kks.change_card_type(self.card, "Land")
        self.assertEqual(new_card.get_name(), "Testi")
        self.assertEqual(new_card.get_maintype(), "Land")
        self.assertEqual(new_card.get_power(), None)

    def test_change_card_type_all(self):
        new_card = self.kks.change_card_type(self.card, "Creature")
        self.assertEqual(new_card.get_maintype(), "Creature")
        new_card = self.kks.change_card_type(self.card, "Artifact")
        self.assertEqual(new_card.get_maintype(), "Artifact")
        new_card = self.kks.change_card_type(self.card, "Enchantment")
        self.assertEqual(new_card.get_maintype(), "Enchantment")
        new_card = self.kks.change_card_type(self.card, "Instant")
        self.assertEqual(new_card.get_maintype(), "Instant")
        new_card = self.kks.change_card_type(self.card, "Sorcery")
        self.assertEqual(new_card.get_maintype(), "Sorcery")
        new_card = self.kks.change_card_type(self.card, "Planeswalker")
        self.assertEqual(new_card.get_maintype(), "Planeswalker")
        new_card = self.kks.change_card_type(self.card, "Artifact Creature")
        self.assertEqual(new_card.get_maintype(), "Artifact Creature")
        new_card = self.kks.change_card_type(self.card, "Enchantment Creature")
        self.assertEqual(new_card.get_maintype(), "Enchantment Creature")

    def test_update_card(self):
        self.assertEqual(self.card.get_name(), "Testi")
        self.assertEqual(self.card.get_maintype(), "")
        self.assertEqual(self.card.get_colour(), [])
        self.assertEqual(self.card.get_feature(), [])
        self.assertEqual(self.card.get_power(), 0)
        self.kks.update_card(self.card, "Uusi", "name")
        self.assertEqual(self.card.get_name(), "Uusi")
        self.assertEqual(self.card.get_maintype(), "")
        self.assertEqual(self.card.get_colour(), [])
        self.assertEqual(self.card.get_feature(), [])
        self.assertEqual(self.card.get_power(), 0)
        self.kks.update_card(self.card, "Vihreä", "colour", True)
        self.assertEqual(self.card.get_name(), "Uusi")
        self.assertEqual(self.card.get_maintype(), "")
        self.assertEqual(self.card.get_colour(), ["Vihreä"])
        self.assertEqual(self.card.get_feature(), [])
        self.assertEqual(self.card.get_power(), 0)
        self.kks.update_card(self.card, 5, "power")
        self.assertEqual(self.card.get_name(), "Uusi")
        self.assertEqual(self.card.get_maintype(), "")
        self.assertEqual(self.card.get_colour(), ["Vihreä"])
        self.assertEqual(self.card.get_feature(), [])
        self.assertEqual(self.card.get_power(), 5)
        self.kks.update_card(self.card, "Haste", "feature", True)
        self.assertEqual(self.card.get_name(), "Uusi")
        self.assertEqual(self.card.get_maintype(), "")
        self.assertEqual(self.card.get_colour(), ["Vihreä"])
        self.assertEqual(self.card.get_feature(), ["Haste"])
        self.assertEqual(self.card.get_power(), 5)
        self.kks.update_card(self.card, "Flying", "feature", True)
        self.assertEqual(self.card.get_name(), "Uusi")
        self.assertEqual(self.card.get_maintype(), "")
        self.assertEqual(self.card.get_colour(), ["Vihreä"])
        self.assertEqual(self.card.get_feature(), ["Haste", "Flying"])
        self.assertEqual(self.card.get_power(), 5)
        self.kks.update_card(self.card, "Firststike", "feature", False)
        self.assertEqual(self.card.get_name(), "Uusi")
        self.assertEqual(self.card.get_maintype(), "")
        self.assertEqual(self.card.get_colour(), ["Vihreä"])
        self.assertEqual(self.card.get_feature(), ["Haste", "Flying"])
        self.assertEqual(self.card.get_power(), 5)
        self.kks.update_card(self.card, "Haste", "feature", False)
        self.assertEqual(self.card.get_name(), "Uusi")
        self.assertEqual(self.card.get_maintype(), "")
        self.assertEqual(self.card.get_colour(), ["Vihreä"])
        self.assertEqual(self.card.get_feature(), ["Flying"])
        self.assertEqual(self.card.get_power(), 5)

    def test_update_card_all(self):
        self.kks.update_card(self.card, "000", "cubes")
        self.assertEqual(self.card.get_cubes(), ["000"])
        self.kks.update_card(self.card, 1, "legendary")
        self.assertEqual(self.card.get_legendary(), 1)
        self.kks.update_card(self.card, 1, "tribal")
        self.assertEqual(self.card.get_tribal(), 1)
        self.kks.update_card(self.card, "Lintu", "subtype")
        self.assertEqual(self.card.get_subtype(), ["Lintu"])
        self.kks.update_card(self.card, "Vihreä", "colour", False)
        self.assertEqual(self.card.get_colour(), [])
        self.kks.update_card(self.card, "2U", "manacost")
        self.assertEqual(self.card.get_manacost(), "2U")
        self.kks.update_card(self.card, "teksti", "ruletext")
        self.assertEqual(self.card.get_ruletext(), "teksti")
        self.kks.update_card(self.card, "tarina", "flavourtext")
        self.assertEqual(self.card.get_flavourtext(), "tarina")
        self.kks.update_card(self.card, 2, "toughness")
        self.assertEqual(self.card.get_toughness(), 2)
        self.kks.update_card(self.card, "kuva", "image")
        self.assertEqual(self.card.get_image(), "kuva")
        self.kks.update_card(self.card, "xx", "seticon")
        self.assertEqual(self.card.get_seticon(), "xx")
        self.kks.update_card(self.card, "ei rare", "rarity")
        self.assertEqual(self.card.get_rarity(), "ei rare")
        self.kks.update_card(self.card, "Peruna", "creator")
        self.assertEqual(self.card.get_creator(), "Peruna")
        self.kks.update_card(self.card, "kuva.png", "picture")
        self.assertEqual(self.card.get_picture(), "kuva.png")

    def test_update_cube(self):
        cube = self.cube
        self.kks.set_cube(cube)
        self.assertEqual(cube.get_name(), "Testikube")
        self.assertEqual(cube.get_users(), [])
        self.assertEqual(cube.get_image(), "")
        self.assertEqual(cube.get_seticon(), "")
        self.kks.update_cube("Uusi", "name")
        self.assertEqual(cube.get_name(), "Uusi")
        self.assertEqual(cube.get_users(), [])
        self.assertEqual(cube.get_image(), "")
        self.assertEqual(cube.get_seticon(), "")
        self.kks.update_cube("id1", "users", True)
        self.assertEqual(cube.get_name(), "Uusi")
        self.assertEqual(cube.get_users(), ["id1"])
        self.assertEqual(cube.get_image(), "")
        self.assertEqual(cube.get_seticon(), "")
        self.kks.update_cube("kuva.pngee", "image")
        self.assertEqual(cube.get_name(), "Uusi")
        self.assertEqual(cube.get_users(), ["id1"])
        self.assertEqual(cube.get_image(), "kuva.pngee")
        self.assertEqual(cube.get_seticon(), "")
        self.kks.update_cube("tunnus.pngee", "seticon")
        self.assertEqual(cube.get_name(), "Uusi")
        self.assertEqual(cube.get_users(), ["id1"])
        self.assertEqual(cube.get_image(), "kuva.pngee")
        self.assertEqual(cube.get_seticon(), "tunnus.pngee")

    def test_set_card_frame(self):
        card_frame_image = self.kks.set_card_frame(self.card_db)
        self.assertEqual(card_frame_image, "img/whitecard.png")
        self.card.set_colour(["Punainen"])
        card_frame_image = self.kks.set_card_frame(self.card)
        self.assertEqual(card_frame_image, "img/redcard.png")
        self.card.set_colour(["Sininen"])
        card_frame_image = self.kks.set_card_frame(self.card)
        self.assertEqual(card_frame_image, "img/bluecard.png")
        self.card.set_colour(["Vihreä"])
        card_frame_image = self.kks.set_card_frame(self.card)
        self.assertEqual(card_frame_image, "img/greencard.png")
        self.card.set_colour(["Musta"])
        card_frame_image = self.kks.set_card_frame(self.card)
        self.assertEqual(card_frame_image, "img/blackcard.png")
        self.card.set_colour([])
        card_frame_image = self.kks.set_card_frame(self.card)
        self.assertEqual(card_frame_image, "img/colourlesscard.png")
        self.card.set_colour(["Punainen", "Valkoinen"])
        card_frame_image = self.kks.set_card_frame(self.card)
        self.assertEqual(card_frame_image, "img/goldcard.png")

    #def test_get_cards_that_contains(self):
    #    cards = self.kks.get_cards_that_contains("ko", "Creature", "Monivärinen")
    #    self.assertEqual(cards, [])

    # DATABASE
    def test_get_cards_in_cube(self):
        self.set_user_and_cube()
        cards = self.kks.get_cards_in_cube()
        self.assertEqual(cards, [])
        card = self.kks.create_card_entity("uusi kortti")
        self.kks.save_to_database(card, "card")
        cards = self.kks.get_cards_in_cube()
        self.assertEqual(cards, [card])

    def test_get_cards_that_contains(self):
        self.set_user_and_cube()
        card1 = self.kks.create_card_entity("testikortti")
        card1 = self.kks.change_card_type(card1, "Creature")
        self.kks.update_card(card1, "Punainen", "colour", True)
        self.kks.save_to_database(card1, "card")
        card2 = self.kks.create_card_entity("testi2")
        card2 = self.kks.change_card_type(card2, "Creature")
        self.kks.update_card(card2, "Punainen", "colour", True)
        self.kks.save_to_database(card2, "card")
        card3 = self.kks.create_card_entity("testi1")
        card3 = self.kks.change_card_type(card3, "Instant")
        self.kks.update_card(card3, "Punainen", "colour", True)
        self.kks.save_to_database(card3, "card")
        card4 = self.kks.create_card_entity("kortti")
        card4 = self.kks.change_card_type(card4, "Creature")
        self.kks.update_card(card4, "Punainen", "colour", True)
        self.kks.save_to_database(card4, "card")
        card5 = self.kks.create_card_entity("testikort")
        card5 = self.kks.change_card_type(card5, "Creature")
        self.kks.update_card(card5, "Vihreä", "colour", True)
        self.kks.update_card(card5, "Sininen", "colour", True)
        self.kks.save_to_database(card5, "card")
        card6 = self.kks.create_card_entity("korttitesti1")
        card6 = self.kks.change_card_type(card6, "Creature")
        self.kks.update_card(card6, "Punainen", "colour", True)
        self.kks.save_to_database(card6, "card")
        cards = self.kks.get_cards_that_contains("testi", "Creature",
                                                 "Punainen", "")
        self.assertEqual(cards, [card1, card2, card6])

    def test_get_cards_that_contains_multicolour(self):
        self.set_user_and_cube()
        card1 = self.kks.create_card_entity("testikortti")
        card1 = self.kks.change_card_type(card1, "Creature")
        self.kks.update_card(card1, "Vihreä", "colour", True)
        self.kks.save_to_database(card1, "card")
        card2 = self.kks.create_card_entity("testi2")
        card2 = self.kks.change_card_type(card2, "Creature")
        self.kks.update_card(card2, "Punainen", "colour", True)
        self.kks.update_card(card2, "Sininen", "colour", True)
        self.kks.save_to_database(card2, "card")
        card3 = self.kks.create_card_entity("testikort")
        card3 = self.kks.change_card_type(card3, "Creature")
        self.kks.update_card(card3, "Vihreä", "colour", True)
        self.kks.update_card(card3, "Sininen", "colour", True)
        self.kks.save_to_database(card3, "card")
        cards = self.kks.get_cards_that_contains("testi", "Creature",
                                                 "Monivärinen", "")
        self.assertEqual(cards, [card2, card3])

    def test_get_cubes_from_user(self):
        suser, cube = self.set_user_and_cube()
        cubes = self.kks.get_cubes_from_user()
        self.assertEqual(cubes, [cube])

    def test_get_users_in_cube(self):
        self.set_user_and_cube()
        users = self.kks.get_users_in_cube()
        self.assertEqual(users, ["Testuri"])

    def test_get_users(self):
        users = self.kks.get_users()
        self.assertEqual(users, [])
        self.kks.save_to_database(self.user, "user")
        users = self.kks.get_users()
        self.assertEqual(users, [self.user])

    def test_delete_card(self):
        self.set_user_and_cube()
        cards = self.kks.get_cards_in_cube()
        self.assertEqual(cards, [])
        card = self.kks.create_card_entity("Testcard123")
        self.kks.save_to_database(card, "card")
        cards = self.kks.get_cards_in_cube()
        self.assertEqual(cards, [card])
        self.kks.delete_card()
        cards = self.kks.get_cards_in_cube()
        self.assertEqual(cards, [])

    def test_user_creates_account_cube_and_card(self):
        user = self.kks.create_user("nimi", "salasana")
        self.assertEqual(user.get_username(), "nimi")
        self.kks.login("nimi", "salasana")
        cube = self.kks.create_cube_entity("uusikube")
        self.kks.set_cube(cube)
        self.assertEqual(self.kks.get_cube().get_name(), "uusikube")
        card = self.kks.create_card_entity("uusikortti")
        self.kks.set_card(card)
        self.assertEqual(self.kks.get_card().get_name(), "uusikortti")

    def test_creating_card_with_existing_name(self):
        self.set_user_and_cube()
        card = self.kks.create_card_entity("Testikortti")
        self.kks.save_to_database(card, "card")
        card2 = self.kks.create_card_entity("testikortti")
        exists = self.kks.check_if_card_exists(card2)
        self.assertTrue(exists)
        exists = self.kks.check_if_card_exists(card)
        self.assertFalse(exists)
        card3 = self.kks.create_card_entity("EiKortti")
        exists = self.kks.check_if_card_exists(card3)
        self.assertFalse(exists)
Example #23
0
def step_add_card(context, card_number, card_type):
    card = Card(card_number, card_type)
    context.player.add_card_to_hand(card)
Example #24
0
def step_add_card_to_table(context, card_number, card_type):
    card = Card(card_number, card_type)
    context.game.table.append(card)