Exemplo n.º 1
0
    def testIsValidPrice(self):
        sellable = Sellable(category=self._category,
                            cost=50,
                            description=u"Test",
                            price=currency(100),
                            store=self.store)
        sellable.max_discount = 0
        cat = self.create_client_category(u'Cat 1')
        cat_price = ClientCategoryPrice(sellable=sellable,
                                        category=cat,
                                        price=150,
                                        max_discount=0,
                                        store=self.store)

        # without a category, and max_discount = 0
        self.assertFalse(sellable.is_valid_price(0))
        self.assertFalse(sellable.is_valid_price(-10))
        self.assertFalse(sellable.is_valid_price(99))
        self.assertTrue(sellable.is_valid_price(101))
        self.assertTrue(sellable.is_valid_price(100))

        # without a category, and max_discount = 10%
        sellable.max_discount = 10
        self.assertFalse(sellable.is_valid_price(0))
        self.assertFalse(sellable.is_valid_price(-1))
        self.assertFalse(sellable.is_valid_price(89))
        self.assertTrue(sellable.is_valid_price(90))
        self.assertTrue(sellable.is_valid_price(95))
        self.assertTrue(sellable.is_valid_price(99))
        self.assertTrue(sellable.is_valid_price(101))

        # Now with a category, max_discount = 0
        self.assertFalse(sellable.is_valid_price(0, cat))
        self.assertFalse(sellable.is_valid_price(-10, cat))
        self.assertFalse(sellable.is_valid_price(Decimal('149.99'), cat))
        self.assertTrue(sellable.is_valid_price(150, cat))
        self.assertTrue(sellable.is_valid_price(151, cat))

        # Now with a category, max_discount = 10%
        cat_price.max_discount = 10
        self.assertTrue(sellable.is_valid_price(Decimal('149.99'), cat))
        self.assertTrue(sellable.is_valid_price(135, cat))
        self.assertFalse(sellable.is_valid_price(134, cat))
Exemplo n.º 2
0
 def test_category_name(self):
     sellable = Sellable(category=None,
                         cost=50,
                         description=u"Test",
                         price=currency(100),
                         store=self.store)
     sellable.max_discount = 0
     cat = self.create_client_category(u'Cat 1')
     cat_price = ClientCategoryPrice(sellable=sellable, category=cat,
                                     price=150, max_discount=0,
                                     store=self.store)
     self.assertEqual(cat_price.category_name, u'Cat 1')
Exemplo n.º 3
0
 def test_category_name(self):
     sellable = Sellable(category=None,
                         cost=50,
                         description=u"Test",
                         price=currency(100),
                         store=self.store)
     sellable.max_discount = 0
     cat = self.create_client_category(u'Cat 1')
     cat_price = ClientCategoryPrice(sellable=sellable, category=cat,
                                     price=150, max_discount=0,
                                     store=self.store)
     self.assertEquals(cat_price.category_name, u'Cat 1')
Exemplo n.º 4
0
    def testIsValidPrice(self):
        sellable = Sellable(category=self._category, cost=50,
                            description=u"Test",
                            price=currency(100),
                            store=self.store)
        sellable.max_discount = 0
        cat = self.create_client_category(u'Cat 1')
        cat_price = ClientCategoryPrice(sellable=sellable, category=cat,
                                        price=150, max_discount=0,
                                        store=self.store)

        # without a category, and max_discount = 0
        self.assertFalse(sellable.is_valid_price(0))
        self.assertFalse(sellable.is_valid_price(-10))
        self.assertFalse(sellable.is_valid_price(99))
        self.assertTrue(sellable.is_valid_price(101))
        self.assertTrue(sellable.is_valid_price(100))

        # without a category, and max_discount = 10%
        sellable.max_discount = 10
        self.assertFalse(sellable.is_valid_price(0))
        self.assertFalse(sellable.is_valid_price(-1))
        self.assertFalse(sellable.is_valid_price(89))
        self.assertTrue(sellable.is_valid_price(90))
        self.assertTrue(sellable.is_valid_price(95))
        self.assertTrue(sellable.is_valid_price(99))
        self.assertTrue(sellable.is_valid_price(101))

        # Now with a category, max_discount = 0
        self.assertFalse(sellable.is_valid_price(0, cat))
        self.assertFalse(sellable.is_valid_price(-10, cat))
        self.assertFalse(sellable.is_valid_price(Decimal('149.99'), cat))
        self.assertTrue(sellable.is_valid_price(150, cat))
        self.assertTrue(sellable.is_valid_price(151, cat))

        # Now with a category, max_discount = 10%
        cat_price.max_discount = 10
        self.assertTrue(sellable.is_valid_price(Decimal('149.99'), cat))
        self.assertTrue(sellable.is_valid_price(135, cat))
        self.assertFalse(sellable.is_valid_price(134, cat))
Exemplo n.º 5
0
 def test_price_based_on_category_markup(self):
     # When the price isn't defined, but the category and the cost. In this
     # case the sellable must have the price calculated applying the category's
     # markup in the sellable's cost.
     self._category.suggested_markup = 0
     sellable = Sellable(description=u"MX123",
                         commission=0,
                         cost=100,
                         category=self._category,
                         store=self.store)
     sellable.max_discount = 0
     self.assertTrue(sellable.markup == self._category.get_markup(),
                     (u"Expected markup: %r, got %r" %
                      (self._category.get_markup(), sellable.markup)))
     price = sellable.cost * (sellable.markup / currency(100) + 1)
     self.assertTrue(sellable.price == price,
                     (u"Expected price: %r, got %r" %
                      (price, sellable.price)))
Exemplo n.º 6
0
 def test_price_based_on_category_markup(self):
     # When the price isn't defined, but the category and the cost. In this
     # case the sellable must have the price calculated applying the category's
     # markup in the sellable's cost.
     self._category.suggested_markup = 0
     sellable = Sellable(description=u"MX123",
                         commission=0,
                         cost=100,
                         category=self._category,
                         store=self.store)
     sellable.max_discount = 0
     self.failUnless(sellable.markup == self._category.get_markup(),
                     (u"Expected markup: %r, got %r"
                      % (self._category.get_markup(),
                         sellable.markup)))
     price = sellable.cost * (sellable.markup / currency(100) + 1)
     self.failUnless(sellable.price == price,
                     (u"Expected price: %r, got %r"
                      % (price, sellable.price)))
Exemplo n.º 7
0
    def test_is_valid_price(self):

        def isValidPriceAssert(valid_data, expected_validity, min_price,
                               max_discount):
            self.assertEquals(valid_data['is_valid'], expected_validity)
            self.assertEquals(valid_data['min_price'], min_price)
            self.assertEquals(valid_data['max_discount'], max_discount)

        sellable = Sellable(category=self._category, cost=50,
                            description=u"Test",
                            price=currency(100),
                            store=self.store)
        sellable.max_discount = 0
        cat = self.create_client_category(u'Cat 1')
        cat_price = ClientCategoryPrice(sellable=sellable, category=cat,
                                        price=150, max_discount=0,
                                        store=self.store)
        user = self.create_user()
        user.profile.max_discount = 50

        # without a category, and max_discount = 0, user = None
        valid_data = sellable.is_valid_price(-10)
        isValidPriceAssert(valid_data, False, sellable.price, 0)

        valid_data = sellable.is_valid_price(0)
        isValidPriceAssert(valid_data, False, sellable.price, 0)

        valid_data = sellable.is_valid_price(99)
        isValidPriceAssert(valid_data, False, sellable.price, 0)

        valid_data = sellable.is_valid_price(100)
        isValidPriceAssert(valid_data, True, sellable.price, 0)

        valid_data = sellable.is_valid_price(101)
        isValidPriceAssert(valid_data, True, sellable.price, 0)

        # without a category, and max_discount = 10%
        sellable.max_discount = 10

        valid_data = sellable.is_valid_price(-1)
        isValidPriceAssert(valid_data, False, currency(90), 10)

        valid_data = sellable.is_valid_price(0)
        isValidPriceAssert(valid_data, False, currency(90), 10)

        valid_data = sellable.is_valid_price(89)
        isValidPriceAssert(valid_data, False, currency(90), 10)

        valid_data = sellable.is_valid_price(90)
        isValidPriceAssert(valid_data, True, currency(90), 10)

        valid_data = sellable.is_valid_price(91)
        isValidPriceAssert(valid_data, True, currency(90), 10)

        # Now with a category, max_discount = 0
        valid_data = sellable.is_valid_price(0, cat)
        isValidPriceAssert(valid_data, False, currency(150), 0)

        valid_data = sellable.is_valid_price(-10, cat)
        isValidPriceAssert(valid_data, False, currency(150), 0)

        valid_data = sellable.is_valid_price(Decimal('149.99'), cat)
        isValidPriceAssert(valid_data, False, currency(150), 0)

        valid_data = sellable.is_valid_price(150, cat)
        isValidPriceAssert(valid_data, True, currency(150), 0)

        valid_data = sellable.is_valid_price(151, cat)
        isValidPriceAssert(valid_data, True, currency(150), 0)

        # Now with a category, max_discount = 10%
        cat_price.max_discount = 10

        valid_data = sellable.is_valid_price(Decimal('149.99'), cat)
        isValidPriceAssert(valid_data, True, currency(135), 10)

        valid_data = sellable.is_valid_price(135, cat)
        isValidPriceAssert(valid_data, True, currency(135), 10)

        valid_data = sellable.is_valid_price(134, cat)
        isValidPriceAssert(valid_data, False, currency(135), 10)

        # with a user
        valid_data = sellable.is_valid_price(49, None, user)
        isValidPriceAssert(valid_data, False, currency(50), 50)

        valid_data = sellable.is_valid_price(50, None, user)
        isValidPriceAssert(valid_data, True, currency(50), 50)
