Add simple product activation test
This commit is contained in:
parent
c57780fb4d
commit
d1e993140c
1 changed files with 39 additions and 3 deletions
|
@ -3,6 +3,7 @@ from django.contrib.auth import get_user_model
|
||||||
from datetime import datetime, date, timedelta
|
from datetime import datetime, date, timedelta
|
||||||
|
|
||||||
from .models import *
|
from .models import *
|
||||||
|
from ungleich_service.models import GenericServiceProduct
|
||||||
|
|
||||||
class BillingTestCase(TestCase):
|
class BillingTestCase(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
@ -10,9 +11,6 @@ class BillingTestCase(TestCase):
|
||||||
username='jdoe',
|
username='jdoe',
|
||||||
email='john.doe@domain.tld')
|
email='john.doe@domain.tld')
|
||||||
|
|
||||||
def test_truth(self):
|
|
||||||
self.assertEqual(1+1, 2)
|
|
||||||
|
|
||||||
def test_basic_monthly_billing(self):
|
def test_basic_monthly_billing(self):
|
||||||
one_time_price = 10
|
one_time_price = 10
|
||||||
recurring_price = 20
|
recurring_price = 20
|
||||||
|
@ -116,3 +114,41 @@ class BillingTestCase(TestCase):
|
||||||
self.assertEqual(len(second_month_bills), 1)
|
self.assertEqual(len(second_month_bills), 1)
|
||||||
self.assertEqual(float(second_month_bills[0].total),
|
self.assertEqual(float(second_month_bills[0].total),
|
||||||
round(12 * recurring_price, AMOUNT_DECIMALS))
|
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')
|
||||||
|
|
||||||
|
def test_product_activation(self):
|
||||||
|
starting_date = datetime.fromisoformat('2020-03-01')
|
||||||
|
|
||||||
|
order = Order.objects.create(
|
||||||
|
owner=self.user,
|
||||||
|
starting_date=starting_date,
|
||||||
|
recurring_period=RecurringPeriod.PER_MONTH)
|
||||||
|
order.save()
|
||||||
|
|
||||||
|
product = GenericServiceProduct(
|
||||||
|
custom_description="Test product",
|
||||||
|
custom_one_time_price=0,
|
||||||
|
custom_recurring_price=20,
|
||||||
|
owner=self.user,
|
||||||
|
order=order)
|
||||||
|
product.save()
|
||||||
|
|
||||||
|
# XXX: to be automated.
|
||||||
|
order.add_record(product.one_time_price, product.recurring_price, product.description)
|
||||||
|
|
||||||
|
# Validate initial state: must be awaiting payment.
|
||||||
|
self.assertEqual(product.status, UncloudStatus.AWAITING_PAYMENT)
|
||||||
|
|
||||||
|
# Pay initial bill, check that product is activated.
|
||||||
|
amount = product.order.bills[0].total
|
||||||
|
payment = Payment(owner=self.user, amount=amount)
|
||||||
|
payment.save()
|
||||||
|
self.assertEqual(
|
||||||
|
GenericServiceProduct.objects.get(uuid=product.uuid).status,
|
||||||
|
UncloudStatus.PENDING
|
||||||
|
)
|
||||||
|
|
Loading…
Reference in a new issue