コード例 #1
0
    def test_add_item(self):
        basket = Basket()

        item1 = Item(product=self.product1, quantity=1)  # total 1 x 5 = 5
        two_items1 = Item(product=self.product1,
                          quantity=2)  # total 2 x 5 = 10

        # assert basket is empty before real testing
        self.assertEqual(0, basket.count())
        self.assertIsNone(basket.get_item_from_product(self.product1))
        self.assertIsNone(basket.get_item_from_product(self.product2))

        # add 1 product
        basket.add_item(item1)
        self.assertEqual(item1, basket.get_item_from_product(self.product1))
        self.assertEqual(1, basket.get_quantity_for_product(self.product1))
        self.assertEqual(1, basket.count())
        self.assertEqual(5, basket.get_total())

        # same product, 2 more of them added to basket
        basket.add_item(two_items1)
        self.assertEqual(3, basket.get_quantity_for_product(self.product1))
        self.assertEqual(1, basket.count())
        self.assertEqual(15, basket.get_total())

        item2 = Item(product=self.product2, quantity=5)  # total 5 x 10 = 50
        basket.add_item(item2)

        self.assertEqual(2, basket.count())
        self.assertEqual(65, basket.get_total())
コード例 #2
0
ファイル: crate.py プロジェクト: krieghan/spelunker
 def __init__(self,
              name,
              description=''):
     Item.__init__(self,
                   name=name,
                   displayName='crate',
                   description=description)
コード例 #3
0
def test_filter_items_modified_today_picks_out_items_from_that_day():
    unfiltered_list = [
        Item(
            'yesterday-item',
            'yesterday-title',
            Status.Done.value,
            "2020-06-24T14:51:12.321Z"
        ),
        Item(
            'today-item',
            'today-title',
            Status.Done.value,
            "2020-06-25T14:51:12.321Z"
        ),
        Item(
            'tomorrow-item',
            'tomorrow-title',
            Status.Done.value,
            "2020-06-26T14:51:12.321Z"
        )
    ]

    filtered_items = filter_items_modified_today(unfiltered_list)

    assert len(filtered_items) == 1
    assert filtered_items[0].id == 'today-item'
コード例 #4
0
class ItemTestCase(unittest.TestCase):
    def setUp(self) -> None:
        self.manufacture = Manufacture()
        self.manufacture_name = "Lol"
        self.manufacture.set_name(self.manufacture_name)

        self.product_name1 = "Product 1"
        self.product_sku1 = "a001"
        self.product_price1 = 5

        self.product1 = Product(
            name=self.product_name1,
            sku=self.product_sku1,
            price=self.product_price1,
            manufacture=self.manufacture,
        )

        self.quantity = 10
        self.item = Item(product=self.product1, quantity=self.quantity)

    def test_getter(self):
        self.item = Item(product=self.product1, quantity=10)
        self.assertEqual(self.product1, self.item.product)
        self.assertEqual(self.quantity, self.item.quantity)

    def test_total_price(self):
        self.assertEqual(50, self.item.total_price())

    def test_add_quantity(self):
        self.item.add_quantity(5)
        self.assertEqual(15, self.item.quantity)
コード例 #5
0
ファイル: bag.py プロジェクト: krieghan/spelunker
 def __init__(self,
              name,
              displayName=None,
              description=None,
              shortDescription=None,
              inventory=None,
              aliases=None,
              isGettable=False,
              displayAutomatically=True):
     if inventory is None:
         inventory = InventoryManager(on=False,
                                      inside=True,
                                      under=False)
         inventory.slots['inside'].exposed = False
     Item.__init__(self,
                   name=name,
                   displayName=displayName,
                   description=description,
                   shortDescription=shortDescription,
                   inventory=inventory,
                   aliases=aliases,
                   isGettable=isGettable,
                   displayAutomatically=displayAutomatically)
     
     self.open = False
コード例 #6
0
ファイル: rope.py プロジェクト: krieghan/spelunker
 def __init__(self,
              name):
     Item.__init__(self,
                   name=name,
                   displayName='rope',
                   description='There is a rope here.  It frays in a few places, but is generally sturdy.',
                   aliases=['rope'],
                   isGettable=True)
