Skip to content

Commit

Permalink
New unit tests for discountable product
Browse files Browse the repository at this point in the history
  • Loading branch information
joamag committed Feb 5, 2019
1 parent e783134 commit 24ca765
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/budy/test/bag.py
Expand Up @@ -405,3 +405,34 @@ def test_product_discounted(self):
self.assertEqual(bag.total, 20.0)
self.assertEqual(bag.discountable, 0.0)
self.assertEqual(len(bag.lines), 1)

def test_product_non_discountable(self):
product = budy.Product(
short_description = "product",
gender = "Male",
price = 10.0,
quantity_hand = 2.0,
discountable = False
)
product.save()

bag = budy.Bag()
bag.save()

bag_line = budy.BagLine(
quantity = 2.0
)
bag_line.product = product
bag_line.save()
bag.add_line_s(bag_line)

self.assertEqual(bag_line.quantity, 2.0)
self.assertEqual(bag_line.total, 20.0)
self.assertEqual(bag_line.discounted, False)
self.assertEqual(bag.sub_total, 20.0)
self.assertEqual(bag.discounted_sub_total, 0.0)
self.assertEqual(bag.undiscounted_sub_total, 20.0)
self.assertEqual(bag.discountable_sub_total, 0.0)
self.assertEqual(bag.total, 20.0)
self.assertEqual(bag.discountable, 0.0)
self.assertEqual(len(bag.lines), 1)
36 changes: 36 additions & 0 deletions src/budy/test/order.py
Expand Up @@ -663,6 +663,42 @@ def test_discountable_full(self):
self.assertEqual(order.shipping_cost, 10.0)
self.assertEqual(order.discountable, 0.0)

def test_non_discountable(self):
product = budy.Product(
short_description = "product",
gender = "Male",
price = 10.0,
discountable = False
)
product.save()

order = budy.Order(
shipping_fixed = 10.0
)
order.save()

order_line = budy.OrderLine(quantity = 2.0)
order_line.product = product
order_line.save()
order.add_line_s(order_line)

self.assertEqual(order.sub_total, 20.0)
self.assertEqual(order.discount, 0.0)
self.assertEqual(order.total, 30.0)
self.assertEqual(order.payable, 30.0)
self.assertEqual(order.shipping_cost, 10.0)
self.assertEqual(order.discountable, 0.0)

order.discount_fixed = 20.0
order.save()

self.assertEqual(order.sub_total, 20.0)
self.assertEqual(order.discount, 0.0)
self.assertEqual(order.total, 30.0)
self.assertEqual(order.payable, 30.0)
self.assertEqual(order.shipping_cost, 10.0)
self.assertEqual(order.discountable, 0.0)

def test_taxes(self):
product = budy.Product(
short_description = "product",
Expand Down

0 comments on commit 24ca765

Please sign in to comment.