Exemplo n.º 1
0
class TestCase(unittest.TestCase):
    def setUp(self):
        Hero.objects.all().delete()
        self.h1 = Hero(name=u'Książę Karol')
        self.h2 = Hero(name=u'Królowa Karolina')
        self.h1.save()
        self.h2.save()

        reka = ItemSlot(name=u'prawa ręka')
        reka.save()

        self.sword = Item(name=u'Srebrny Miecz', location=reka, min_lvl=0)
        Item.objects.all().delete()
        self.sword.save()
        self.sword.spawn(1, self.h1).save()

    def test_ownership(self):
        foundItems = ItemInstance.objects.filter(owner=self.h1)
        print type(foundItems)
        self.assertEqual(foundItems.count(), 1)
        self.assertEqual(foundItems[0].item.name, u'Srebrny Miecz')
Exemplo n.º 2
0
    def setUp(self):
        Hero.objects.all().delete()
        self.h1 = Hero(name=u'Książę Karol')
        self.h2 = Hero(name=u'Królowa Karolina')
        self.h1.save()
        self.h2.save()

        reka = ItemSlot(name=u'prawa ręka')
        reka.save()

        self.sword = Item(name=u'Srebrny Miecz', location=reka, min_lvl=0)
        Item.objects.all().delete()
        self.sword.save()
        self.sword.spawn(1, self.h1).save()
characters_count = Character.objects.all().count()
print('How many total Characters are there?', characters_count)

# How many of each specific subclass?
characters_subclasses = Character.__subclasses__()
print('How many of each specific subclass?')
for subclass in characters_subclasses:
    print(subclass.__name__, ':', subclass.objects.all().count())

# How many total Items?
from armory.models import Item
items_count = Item.objects.all().count()
print('How many total Items?', items_count)

# How many of the Items are weapons? How many are not?
weapons_count = Item.__subclasses__()[0].objects.all().count()
print('How many of the Items are weapons?', weapons_count,
      ',How many are not?', items_count - weapons_count)

# On average, how many Items does each Character have?
characters = Character.objects.all()
average_items = 0
for character in characters:
    average_items += character.inventory.count()
average_items = average_items / characters.count()
print('On average, how many Items does each Character have?', average_items)

# On average, how many Weapons does each character have?
average_weapons = 0
for character in characters:
    average_weapons += character.inventory.filter(weapon=None)