Ejemplo n.º 1
0
    def test_prices_and_markups(self):
        self._category.markup = 0
        sellable = Sellable(category=self._category, cost=50,
                            description=u"Test", price=currency(100),
                            store=self.store)
        self.failUnless(sellable.price == 100,
                        u"Expected price: %r, got %r" % (100, sellable.price))
        self.failUnless(sellable.markup == 100,
                        u"Expected markup: %r, got %r" % (100, sellable.markup))
        sellable.markup = 10
        self.failUnless(sellable.price == 55,
                        u"Expected price: %r, got %r" % (55, sellable.price))
        sellable.price = 50
        self.failUnless(sellable.markup == 0,
                        u"Expected markup %r, got %r" % (0, sellable.markup))

        # When the price specified isn't equivalent to the markup specified.
        # In this case the price don't must be updated based on the markup.
        sellable = Sellable(cost=50,
                            description=u"Test", price=currency(100),
                            store=self.store)
        self.failUnless(sellable.price == 100)

        # A simple test: product without cost and price, markup must be 0
        sellable.cost = currency(0)
        sellable.price = currency(0)
        self.failUnless(sellable.markup == 0,
                        u"Expected markup %r, got %r" % (0, sellable.markup))
Ejemplo n.º 2
0
    def test_prices_and_markups(self):
        self._category.markup = 0
        sellable = Sellable(category=self._category, cost=50,
                            description=u"Test", price=currency(100),
                            store=self.store)
        self.failUnless(sellable.price == 100,
                        u"Expected price: %r, got %r" % (100, sellable.price))
        self.failUnless(sellable.markup == 100,
                        u"Expected markup: %r, got %r" % (100, sellable.markup))
        sellable.markup = 10
        self.failUnless(sellable.price == 55,
                        u"Expected price: %r, got %r" % (55, sellable.price))
        sellable.price = 50
        self.failUnless(sellable.markup == 0,
                        u"Expected markup %r, got %r" % (0, sellable.markup))

        # When the price specified isn't equivalent to the markup specified.
        # In this case the price don't must be updated based on the markup.
        sellable = Sellable(cost=50,
                            description=u"Test", price=currency(100),
                            store=self.store)
        self.failUnless(sellable.price == 100)

        # A simple test: product without cost and price, markup must be 0
        sellable.cost = currency(0)
        sellable.price = currency(0)
        self.failUnless(sellable.markup == 0,
                        u"Expected markup %r, got %r" % (0, sellable.markup))
Ejemplo n.º 3
0
    def test_price_on_sale_price_setter(self):
        sellable = Sellable(category=self._category,
                            cost=50,
                            description=u"Test",
                            price=100,
                            store=self.store)
        sellable.on_sale_price = 80

        # - Old promotion
        sellable.on_sale_start_date = localdate(2001, 1, 1)
        sellable.on_sale_end_date = localdate(2002, 1, 1)
        sellable.price = 10
        self.assertEquals(sellable.base_price, 10)
        self.assertEquals(sellable.on_sale_price, 80)

        # - Future promotion
        sellable.on_sale_start_date = localdate(3001, 1, 1)
        sellable.on_sale_end_date = localdate(3002, 1, 1)
        sellable.price = 10
        self.assertEquals(sellable.base_price, 10)
        self.assertEquals(sellable.on_sale_price, 80)

        # Current promotion
        sellable.price = 100
        sellable.on_sale_start_date = localdate(2001, 1, 1)
        sellable.on_sale_end_date = localdate(3002, 1, 1)
        sellable.price = 10
        self.assertEquals(sellable.base_price, 100)
        self.assertEquals(sellable.on_sale_price, 10)

        sellable.price = -80
        self.assertEquals(sellable.base_price, 100)
        self.assertEquals(sellable.on_sale_price, 0)
Ejemplo n.º 4
0
    def test_price_on_sale_price_setter(self):
        sellable = Sellable(category=self._category,
                            cost=50,
                            description=u"Test",
                            price=100,
                            store=self.store)
        sellable.on_sale_price = 80

        # - Old promotion
        sellable.on_sale_start_date = localdate(2001, 1, 1)
        sellable.on_sale_end_date = localdate(2002, 1, 1)
        sellable.price = 10
        self.assertEquals(sellable.base_price, 10)
        self.assertEquals(sellable.on_sale_price, 80)

        # - Future promotion
        sellable.on_sale_start_date = localdate(3001, 1, 1)
        sellable.on_sale_end_date = localdate(3002, 1, 1)
        sellable.price = 10
        self.assertEquals(sellable.base_price, 10)
        self.assertEquals(sellable.on_sale_price, 80)

        # Current promotion
        sellable.price = 100
        sellable.on_sale_start_date = localdate(2001, 1, 1)
        sellable.on_sale_end_date = localdate(3002, 1, 1)
        sellable.price = 10
        self.assertEquals(sellable.base_price, 100)
        self.assertEquals(sellable.on_sale_price, 10)

        sellable.price = -80
        self.assertEquals(sellable.base_price, 100)
        self.assertEquals(sellable.on_sale_price, 0)
Ejemplo n.º 5
0
    def test_price_on_sale_price_setter(self):
        sellable = Sellable(category=self._category,
                            cost=50,
                            description=u"Test",
                            price=100,
                            store=self.store)
        sellable.on_sale_price = 100

        # - Sale period is undefined.
        sellable.on_sale_start_date = None
        sellable.on_sale_end_date = None
        sellable.price = 10
        self.assertEqual(sellable.base_price, 10)
        self.assertEqual(sellable.on_sale_price, 100)

        # - Sale is in the past.
        sellable.on_sale_start_date = localdate(2001, 1, 1)
        sellable.on_sale_end_date = localdate(2002, 1, 1)
        sellable.price = 20
        self.assertEqual(sellable.base_price, 20)
        self.assertEqual(sellable.on_sale_price, 100)

        # - Sale is in the future.
        sellable.on_sale_start_date = localdate(3001, 1, 1)
        sellable.on_sale_end_date = localdate(3002, 1, 1)
        sellable.price = 30
        self.assertEqual(sellable.base_price, 30)
        self.assertEqual(sellable.on_sale_price, 100)

        sellable.price = 100
        # - Sale has no start_date but has end_date in the future.
        sellable.on_sale_start_date = None
        sellable.on_sale_end_date = localdate(3002, 1, 1)
        sellable.price = 40
        self.assertEqual(sellable.base_price, 100)
        self.assertEqual(sellable.on_sale_price, 40)

        # - Sale has no end_date but has start_date in the past.
        sellable.on_sale_start_date = localdate(2001, 1, 1)
        sellable.on_sale_end_date = None
        sellable.price = 50
        self.assertEqual(sellable.base_price, 100)
        self.assertEqual(sellable.on_sale_price, 50)

        # - Sale is on.
        sellable.on_sale_start_date = localdate(2001, 1, 1)
        sellable.on_sale_end_date = localdate(3002, 1, 1)
        sellable.price = 60
        self.assertEqual(sellable.base_price, 100)
        self.assertEqual(sellable.on_sale_price, 60)

        sellable.price = -80
        self.assertEqual(sellable.base_price, 100)
        self.assertEqual(sellable.on_sale_price, 0)
Ejemplo n.º 6
0
    def test_price_on_sale_price_setter(self):
        sellable = Sellable(category=self._category,
                            cost=50,
                            description=u"Test",
                            price=100,
                            store=self.store)
        sellable.on_sale_price = 100

        # - Sale period is undefined.
        sellable.on_sale_start_date = None
        sellable.on_sale_end_date = None
        sellable.price = 10
        self.assertEqual(sellable.base_price, 10)
        self.assertEqual(sellable.on_sale_price, 100)

        # - Sale is in the past.
        sellable.on_sale_start_date = localdate(2001, 1, 1)
        sellable.on_sale_end_date = localdate(2002, 1, 1)
        sellable.price = 20
        self.assertEqual(sellable.base_price, 20)
        self.assertEqual(sellable.on_sale_price, 100)

        # - Sale is in the future.
        sellable.on_sale_start_date = localdate(3001, 1, 1)
        sellable.on_sale_end_date = localdate(3002, 1, 1)
        sellable.price = 30
        self.assertEqual(sellable.base_price, 30)
        self.assertEqual(sellable.on_sale_price, 100)

        sellable.price = 100
        # - Sale has no start_date but has end_date in the future.
        sellable.on_sale_start_date = None
        sellable.on_sale_end_date = localdate(3002, 1, 1)
        sellable.price = 40
        self.assertEqual(sellable.base_price, 100)
        self.assertEqual(sellable.on_sale_price, 40)

        # - Sale has no end_date but has start_date in the past.
        sellable.on_sale_start_date = localdate(2001, 1, 1)
        sellable.on_sale_end_date = None
        sellable.price = 50
        self.assertEqual(sellable.base_price, 100)
        self.assertEqual(sellable.on_sale_price, 50)

        # - Sale is on.
        sellable.on_sale_start_date = localdate(2001, 1, 1)
        sellable.on_sale_end_date = localdate(3002, 1, 1)
        sellable.price = 60
        self.assertEqual(sellable.base_price, 100)
        self.assertEqual(sellable.on_sale_price, 60)

        sellable.price = -80
        self.assertEqual(sellable.base_price, 100)
        self.assertEqual(sellable.on_sale_price, 0)