def handle(self, *args, **options):
        models_to_track = [Set, Card, Printing]
        initial = {model: model.objects.count() for model in models_to_track}

        p = inflect.engine()
        set_codes = options['set_code']
        if set_codes:
            count = len(set_codes)
            set_string = 'num({count}) plural_noun(set) ({codes})'.format(
                count=count, codes=', '.join(set_codes))
        else:
            set_string = 'all sets'

        self.stdout.write(
            p.inflect("Beginning import of {}.".format(set_string)))
        import_cards(set_codes or Everything)
        self.stdout.write("Import complete.")

        final = {model: model.objects.count() for model in models_to_track}
        status_strings = [
            p.inflect("{0} new num({0},)plural_noun({1})".format(
                final[model] - initial[model], model._meta.object_name))
            for model in models_to_track
        ]
        self.stdout.write("Added {}.".format(p.join(status_strings)))
    def test_planeswalker_loyalty(self):
        import_cards(["AVR"])

        tamiyo = Card.objects.get(name="Tamiyo, the Moon Sage")
        self.assertEqual(tamiyo.loyalty, 4)

        tracker = Card.objects.get(name="Ulvenwald Tracker")
        self.assertIsNone(tracker.loyalty)
Exemple #3
0
    def test_import_is_idempotent(self):
        """
        Importing the same set additional times has no effect (assuming the same data)
        """
        import_cards(["AKH"])
        import_cards(["AKH"])

        self.assertEqual(Set.objects.count(), 1)
        self.assertEqual(Card.objects.count(), 287)
        self.assertEqual(Printing.objects.count(), 302)
    def test_long_card_name(self):
        """
        The longest card name can be successfully imported and stored fully in the database.
        """
        import_cards(["UNH"])

        longest_name = "Our Market Research Shows That Players Like Really Long Card Names " \
                       "So We Made this Card to Have the Absolute Longest Card Name Ever Elemental"
        longest_name_card = Card.objects.get(name=longest_name)
        self.assertEqual(longest_name_card.name, longest_name)
        # SQLite does not actually enforce the length of a VARCHAR, but Django will validate
        # if we call full_clean.
        longest_name_card.full_clean()
Exemple #5
0
    def test_reimport_sets_without_multiverse_ids(self):
        """
        Even if a set does not have proper multiverse_ids in MTGJSON, importing it
        multiple times has no effect and does not crash.
        """
        import_cards(["CED"])
        card_count = Card.objects.count()
        printing_count = Printing.objects.count()

        import_cards(["CED"])

        self.assertEqual(Set.objects.count(), 1)
        self.assertEqual(Card.objects.count(), card_count)
        self.assertEqual(Printing.objects.count(), printing_count)
Exemple #6
0
    def test_import_single_set(self):
        import_cards(["SOM"])

        self.assertEqual(Set.objects.count(), 1)
        scars = Set.objects.first()
        self.assertEqual(scars.name, "Scars of Mirrodin")
        self.assertEqual(scars.code, "SOM")

        self.assertEqual(Card.objects.count(), SOM_CARDS)
        #   234 Distinctly-named cards

        self.assertEqual(Printing.objects.count(), SOM_PRINTINGS)
        #   234 Number of cards
        # +  15 Each of the 5 basic lands has 3 additional arts

        self.check_common_set_constraints()
Exemple #7
0
    def test_import_betrayers(self):
        """
        Data integrity issues from a bug in MTGJSON are cleaned up by the import process.
        """
        import_cards(["BOK"])

        self.assertEqual(Set.objects.count(), 1)
        betrayers = Set.objects.first()
        self.assertEqual(betrayers.name, "Betrayers of Kamigawa")
        self.assertEqual(betrayers.code, "BOK")

        self.assertEqual(Card.objects.count(), 170)
        #   170 Distinctly-named cards

        self.assertEqual(Printing.objects.count(), 170)
        #   170 Number of cards
        # +   0 Basic lands

        self.check_common_set_constraints()
Exemple #8
0
    def test_import_single_set_with_split_cards(self):
        import_cards(["AKH"])

        self.assertEqual(Set.objects.count(), 1)
        amonkhet = Set.objects.first()
        self.assertEqual(amonkhet.name, "Amonkhet")
        self.assertEqual(amonkhet.code, "AKH")

        self.assertEqual(Card.objects.count(), 287)
        #   239 Distinctly named non-split cards
        # +  15 Top halves of split cards
        # +  15 Bottom halves of split cards
        # +   8 Cards from Planeswalker decks
        # +  10 Dual lands

        self.assertEqual(Printing.objects.count(), 302)
        #   287 Number of cards
        # +  15 Each of the 5 basic lands has 3 additional arts

        self.check_common_set_constraints()