def test_query_cards(self): # initialize some sample cards # testing comment user = self.generate_user(COOL_USERNAME, PASSWORD) card_names = [ "Jace, The Mind Sculptor", "Jace's Defeat", "Jace, Vrynn's Prodigy", "Jackal Pup", "Scalding Tarn", "Ancestral Vision", "Serum Visions", "Lightning Bolt", "Forked Bolt", "Boltwing Marauder", "Firebolt" ] for name in card_names: new_card = Card(name) db.session.add(new_card) db.session.commit() # assert that each query for a specific card has exactly one match. # Note for our input that none of the names are substrings of another for name in card_names: sample = Card.query.filter_by( search_name=Card.format_card_name_for_search(name)).first() query = user.query_cards(name) self.assertEqual(len(query), 1) # these queries have the query amount and expected output test_queries = [("Tarn", 1), ("Jace", 3), ("jace", 3), ("Jac", 4), ("bolt", 4), ("vision", 2), ("visions", 1)] for test in test_queries: card_name = test[0] expected_quantity = test[1] query = user.query_cards(card_name) self.assertEqual(len(query), expected_quantity)
def test_card_search_name(self): # there's 18000 in this AllCards.json so we only check some of them # This variable can be adjusted to check all of them # To check all 18000 cards, it will take at least 30 seconds # and will bog down other tests NUM_CARDS_TO_CHECK = 100 with open("./data/AllCards.json", "r") as f: card_data = json.load(f) count = 0 for name in card_data: if count < NUM_CARDS_TO_CHECK: new_card = Card(name) db.session.add(new_card) count += 1 db.session.commit() count = 0 for name in card_data: if count < NUM_CARDS_TO_CHECK: card = Card.search_card_by_name(name) self.assertIsNotNone(card) formatted_name = Card.format_card_name_for_search(name) cards = Card.query.filter_by(search_name=formatted_name).all() self.assertEqual(len(cards), 1) count += 1