Fix first test case / billing

This commit is contained in:
Nico Schottelius 2020-10-06 23:14:32 +02:00
commit 2e74661702
3 changed files with 111 additions and 79 deletions

View file

@ -13,8 +13,8 @@ chocolate_product_config = {
'gramm':
{ 'min': 100,
'max': 5000,
'one_time_price': 0.2,
'recurring_price': 0
'one_time_price_per_unit': 0.2,
'recurring_price_per_unit': 0
},
},
}
@ -25,21 +25,21 @@ chocolate_order_config = {
}
}
chocolate_one_time_price = chocolate_order_config['features']['gramm'] * chocolate_product_config['features']['gramm']['one_time_price']
chocolate_one_time_price = chocolate_order_config['features']['gramm'] * chocolate_product_config['features']['gramm']['one_time_price_per_unit']
vm_product_config = {
'features': {
'cores':
{ 'min': 1,
'max': 48,
'one_time_price': 0,
'recurring_price': 4
'one_time_price_per_unit': 0,
'recurring_price_per_unit': 4
},
'ram_gb':
{ 'min': 1,
'max': 256,
'one_time_price': 0,
'recurring_price': 4
'one_time_price_per_unit': 0,
'recurring_price_per_unit': 4
},
},
}
@ -94,8 +94,10 @@ class ProductTestCase(TestCase):
p = Product.objects.create(name="Testproduct",
description="Only for testing",
config=vm_product_config,
default_recurring_period=self.default_recurring_period)
config=vm_product_config)
p.recurring_periods.add(self.default_recurring_period,
through_defaults= { 'is_default': True })
class OrderTestCase(TestCase):
@ -116,24 +118,36 @@ class OrderTestCase(TestCase):
postal_code="somewhere else",
active=True)
self.product = Product.objects.create(name="Testproduct",
description="Only for testing",
config=vm_product_config)
RecurringPeriod.populate_db_defaults()
self.default_recurring_period = RecurringPeriod.objects.get(name="Per 30 days")
self.product.recurring_periods.add(self.default_recurring_period,
through_defaults= { 'is_default': True })
def test_order_invalid_recurring_period(self):
"""
Order a products with a recurringperiod that is not added to the product
"""
o = Order.objects.create(owner=self.user,
billing_address=self.ba,
product=self.product,
config=vm_order_config)
def test_order_product(self):
"""
Order a product, ensure the order has correct price setup
"""
p = Product.objects.create(name="Testproduct",
description="Only for testing",
config=vm_product_config,
default_recurring_period=self.default_recurring_period)
o = Order.objects.create(owner=self.user,
billing_address=self.ba,
product=p,
config=vm_order_config)
product=self.product)
self.assertEqual(o.one_time_price, 0)
self.assertEqual(o.recurring_price, 16)
@ -144,19 +158,12 @@ class OrderTestCase(TestCase):
- a new order is created
- the price is correct in the new order
"""
p = Product.objects.create(name="Testproduct",
description="Only for testing",
config=vm_product_config,
default_recurring_period=self.default_recurring_period)
order1 = Order.objects.create(owner=self.user,
billing_address=self.ba,
product=p,
product=self.product,
config=vm_order_config)
self.assertEqual(order1.one_time_price, 0)
self.assertEqual(order1.recurring_price, 16)
@ -182,13 +189,15 @@ class ModifyOrderTestCase(TestCase):
postal_code="somewhere else",
active=True)
self.product = Product.objects.create(name="Testproduct",
description="Only for testing",
config=vm_product_config)
RecurringPeriod.populate_db_defaults()
self.default_recurring_period = RecurringPeriod.objects.get(name="Per 30 days")
self.product = Product.objects.create(name="Testproduct",
description="Only for testing",
config=vm_product_config,
default_recurring_period=self.default_recurring_period)
self.product.recurring_periods.add(self.default_recurring_period,
through_defaults= { 'is_default': True })
def test_change_order(self):
@ -468,6 +477,18 @@ class BillTestCase(TestCase):
config=vm_product_config)
RecurringPeriod.populate_db_defaults()
self.default_recurring_period = RecurringPeriod.objects.get(name="Per 30 days")
self.onetime_recurring_period = RecurringPeriod.objects.get(name="Onetime")
self.chocolate.recurring_periods.add(self.onetime_recurring_period,
through_defaults= { 'is_default': True })
self.vm.recurring_periods.add(self.default_recurring_period,
through_defaults= { 'is_default': True })
# used for generating multiple bills
self.bill_dates = [
timezone.make_aware(datetime.datetime(2020,3,31)),