Example #1
0
    def saveChangesToModel(self, currStep):
        if currStep == StepOne:
            self.model.set(
                "afkMessage",
                self.rootframe.rootEntry.get("1.0",
                                             tkinter.END).replace("\n", ""))
        elif currStep == StepTwo:
            self.model.set("defaultKey", self.rootframe.radiostatus.get())
            self.model.set("specialKey",
                           self.rootframe.specialKeyEntry.get()[0])
        elif currStep == StepThree:
            self.model.set('numberOfSlotsNeeded',
                           len(self.get_all_children(self.rootframe.treeview)))
            self.model.initializeSlots()
            for itemm in self.get_all_children(self.rootframe.treeview):
                dictItem = self.rootframe.treeview.item(itemm)
                slot = int(dictItem['text'])
                item2 = str(dictItem['values'][0])
                count = int(dictItem['values'][1])
                price = int(dictItem['values'][2])

                newslot = InventorySlot.InventorySlot(slot, item2, price,
                                                      count)
                self.model.addSlot(newslot)
        elif currStep == lastStep:
            self.model.set("filepath", self.rootframe.entryForFilepath.get())
            self.model.set("filename", self.rootframe.filenameEntry.get())
Example #2
0
    def test_InventorySlotGiven_addsToModel_addsCorrectly(self):
        #Arrange
        pm = PresetModel.PresetModel()
        ex = InventorySlot.InventorySlot(1, "My Item", 10, 5)
        ex2 = InventorySlot.InventorySlot(2, "MY Item 2", 24, 64)

        #Act
        pm.addSlot(ex)
        pm.addSlot(ex2)

        #Assert
        self.assertEqual(pm.slot1.getCount(), 5)
        self.assertEqual(pm.slot2.getCount(), 64)
        self.assertEqual(pm.slot1.getPosition(), 1)
        self.assertEqual(pm.slot2.getPosition(), 2)
        self.assertEqual(pm.slot3, None)
 def test_CreateNewSlot_fillByConstructor_filledCorrectly(self):
     #Arrange + Act
     slot = InventorySlot.InventorySlot(2, "My Item", 100, 3)
     #Assert
     self.assertEqual(slot.getCount(), 3)
     self.assertEqual(slot.getItem(), "My Item")
     self.assertEqual(slot.getPosition(), 2)
     self.assertEqual(slot.getPrice(), 100)
 def test_filledSlotGiven_clearSlot_slotBackToDefaults(self):
     #Arrange
     slot = InventorySlot.InventorySlot(2, "Testitem, 25, 3")
     #Act
     slot.clear()
     #Assert
     self.assertEqual(slot.getCount(), 0)
     self.assertEqual(slot.getItem(), "")
     self.assertEqual(slot.getPosition(), -1)
     self.assertEqual(slot.getPrice(), -1)
 def __init__(self):
     self.inventorySize = 5
     #print(self.items)
     #for x in range(self.inventorySizeX):
     #    for y in range(self.inventorySizeY):
     #        slot = InventorySlot(x, y, self.items[y][x])
     #        self.items.append(slot)
     self.items = [InventorySlot() for x in range(self.inventorySize)]
     self.str_items = ["null" for x in range(self.inventorySize)]
     self.currentItem = self.items[0].containedItem
Example #6
0
 def readInventoryLine(self, lineToRead):
     #Error Handling muss in Aufruffunktion gemacht werden!
     #data: 1 32 500 bea con
     #data: slot Anzahl Preis Material
     #lineToRead = ['data:', '1', '32', '500', 'bea', con']
     newSlot = InventorySlot.InventorySlot()
     newSlot.setPosition(int(lineToRead[1]))
     newSlot.setCount(int(lineToRead[2]))
     newSlot.setPrice(int(lineToRead[3]))
     newSlot.setItem(' '.join(lineToRead[4:]))
     return newSlot
 def test_CreateNewSlot_fillByAttributes_filledCorrectly(self):
     #Arrange
     slot = InventorySlot.InventorySlot()
     #Act
     slot.setItem("My Item")
     slot.setPosition(2)
     slot.setCount(3)
     slot.setPrice(100)
     #Assert
     self.assertEqual(slot.getCount(), 3)
     self.assertEqual(slot.getItem(), "My Item")
     self.assertEqual(slot.getPosition(), 2)
     self.assertEqual(slot.getPrice(), 100)
Example #8
0
    def test_FilledModelWithSlots_asStr_GivesCorrectString(self):
        #Arrange
        self.maxDiff = None

        model = PresetModel.PresetModel()
        model.set("afkMessage", "Ich bin Testweise Afk")
        model.set("specialKey", 'e')
        model.set("defaultKey", True)
        model.set("filepath", "C:/Programme/AppData")
        model.set("filename", "unittestpreset.preset")
        model.set("numberOfSlotsNeeded", 2)

        slot1 = InventorySlot.InventorySlot(1, "Item 1", 100, 20)
        slot2 = InventorySlot.InventorySlot(2, "Second Item", 250, 64)

        model.addSlot(slot1)
        model.addSlot(slot2)
        #Act
        conv = str(model)
        #Assert
        real = """{'defaultKey': True, 'specialKey': 'e', 'afkMessage': 'Ich bin Testweise Afk', 'numberOfSlotsNeeded': 2, 'filepath': 'C:/Programme/AppData', 'filename': 'unittestpreset.preset'}1 Item 1 100 202 Second Item 250 64NoneNoneNoneNoneNoneNoneNoneNone"""
        self.assertEqual(conv, real)
 def test_EmptySlot_WriteStringToCount_ThrowsTypeError(self):
     #Arrange
     slot = InventorySlot.InventorySlot()
     sCount = partial(slot.setCount, "Stringg")
     #Act + Assert
     self.assertRaises(TypeError, sCount)