コード例 #7
0
ファイル: tree.py プロジェクト: krieghan/spelunker
    def __init__(self, name, description="", inventory=None):
        if inventory is None:
            inventory = InventoryManager(on=False, inside=True, under=False)
            inventory.slots["inside"].exposed = False
        Item.__init__(
            self, name=name, description=description, inventory=inventory, displayName="tree", displayAutomatically=True
        )

        self.stateMachine = StateMachine(owner=self, startingState=acornStillInTree)
コード例 #8
0
def stub_get_all_items(collection):
    return [
        Item('test-to-do-item-id', 'Test To Do item Title', 'To Do',
             'Test To Do item Description', '2020-07-30T12:52:06.278Z'),
        Item('test-doing-item-id', 'Test Doing item Title', 'Doing',
             'Test Doing item Description', '2020-07-30T12:52:06.278Z'),
        Item('test-done-item-id', 'Test Done item Title', 'Done',
             'Test Done item Description', '2020-07-30T12:52:06.278Z')
    ]
コード例 #9
0
def view_model():
    return ViewModel(
        [
            Item('to-do-id', 'to-do-title', Status.TO_DO.value, 'to-do-description', "2021-01-01T15:47:23.517Z"),
            Item('doing-id', 'doing-title', Status.DOING.value, 'doing-description', "2021-01-01T15:47:23.517Z"),
            Item('done-id', 'done-title', Status.DONE.value, 'done-description', "2021-01-01T15:47:23.517Z")
        ],
        False
    )
コード例 #10
0
ファイル: paper.py プロジェクト: krieghan/spelunker
 def __init__(self, 
              name):
     Item.__init__(self,
                   name,
                   displayAutomatically=True,
                   isGettable=True,
                   displayName='paper',
                   aliases=['paper'])
     self.text = ''
コード例 #11
0
ファイル: acorn.py プロジェクト: krieghan/spelunker
 def __init__(self,
              name,
              description=''):
     Item.__init__(self,
                   name=name,
                   description=description,
                   displayName='acorn',
                   displayAutomatically=True,
                   isGettable=True)
コード例 #12
0
def stub_get_all_items(collection):
    return [
        Item('test-to-do-card-id', 'Test To Do Card Title', 'To do',
             '2020-06-24T14:51:12.321Z'),
        Item('test-doing-card-id', 'Test Doing Card Title', 'Doing',
             '2020-06-24T14:51:12.321Z'),
        Item('test-done-card-id', 'Test Done Card Title', 'Done',
             '2020-06-24T14:51:12.321Z')
    ]
コード例 #13
0
def done_items_view_model():
    return ViewModel(
        [
            Item('to-do-id', 'to-do-title', Status.DONE.value, '5 days done', datetime.now() - timedelta(days=5)),
            Item('to-do-id', 'to-do-title', Status.DONE.value, '3 hours done', datetime.now() - timedelta(hours=3)),
            Item('to-do-id', 'to-do-title', Status.DONE.value, 'Just done', datetime.now()),
            Item('to-do-id', 'to-do-title', Status.DONE.value, '20 days done', datetime.now() - timedelta(days=20)),
            Item('to-do-id', 'to-do-title', Status.DONE.value, '20 hours done', datetime.now() - timedelta(hours=20))
        ],
        False
    )
コード例 #14
0
ファイル: pond.py プロジェクト: krieghan/spelunker
 def __init__(self,
              name,
              description=''):
     Item.__init__(self,
                   name=name,
                   description=description,
                   displayName='pond',
                   aliases=['pond',
                            'lake',
                            'water'],
                   displayAutomatically=True)
コード例 #15
0
    def test_remove_item(self):

        basket = Basket()
        item1 = Item(product=self.product1, quantity=1)  # total  5 x 1 = 5
        item2 = Item(product=self.product2, quantity=3)  # total 10 x 3 = 30
        basket.add_item(item1)
        basket.add_item(item2)

        self.assertEqual(2, basket.count())
        self.assertEqual(35, basket.get_total())

        # remove Product1
        basket.remove_product(self.product1)
        self.assertIsNone(basket.get_item_from_product(self.product1))
        self.assertEqual(1, basket.count())
        self.assertEqual(30, basket.get_total())
コード例 #16
0
 def __init__(self, entity: Item, view: 'InGameView'):
     super().__init__(entity, view,
                      (InGameView.ITEM_SIZE, InGameView.ITEM_SIZE))
     tile_name = self.ITEMS_NAMES.get(entity.get_incarnation_type())
     self.tile_surface = None if tile_name is None else view.get_item_tilemap(
     ).get_tile(tile_name)
     self.anim_phase_shift = random.random() * math.pi
コード例 #17
0
def doing_item():
    item = Item(
        'doing-id',
        'doing-title',
        Status.Doing.value,
        "2020-06-24T14:51:12.321Z"
    )
    return item
コード例 #18
0
def done_item():
    item = Item(
        'done-id',
        'done-title',
        Status.Done.value,
        "2020-06-24T14:51:12.321Z"
    )
    return item
コード例 #19
0
def to_do_item():
    item = Item(
        'to-do-id',
        'to-do-title',
        Status.ToDo.value,
        "2020-06-24T14:51:12.321Z"
    )
    return item
コード例 #20
0
ファイル: darkHenry.py プロジェクト: krieghan/spelunker
 def handleReceiveGive(self,
                         givingAgent,
                         entityToGive):
     if entityToGive == Item.getItem('Note from Adventurer'):
         self.speak("So I guess Alec didn't make it.  It's a shame.  I'll give the note to Stephanie next time I see her.")
         entityToGive.changeOwner(self)
     else:
         self.speak("What do I look like?  An old canvas sack?  I'm not here to hold onto all that random shit you're picking up, dude.")
コード例 #21
0
    def setUp(self) -> None:
        self.manufacture = Manufacture()
        self.manufacture_name = "Lol"
        self.manufacture.set_name(self.manufacture_name)

        self.product_name1 = "Product 1"
        self.product_sku1 = "a001"
        self.product_price1 = 5

        self.product1 = Product(
            name=self.product_name1,
            sku=self.product_sku1,
            price=self.product_price1,
            manufacture=self.manufacture,
        )

        self.quantity = 10
        self.item = Item(product=self.product1, quantity=self.quantity)
コード例 #22
0
ファイル: queries.py プロジェクト: robin-leach/DevOps-Course
def get_all_items(collection):
    log.debug(f'Fetching all items')
    items = []
    for item in collection.find():
        items.append(
            Item(item['_id'], item['name'], item['status'],
                 item['dateLastActivity']))
    log.debug(f'Found {len(items)} items')
    return items
コード例 #23
0
ファイル: prop.py プロジェクト: krieghan/spelunker
 def __init__(self,
              name,
              displayName=None,
              description=None,
              shortDescription=None,
              inventory=None,
              aliases=None,
              isGettable=False,
              displayAutomatically=False):
     Item.__init__(self,
                   name=name,
                   displayName=displayName,
                   description=description,
                   shortDescription=shortDescription,
                   inventory=inventory,
                   aliases=aliases,
                   isGettable=isGettable,
                   displayAutomatically=displayAutomatically)
コード例 #24
0
ファイル: blueDoor.py プロジェクト: krieghan/spelunker
 def handleReceivingUnlock(self,
                  unlockingAgent,
                  entityToUnlockWith=None):
     if not self.door.locked:
         raise CannotPerformAction('%s is already unlocked.' %
                                   self.getDisplayNameWithDefiniteArticle())
     if entityToUnlockWith == Item.getItem('Blue Key'):
         self.door.locked = False
         print 'You unlock the door.'
     elif entityToUnlockWith is not None:
         raise CannotPerformAction('You cannot unlock %s with %s' %
                                   self.getDisplayNameWithDefiniteArticle(),
                                   entityToUnlockWith.getDisplayNameWithDefiniteArticle())
     else:
         raise CannotPerformAction(
                     'You cannot unlock %s with your bare hands' %
                     self.getDisplayNameWithDefiniteArticle())
コード例 #25
0
ファイル: wolf.py プロジェクト: krieghan/spelunker
 def handleReceiveThrowAt(self,
                        throwingAgent,
                        itemBeingThrown,
                        receivingEntity):
     if itemBeingThrown == Item.getItem('Dagger'):
         print ('The dagger pierces the wolf in the throat.  It lets out '
                'a blood-chilling whine and collapses on the ground.')
         itemBeingThrown.changeOwner(newOwner=receivingEntity,
                                toSlot='inside')
         receivingEntity.inventory.slots['inside'].exposed = True
         receivingEntity.stateMachine.changeState(wolfDeadState)
         receivingEntity.names.append('body')
         
     else:
         print ('The %s hits the wolf squarely in the jaw.  The wolf lunges at you, '
               'tearing out your throat as you go down.' %\
                 itemBeingThrown.getDisplayName())
         raise PlayerDeath()
