From db1a69561bde519a314a5e1ff1f82054fb143863 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Sat, 8 Aug 2020 22:31:43 +0200 Subject: [PATCH] pass first 2 bill tests Signed-off-by: Nico Schottelius --- uncloud_pay/models.py | 8 +++++--- uncloud_pay/tests.py | 23 +++++++++++++---------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/uncloud_pay/models.py b/uncloud_pay/models.py index 0c3dcf6..9de1631 100644 --- a/uncloud_pay/models.py +++ b/uncloud_pay/models.py @@ -399,8 +399,8 @@ class Bill(models.Model): @property def sum(self): - return 0 -# for self.billrecord_set. + bill_records = BillRecord.objects.filter(bill=self) + return sum([ br.sum for br in bill_records ]) @classmethod @@ -525,9 +525,10 @@ class BillRecord(models.Model): starting_date = models.DateTimeField() ending_date = models.DateTimeField() + @property def quantity(self): """ Determine the quantity by the duration""" - if self.order.is_recurring: + if self.order.is_one_time: return 1 record_delta = self.ending_date - self.starting_date @@ -535,6 +536,7 @@ class BillRecord(models.Model): return record_delta.total_seconds()/self.order.recurring_period + @property def sum(self): return self.order.price * self.quantity diff --git a/uncloud_pay/tests.py b/uncloud_pay/tests.py index d2cdc34..6dc0aeb 100644 --- a/uncloud_pay/tests.py +++ b/uncloud_pay/tests.py @@ -27,14 +27,7 @@ class ProductActivationTestCase(TestCase): 'description': 'One chocolate bar' } - - def test_bill_one_time_order(self): - one_time_price = 10 - recurring_price = 150 - description = "Test Product 1" - - - order = Order.objects.create( + self.one_time_order = Order.objects.create( owner=self.user, starting_date=self.order_meta[1]['starting_date'], ending_date=self.order_meta[1]['ending_date'], @@ -44,15 +37,25 @@ class ProductActivationTestCase(TestCase): billing_address=self.billing_address) + def test_bill_one_time_one_bill_record(self): + """ + Ensure there is only 1 bill record per order + """ + bill = Bill.create_next_bill_for_user(self.user) - self.assertEqual(order.billrecord_set.count(), 1) + self.assertEqual(self.one_time_order.billrecord_set.count(), 1) + def test_bill_sum(self): + """ + Ensure there is only 1 bill record per order + """ + + bill = Bill.create_next_bill_for_user(self.user) self.assertEqual(bill.sum, self.order_meta[1]['price']) - # class NotABillingTC(TestCase): # #class BillingTestCase(TestCase): # def setUp(self):