forked from uncloud/uncloud
Test that creating products w/o correct billing address fails
This commit is contained in:
parent
7b83efe995
commit
ab412cb877
3 changed files with 89 additions and 13 deletions
33
uncloud_pay/migrations/0014_auto_20200825_1915.py
Normal file
33
uncloud_pay/migrations/0014_auto_20200825_1915.py
Normal file
|
@ -0,0 +1,33 @@
|
|||
# Generated by Django 3.1 on 2020-08-25 19:15
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('uncloud_pay', '0013_auto_20200809_1237'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='sampleonetimeproduct',
|
||||
name='ot_price',
|
||||
field=models.IntegerField(default=5),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='samplerecurringproduct',
|
||||
name='rc_price',
|
||||
field=models.IntegerField(default=10),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='samplerecurringproductonetimefee',
|
||||
name='ot_price',
|
||||
field=models.IntegerField(default=5),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name='samplerecurringproductonetimefee',
|
||||
name='rc_price',
|
||||
field=models.IntegerField(default=10),
|
||||
),
|
||||
]
|
|
@ -789,8 +789,25 @@ class Product(UncloudModel):
|
|||
# FIXME: use the right type of exception here!
|
||||
raise Exception("Did not implement the discounter for this case")
|
||||
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
try:
|
||||
ba = BillingAddress.get_address_for(self.owner)
|
||||
except BillingAddress.DoesNotExist:
|
||||
raise ValidationError("User does not have a billing address")
|
||||
|
||||
if not ba.active:
|
||||
raise ValidationError("User does not have an active billing address")
|
||||
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
|
||||
# Sample products included into uncloud
|
||||
class SampleOneTimeProduct(Product):
|
||||
"""
|
||||
Products are usually more complex, but this product shows how easy
|
||||
it can be to create your own one time product.
|
||||
"""
|
||||
|
||||
default_recurring_period = RecurringPeriod.ONE_TIME
|
||||
|
||||
|
@ -801,6 +818,11 @@ class SampleOneTimeProduct(Product):
|
|||
return self.ot_price
|
||||
|
||||
class SampleRecurringProduct(Product):
|
||||
"""
|
||||
Products are usually more complex, but this product shows how easy
|
||||
it can be to create your own recurring fee product.
|
||||
"""
|
||||
|
||||
default_recurring_period = RecurringPeriod.PER_30D
|
||||
|
||||
rc_price = models.IntegerField(default=10)
|
||||
|
@ -810,6 +832,11 @@ class SampleRecurringProduct(Product):
|
|||
return self.rc_price
|
||||
|
||||
class SampleRecurringProductOneTimeFee(Product):
|
||||
"""
|
||||
Products are usually more complex, but this product shows how easy
|
||||
it can be to create your own one time + recurring fee product.
|
||||
"""
|
||||
|
||||
default_recurring_period = RecurringPeriod.PER_30D
|
||||
|
||||
ot_price = models.IntegerField(default=5)
|
||||
|
|
|
@ -16,7 +16,7 @@ class ProductTestCase(TestCase):
|
|||
username='random_user',
|
||||
email='jane.random@domain.tld')
|
||||
|
||||
ba = BillingAddress.objects.create(
|
||||
self.ba = BillingAddress.objects.create(
|
||||
owner=self.user,
|
||||
organization = 'Test org',
|
||||
street="unknown",
|
||||
|
@ -34,6 +34,29 @@ class ProductTestCase(TestCase):
|
|||
self.assertEqual(p.one_time_price, 5)
|
||||
self.assertEqual(p.recurring_price, 0)
|
||||
|
||||
def test_create_product_without_active_billing_address(self):
|
||||
"""
|
||||
Fail to create a product without an active billing address
|
||||
"""
|
||||
|
||||
self.ba.active = False
|
||||
self.ba.save()
|
||||
|
||||
with self.assertRaises(ValidationError):
|
||||
p = SampleOneTimeProduct.objects.create(owner=self.user)
|
||||
|
||||
def test_create_product_without_billing_address(self):
|
||||
"""
|
||||
Fail to create a product without a billing address
|
||||
"""
|
||||
|
||||
user2 = get_user_model().objects.create(
|
||||
username='random_user2',
|
||||
email='jane.randomly@domain.tld')
|
||||
|
||||
with self.assertRaises(ValidationError):
|
||||
p = SampleOneTimeProduct.objects.create(owner=user2)
|
||||
|
||||
|
||||
def test_create_order_creates_correct_order_count(self):
|
||||
"""
|
||||
|
@ -329,6 +352,7 @@ class BillTestCase(TestCase):
|
|||
|
||||
|
||||
class ModifyProductTestCase(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.user = get_user_model().objects.create(
|
||||
username='random_user',
|
||||
|
@ -340,23 +364,15 @@ class ModifyProductTestCase(TestCase):
|
|||
street="unknown",
|
||||
city="unknown",
|
||||
postal_code="somewhere else",
|
||||
active=False)
|
||||
active=True)
|
||||
|
||||
def test_user_no_address(self):
|
||||
"""
|
||||
Raise an error, when there is no address
|
||||
def test_modify_recurring_product(self):
|
||||
"""
|
||||
|
||||
|
||||
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
|
||||
"""
|
||||
|
||||
product = SampleRecurringProduct.objects.create(owner=self.user)
|
||||
|
||||
|
||||
|
||||
# class NotABillingTC(TestCase):
|
||||
|
|
Loading…
Reference in a new issue