begin testing bill sums

Signed-off-by: Nico Schottelius <nico@nico-notebook.schottelius.org>
This commit is contained in:
Nico Schottelius 2020-08-25 21:53:25 +02:00
parent ab412cb877
commit b8b15704a3

View file

@ -352,7 +352,6 @@ class BillTestCase(TestCase):
class ModifyProductTestCase(TestCase):
def setUp(self):
self.user = get_user_model().objects.create(
username='random_user',
@ -366,12 +365,35 @@ class ModifyProductTestCase(TestCase):
postal_code="somewhere else",
active=True)
def test_modify_recurring_product(self):
def test_no_pro_rata_first_bill(self):
"""
The bill should NOT contain a partial amount
"""
"""
price = 5
# Standard 30d recurring product
product = SampleRecurringProduct.objects.create(owner=self.user,
rc_price=price)
starting_date = timezone.make_aware(datetime.datetime(2020,3,3))
ending_date = timezone.make_aware(datetime.datetime(2020,3,31))
time_diff = (ending_date - starting_date).total_seconds()
product.create_order_at(starting_date)
bills = Bill.create_next_bills_for_user(self.user,
ending_date=ending_date)
# We expect 1 bill for 1 billing address and 1 time frame
self.assertEqual(len(bills), 1)
pro_rata_amount = time_diff / product.default_recurring_period.value
self.assertNotEqual(bills[0].sum, pro_rata_amount * price)
self.assertEqual(bills[0].sum, price)
product = SampleRecurringProduct.objects.create(owner=self.user)
@ -500,111 +522,3 @@ class ModifyProductTestCase(TestCase):
# self.assertEqual(len(second_month_bills), 1)
# self.assertEqual(float(second_month_bills[0].amount),
# round(12 * recurring_price, AMOUNT_DECIMALS))
# class ProductActivationTestCase(TestCase):
# def setUp(self):
# self.user = get_user_model().objects.create(
# username='jdoe',
# email='john.doe@domain.tld')
# self.billing_address = BillingAddress.objects.create(
# owner=self.user,
# street="unknown",
# city="unknown",
# postal_code="unknown")
# def test_product_activation(self):
# starting_date = datetime.fromisoformat('2020-03-01')
# one_time_price = 0
# recurring_price = 1
# description = "Test Product"
# order = Order.objects.create(
# owner=self.user,
# starting_date=starting_date,
# recurring_period=RecurringPeriod.PER_30D,
# recurring_price=recurring_price,
# one_time_price=one_time_price,
# description=description,
# billing_address=self.billing_address)
# product = GenericServiceProduct(
# custom_description=description,
# custom_one_time_price=one_time_price,
# custom_recurring_price=recurring_price,
# owner=self.user,
# order=order)
# product.save()
# # Validate initial state: must be awaiting payment.
# self.assertEqual(product.status, UncloudStatus.AWAITING_PAYMENT)
# # Pay initial bill, check that product is activated.
# order.generate_initial_bill()
# amount = product.order.bills[0].amount
# payment = Payment(owner=self.user, amount=amount)
# payment.save()
# self.assertEqual(
# GenericServiceProduct.objects.get(uuid=product.uuid).status,
# UncloudStatus.PENDING
# )
# class BillingAddressTestCase(TestCase):
# def setUp(self):
# self.user = get_user_model().objects.create(
# username='jdoe',
# email='john.doe@domain.tld')
# self.billing_address_01 = BillingAddress.objects.create(
# owner=self.user,
# street="unknown1",
# city="unknown1",
# postal_code="unknown1",
# country="CH")
# self.billing_address_02 = BillingAddress.objects.create(
# owner=self.user,
# street="unknown2",
# city="unknown2",
# postal_code="unknown2",
# country="CH")
# def test_billing_with_single_address(self):
# # Create new orders somewhere in the past so that we do not encounter
# # auto-created initial bills.
# starting_date = datetime.fromisoformat('2020-03-01')
# order_01 = Order.objects.create(
# owner=self.user,
# starting_date=starting_date,
# recurring_period=RecurringPeriod.PER_30D,
# billing_address=self.billing_address_01)
# order_02 = Order.objects.create(
# owner=self.user,
# starting_date=starting_date,
# recurring_period=RecurringPeriod.PER_30D,
# billing_address=self.billing_address_01)
# # We need a single bill since we work with a single address.
# bills = Bill.generate_for(2020, 4, self.user)
# self.assertEqual(len(bills), 1)
# def test_billing_with_multiple_addresses(self):
# # Create new orders somewhere in the past so that we do not encounter
# # auto-created initial bills.
# starting_date = datetime.fromisoformat('2020-03-01')
# order_01 = Order.objects.create(
# owner=self.user,
# starting_date=starting_date,
# recurring_period=RecurringPeriod.PER_30D,
# billing_address=self.billing_address_01)
# order_02 = Order.objects.create(
# owner=self.user,
# starting_date=starting_date,
# recurring_period=RecurringPeriod.PER_30D,
# billing_address=self.billing_address_02)
# # We need different bills since we work with different addresses.
# bills = Bill.generate_for(2020, 4, self.user)
# self.assertEqual(len(bills), 2)