From 7b83efe995206b85b68bff0cfac4a404e17413aa Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 25 Aug 2020 21:11:28 +0200 Subject: [PATCH] [pay] make sample products more modular --- uncloud_pay/models.py | 15 +++++++++++---- uncloud_pay/tests.py | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/uncloud_pay/models.py b/uncloud_pay/models.py index fd9eab8..f4d4c52 100644 --- a/uncloud_pay/models.py +++ b/uncloud_pay/models.py @@ -794,24 +794,31 @@ class SampleOneTimeProduct(Product): default_recurring_period = RecurringPeriod.ONE_TIME + ot_price = models.IntegerField(default=5) + @property def one_time_price(self): - return 5 + return self.ot_price class SampleRecurringProduct(Product): default_recurring_period = RecurringPeriod.PER_30D + rc_price = models.IntegerField(default=10) + @property def recurring_price(self): - return 10 + return self.rc_price class SampleRecurringProductOneTimeFee(Product): default_recurring_period = RecurringPeriod.PER_30D + ot_price = models.IntegerField(default=5) + rc_price = models.IntegerField(default=10) + @property def one_time_price(self): - return 5 + return self.ot_price @property def recurring_price(self): - return 1 + return self.rc_price diff --git a/uncloud_pay/tests.py b/uncloud_pay/tests.py index 9aa86ef..69af3cc 100644 --- a/uncloud_pay/tests.py +++ b/uncloud_pay/tests.py @@ -327,6 +327,38 @@ class BillTestCase(TestCase): self.assertEqual(len(bills), 2) + +class ModifyProductTestCase(TestCase): + def setUp(self): + self.user = get_user_model().objects.create( + username='random_user', + email='jane.random@domain.tld') + + self.ba = BillingAddress.objects.create( + owner=self.user, + organization = 'Test org', + street="unknown", + city="unknown", + postal_code="somewhere else", + active=False) + + def test_user_no_address(self): + """ + Raise an error, when there is no address + """ + + + self.assertRaises(uncloud_pay.models.BillingAddress.DoesNotExist, + BillingAddress.get_address_for, + self.user) + + def test_user_only_inactive_address(self): + """ + Raise an error, when there is no active address + """ + + + # class NotABillingTC(TestCase): # #class BillingTestCase(TestCase): # def setUp(self):