Exemplo n.º 8
0
    def test_is_valid_price(self):

        def isValidPriceAssert(valid_data, expected_validity, min_price,
                               max_discount):
            self.assertEquals(valid_data['is_valid'], expected_validity)
            self.assertEquals(valid_data['min_price'], min_price)
            self.assertEquals(valid_data['max_discount'], max_discount)

        sellable = Sellable(category=self._category, cost=50,
                            description=u"Test",
                            price=currency(100),
                            store=self.store)
        sellable.max_discount = 0
        cat = self.create_client_category(u'Cat 1')
        cat_price = ClientCategoryPrice(sellable=sellable, category=cat,
                                        price=150, max_discount=0,
                                        store=self.store)
        user = self.create_user()
        user.profile.max_discount = 50

        # without a category, and max_discount = 0, user = None
        valid_data = sellable.is_valid_price(-10)
        isValidPriceAssert(valid_data, False, sellable.price, 0)

        valid_data = sellable.is_valid_price(0)
        isValidPriceAssert(valid_data, False, sellable.price, 0)

        valid_data = sellable.is_valid_price(99)
        isValidPriceAssert(valid_data, False, sellable.price, 0)

        valid_data = sellable.is_valid_price(100)
        isValidPriceAssert(valid_data, True, sellable.price, 0)

        valid_data = sellable.is_valid_price(101)
        isValidPriceAssert(valid_data, True, sellable.price, 0)

        # without a category, and max_discount = 10%
        sellable.max_discount = 10

        valid_data = sellable.is_valid_price(-1)
        isValidPriceAssert(valid_data, False, currency(90), 10)

        valid_data = sellable.is_valid_price(0)
        isValidPriceAssert(valid_data, False, currency(90), 10)

        valid_data = sellable.is_valid_price(89)
        isValidPriceAssert(valid_data, False, currency(90), 10)

        valid_data = sellable.is_valid_price(90)
        isValidPriceAssert(valid_data, True, currency(90), 10)

        valid_data = sellable.is_valid_price(91)
        isValidPriceAssert(valid_data, True, currency(90), 10)

        # Now with a category, max_discount = 0
        valid_data = sellable.is_valid_price(0, cat)
        isValidPriceAssert(valid_data, False, currency(150), 0)

        valid_data = sellable.is_valid_price(-10, cat)
        isValidPriceAssert(valid_data, False, currency(150), 0)

        valid_data = sellable.is_valid_price(Decimal('149.99'), cat)
        isValidPriceAssert(valid_data, False, currency(150), 0)

        valid_data = sellable.is_valid_price(150, cat)
        isValidPriceAssert(valid_data, True, currency(150), 0)

        valid_data = sellable.is_valid_price(151, cat)
        isValidPriceAssert(valid_data, True, currency(150), 0)

        # Now with a category, max_discount = 10%
        cat_price.max_discount = 10

        valid_data = sellable.is_valid_price(Decimal('149.99'), cat)
        isValidPriceAssert(valid_data, True, currency(135), 10)

        valid_data = sellable.is_valid_price(135, cat)
        isValidPriceAssert(valid_data, True, currency(135), 10)

        valid_data = sellable.is_valid_price(134, cat)
        isValidPriceAssert(valid_data, False, currency(135), 10)

        # with a user
        valid_data = sellable.is_valid_price(49, None, user)
        isValidPriceAssert(valid_data, False, currency(50), 50)

        valid_data = sellable.is_valid_price(50, None, user)
        isValidPriceAssert(valid_data, True, currency(50), 50)