Exemplo n.º 1
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")
Exemplo n.º 2
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)