From d1e993140c9afc61503ab96fe71a2721b6be9586 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Floure?= Date: Fri, 17 Apr 2020 10:09:28 +0200 Subject: [PATCH] Add simple product activation test --- .../uncloud/uncloud_pay/tests.py | 42 +++++++++++++++++-- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/uncloud_django_based/uncloud/uncloud_pay/tests.py b/uncloud_django_based/uncloud/uncloud_pay/tests.py index f76007f..4bdd791 100644 --- a/uncloud_django_based/uncloud/uncloud_pay/tests.py +++ b/uncloud_django_based/uncloud/uncloud_pay/tests.py @@ -3,6 +3,7 @@ from django.contrib.auth import get_user_model from datetime import datetime, date, timedelta from .models import * +from ungleich_service.models import GenericServiceProduct class BillingTestCase(TestCase): def setUp(self): @@ -10,9 +11,6 @@ class BillingTestCase(TestCase): username='jdoe', email='john.doe@domain.tld') - def test_truth(self): - self.assertEqual(1+1, 2) - def test_basic_monthly_billing(self): one_time_price = 10 recurring_price = 20 @@ -116,3 +114,41 @@ class BillingTestCase(TestCase): self.assertEqual(len(second_month_bills), 1) self.assertEqual(float(second_month_bills[0].total), 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 + )