コード例 #26
0
ファイル: blueDoor.py プロジェクト: krieghan/spelunker
 def handleReceivingLock(self,
                lockingAgent,
                entityToLockWith=None):
     if self.door.locked:
         raise CannotPerformAction('%s is already locked.' %
                                   self.getDisplayNameWithDefiniteArticle())
     if self.door.open:
         raise CannotPerformAction('%s is open.  It cannot be locked at this time.' %
                                   self.getDisplayNameWithDefiniteArticle())
     if entityToLockWith == Item.getItem('Blue Key'):
         self.door.locked = True
         print 'You lock the door.'
     elif entityToLockWith is not None:
         raise CannotPerformAction('You cannot lock %s with %s' %
                                   self.getDisplayNameWithDefiniteArticle(),
                                   entityToLockWith.getDisplayNameWithDefiniteArticle())
     else:
         raise CannotPerformAction(
                     'You cannot lock %s with your bare hands' %
                     self.getDisplayNameWithDefiniteArticle())
コード例 #27
0
 def test_getter(self):
     self.item = Item(product=self.product1, quantity=10)
     self.assertEqual(self.product1, self.item.product)
     self.assertEqual(self.quantity, self.item.quantity)
コード例 #28
0
ファイル: tree.py プロジェクト: krieghan/spelunker
 def handlePositioning(self, positioningAgent, whereToPosition):
     if whereToPosition == "on":
         Item.handlePositioning(self, positioningAgent, whereToPosition)
     else:
         self.stateMachine.currentState.handleGoingUnder(owner=self, positioningAgent=positioningAgent)
コード例 #29
0
ファイル: note.py プロジェクト: krieghan/spelunker
 def read(self):
     if self.text is None:
         Item.read(self)
     else:
         self.speak(self.text)
コード例 #30
0
def fillContainers():
    wall = Item.getItem('Wall')
    pathToTown = Item.getItem('Path To Town')
    
    player = Agent.getAgent('Player')
    player.addEntity(Item.getItem('Note from Unknown Party'))
    
    table = Item.getItem('Table')
    sunlightRoom = Room.getRoom('Sunlight Room')
    sunlightRoom.addEntity(Item.getItem('Note from Adventurer'))
    sunlightRoom.addEntity(table)
    sunlightRoom.addEntity(wall)
    table.addEntity(Item.getItem('Apple'))
    table.addEntity(Item.getItem('Paper'))
    table.addEntity(Item.getItem('Pencil'))
    
    sack = Item.getItem('Canvas Sack')
    entrance = Room.getRoom('Entrance')
    entrance.addEntity(pathToTown)
    entrance.addEntity(wall)
    entrance.addEntity(sack)
    sack.addEntity(Item.getItem('Dagger'))
    
    pathToTownLocation = Room.getRoom('North Of Town')
    pathToTownLocation.addEntity(Item.getItem('Rock'))
    pathToTownLocation.addEntity(pathToTown)
    
    townGate = Room.getRoom('Town Gate')
    townGate.addEntity(Item.getItem('Rope'))
    
    wolfDen = Room.getRoom('Wolf Den')
    wolfDen.addEntity(Agent.getAgent('Wolf'))
    wolfDen.addEntity(Item.getItem('Blue Key'))
    
    townPlaza = Room.getRoom('Town Plaza')
    townPlaza.addEntity(Agent.getAgent('Dark Henry'))    
    
    pond = Room.getRoom('Pond')
    tree = Item.getItem('Tree')
    pond.addEntity(tree)
    tree.addEntity(Item.getItem('Acorn'))
    pond.addEntity(Item.getItem('Pond'))
    
    darkRoom = Room.getRoom('Dark Room')
    darkRoom.addEntity(Item.getItem('Crate'))
コード例 #31
0
def done_item():
    return Item('done-id', 'done-title', Status.DONE.value, 'done-description', "2021-01-01T15:47:23.517Z")
コード例 #32
0
def doing_item():
    return Item('doing-id', 'doing-title', Status.DOING.value,'doing-description', "2021-01-01T15:47:23.517Z")
コード例 #33
0
def to_do_item():
    return Item('to-do-id', 'to-do-title', Status.TO_DO.value, 'to-do-description', "2021-01-01T15:47:23.517Z")
コード例 #34
0
ファイル: main.py プロジェクト: krieghan/spelunker
 def getEntityNames(self):
     return Agent.getNames() + Room.getNames() + Item.getNames()