remove big mistake: orders from product
Signed-off-by: Nico Schottelius <nico@nico-notebook.schottelius.org>
This commit is contained in:
parent
d8a7964fed
commit
1aead50170
8 changed files with 287 additions and 35 deletions
|
|
@ -1,6 +1,7 @@
|
|||
from django.test import TestCase
|
||||
from django.contrib.auth import get_user_model
|
||||
from datetime import datetime, date, timedelta
|
||||
from django.utils import timezone
|
||||
|
||||
from .models import *
|
||||
from uncloud_service.models import GenericServiceProduct
|
||||
|
|
@ -93,7 +94,9 @@ class ProductTestCase(TestCase):
|
|||
p = SampleRecurringProduct.objects.create(owner=self.user)
|
||||
p.create_order(timezone.make_aware(datetime.datetime(2020,3,3)))
|
||||
|
||||
p.create_or_update_recurring_order(timezone.make_aware(datetime.datetime(2020,3,3)))
|
||||
p.create_or_update_recurring_order(timezone.make_aware(datetime.datetime(2020,3,4)))
|
||||
|
||||
# FIXME: where is the assert?
|
||||
|
||||
|
||||
class BillingAddressTestCase(TestCase):
|
||||
|
|
@ -413,38 +416,96 @@ class ModifyProductTestCase(TestCase):
|
|||
self.assertNotEqual(bills[0].sum, pro_rata_amount * price)
|
||||
self.assertEqual(bills[0].sum, price)
|
||||
|
||||
def test_bill_for_increasing_product_easy(self):
|
||||
|
||||
def test_downgrade_product(self):
|
||||
"""
|
||||
Modify product, check general logi
|
||||
Test downgrading behaviour:
|
||||
|
||||
We create a recurring product (recurring time: 30 days) and downgrade after 15 days.
|
||||
|
||||
We create the bill right AFTER the end of the first order.
|
||||
|
||||
Expected result:
|
||||
|
||||
- First bill record for 30 days
|
||||
- Second bill record starting after 30 days
|
||||
- Bill contains two bill records
|
||||
|
||||
"""
|
||||
|
||||
# Create product
|
||||
starting_date = timezone.make_aware(datetime.datetime(2019,3,3))
|
||||
user = self.user
|
||||
|
||||
|
||||
|
||||
starting_price = 10
|
||||
product = SampleRecurringProduct.objects.create(owner=self.user,
|
||||
rc_price=starting_price)
|
||||
downgrade_price = 5
|
||||
|
||||
|
||||
starting_date = timezone.make_aware(datetime.datetime(2019,3,3))
|
||||
first_order_should_end_at = starting_date + datetime.timedelta(days=30)
|
||||
change1_date = start_after(starting_date + datetime.timedelta(days=15))
|
||||
bill_ending_date = change1_date + datetime.timedelta(days=1)
|
||||
|
||||
|
||||
product = SampleRecurringProduct.objects.create(owner=user, rc_price=starting_price)
|
||||
product.create_order(starting_date)
|
||||
|
||||
change1_date = timezone.make_aware(datetime.datetime(2019,4,17))
|
||||
product.rc_price = 20
|
||||
product.rc_price = downgrade_price
|
||||
product.save()
|
||||
product.create_or_update_recurring_order(when_to_start=change1_date)
|
||||
|
||||
bill_ending_date = timezone.make_aware(datetime.datetime(2019,6,30))
|
||||
bills = Bill.create_next_bills_for_user(self.user,
|
||||
ending_date=bill_ending_date)
|
||||
bills = Bill.create_next_bills_for_user(user, ending_date=bill_ending_date)
|
||||
|
||||
bill = bills[0]
|
||||
bill_records = BillRecord.objects.filter(bill=bill)
|
||||
|
||||
self.assertEqual(len(bill_records), 3)
|
||||
self.assertEqual(int(bill.sum), 35)
|
||||
self.assertEqual(len(bill_records), 2)
|
||||
|
||||
self.assertEqual(bill_records[0].starting_date, starting_date)
|
||||
|
||||
self.assertEqual(bill_records[0].order.ending_date, first_order_should_end_at)
|
||||
|
||||
# self.assertEqual(bill_records[0].ending_date, first_order_should_end_at)
|
||||
|
||||
# self.assertEqual(bill_records[0].quantity, 1)
|
||||
|
||||
# self.assertEqual(bill_records[1].quantity, 1)
|
||||
# self.assertEqual(int(bill.sum), 15)
|
||||
|
||||
def test_upgrade_product(self):
|
||||
"""
|
||||
Test upgrading behaviour
|
||||
"""
|
||||
|
||||
user = self.user
|
||||
|
||||
# Create product
|
||||
starting_date = timezone.make_aware(datetime.datetime(2019,3,3))
|
||||
starting_price = 10
|
||||
product = SampleRecurringProduct.objects.create(owner=user, rc_price=starting_price)
|
||||
product.create_order(starting_date)
|
||||
|
||||
change1_date = start_after(starting_date + datetime.timedelta(days=15))
|
||||
product.rc_price = 20
|
||||
product.save()
|
||||
product.create_or_update_recurring_order(when_to_start=change1_date)
|
||||
|
||||
bill_ending_date = change1_date + datetime.timedelta(days=1)
|
||||
bills = Bill.create_next_bills_for_user(user, ending_date=bill_ending_date)
|
||||
|
||||
bill = bills[0]
|
||||
bill_records = BillRecord.objects.filter(bill=bill)
|
||||
|
||||
self.assertEqual(len(bill_records), 2)
|
||||
self.assertEqual(bill_records[0].quantity, .5)
|
||||
|
||||
self.assertEqual(bill_records[0].ending_date, end_before(change1_date))
|
||||
|
||||
self.assertEqual(bill_records[1].quantity, 1)
|
||||
self.assertEqual(bill_records[1].starting_date, change1_date)
|
||||
|
||||
self.assertEqual(int(bill.sum), 25)
|
||||
|
||||
# Expected bill sum & records:
|
||||
# 2019-03-03 - 2019-04-02 +30d: 10
|
||||
# 2019-04-02 - 2019-04-17: +15d: 5
|
||||
# 2019-04-17 - 2019-05-17: +30d: 20
|
||||
# total: 35
|
||||
|
||||
|
||||
# def test_bill_for_increasing_product(self):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue