From 8bbcc5df5f7f5ea0dd10368c259355698165d478 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Sat, 23 May 2020 21:32:56 +0200 Subject: [PATCH] ++dev --- uncloud/urls.py | 2 +- uncloud_net/tests.py | 12 ++++++++++-- uncloud_pay/models.py | 13 +++++++++++++ 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/uncloud/urls.py b/uncloud/urls.py index c75ba95..4033f88 100644 --- a/uncloud/urls.py +++ b/uncloud/urls.py @@ -57,7 +57,7 @@ router.register(r'v1/admin/vpnreservation', netviews.VPNNetworkReservationViewSe # Pay -router.register(r'v1/my/address', payviews.BillingAddressViewSet, basename='address') +router.register(r'v1/my/address', payviews.BillingAddressViewSet, basename='billingaddress') router.register(r'v1/my/bill', payviews.BillViewSet, basename='bill') router.register(r'v1/my/order', payviews.OrderViewSet, basename='order') router.register(r'v1/my/payment', payviews.PaymentViewSet, basename='payment') diff --git a/uncloud_net/tests.py b/uncloud_net/tests.py index dadaecf..7ed6f1f 100644 --- a/uncloud_net/tests.py +++ b/uncloud_net/tests.py @@ -8,6 +8,7 @@ from django.core.exceptions import ValidationError from .views import * from .models import * +from uncloud_pay.models import BillingAddress, Order class VPNTests(TestCase): def setUp(self): @@ -61,12 +62,19 @@ class VPNTests(TestCase): }) force_authenticate(request, user=self.user) - # we don't have a billing address + # we don't have a billing address -> raises error with self.assertRaises(ValidationError): response = view(request) + ba = BillingAddress.objects.create(owner=self.user) + + # This should work now + response = view(request) + + # Verify that an order was created successfully - there should only be one order at + # this point in time + order = Order.objects.get(owner=self.user) - #print(response) def tearDown(self): diff --git a/uncloud_pay/models.py b/uncloud_pay/models.py index efb7b07..0b7a132 100644 --- a/uncloud_pay/models.py +++ b/uncloud_pay/models.py @@ -623,10 +623,23 @@ class Order(models.Model): blank=True, null=True) + def active_before(self, ending_date): + # Was this order started before the specified ending date? + if self.starting_date <= ending_date: + if self.ending_date: + if self.ending_date > ending_date: + + @property + def is_recurring(self): + return not self.recurring_period == RecurringPeriod.ONE_TIME + @property def is_terminated(self): return self.ending_date != None and self.ending_date < timezone.now() + def is_terminated_at(self, a_date): + return self.ending_date != None and self.ending_date < timezone.now() + def terminate(self): if not self.is_terminated: self.ending_date = timezone.now()