def testReturnsFirstValueAddedIfThereAreMultipleMatches(self):
     pricelist = behaviors.PriceList()
     np1 = behaviors.NamedPrice(Decimal('2.99'), u"price one")
     np2 = behaviors.NamedPrice(Decimal('3.99'), u"price one")
     pricelist.append(np1)
     pricelist.append(np2)
     found = pricelist.by_name(u"price one")
     self.assertEqual(np1, found)
 def testPriceListAcceptsNewNamedPriceObjects(self):
     context = StubContext()
     priced = behaviors.IPriced(context)
     priced.pricelist = behaviors.PriceList()
     a_price = Decimal('2.99')
     priced.pricelist.append(behaviors.NamedPrice(a_price))
     self.assertEqual(a_price,
                      behaviors.IPriced(context).pricelist[0].price)
 def testInvariants(self):
     validation = behaviors.IPriced.validateInvariants
     context = StubContext()
     priced = behaviors.IPriced(context)
     priced.enabled = True
     self.assertRaises(zif.Invalid, validation, priced)
     # an empty PriceList should also fail
     priced.pricelist = behaviors.PriceList()
     self.assertRaises(zif.Invalid, validation, priced)
     # set a price and we're OK
     a_price = Decimal('2.99')
     priced.pricelist.append(behaviors.NamedPrice(a_price))
     self.assertEqual(None, validation(priced))
 def testWillFindANamelessPrice(self):
     pricelist = behaviors.PriceList()
     np = behaviors.NamedPrice(Decimal('2.99'))
     pricelist.append(np)
     found = pricelist.by_name(u"")
     self.assertEqual(np, found)
 def testReturnsNotFoundValWhenItMisses(self):
     pricelist = behaviors.PriceList()
     np = behaviors.NamedPrice(Decimal('2.99'), u"price one")
     pricelist.append(np)
     self.assertEqual(self.NAMED_PRICE_NOT_FOUND,
                      pricelist.by_name(u"other one"))
 def testReturnsNotFoundValIfEmpty(self):
     pricelist = behaviors.PriceList()
     self.assertEqual(self.NAMED_PRICE_NOT_FOUND, pricelist.by_name(u"foo"))
 def testCanFindASinglePriceByName(self):
     pricelist = behaviors.PriceList()
     np = behaviors.NamedPrice(Decimal('2.99'), u"price one")
     pricelist.append(np)
     found = pricelist.by_name(u"price one")
     self.assertEqual(np, found)