Simplifies creation of test data in test_cart, adds an extra product category and two new products

This commit is contained in:
Christopher Neugebauer 2016-03-27 12:08:17 +11:00
parent db332da958
commit 7c99750f3a

View file

@ -32,69 +32,46 @@ class RegistrationCartTestCase(SetTimeMixin, TestCase):
email='test2@example.com', email='test2@example.com',
password='top_secret') password='top_secret')
cls.CAT_1 = rego.Category.objects.create(
name="Category 1",
description="This is a test category",
order=10,
render_type=rego.Category.RENDER_TYPE_RADIO,
required=False,
)
cls.CAT_1.save()
cls.CAT_2 = rego.Category.objects.create(
name="Category 2",
description="This is a test category",
order=10,
render_type=rego.Category.RENDER_TYPE_RADIO,
required=False,
)
cls.CAT_2.save()
cls.RESERVATION = datetime.timedelta(hours=1) cls.RESERVATION = datetime.timedelta(hours=1)
cls.PROD_1 = rego.Product.objects.create( cls.categories = []
name="Product 1", for i in xrange(3):
description="This is a test product. It costs $10. " cat = rego.Category.objects.create(
"A user may have 10 of them.", name="Category " + str(i + 1),
category=cls.CAT_1, description="This is a test category",
price=Decimal("10.00"), order=i,
reservation_duration=cls.RESERVATION, render_type=rego.Category.RENDER_TYPE_RADIO,
limit_per_user=10, required=False,
order=10, )
) cat.save()
cls.PROD_1.save() cls.categories.append(cat)
cls.PROD_2 = rego.Product.objects.create( cls.CAT_1 = cls.categories[0]
name="Product 2", cls.CAT_2 = cls.categories[1]
description="This is a test product. It costs $10. " cls.CAT_3 = cls.categories[2]
"A user may have 10 of them.",
category=cls.CAT_1,
price=Decimal("10.00"),
limit_per_user=10,
order=10,
)
cls.PROD_2.save()
cls.PROD_3 = rego.Product.objects.create( cls.products = []
name="Product 3", for i in xrange(6):
description="This is a test product. It costs $10. " prod = rego.Product.objects.create(
"A user may have 10 of them.", name="Product 1",
category=cls.CAT_2, description="This is a test product."
price=Decimal("10.00"), category=cls.categories[i / 2], # 2 products per category
limit_per_user=10, price=Decimal("10.00"),
order=10, reservation_duration=cls.RESERVATION,
) limit_per_user=10,
cls.PROD_3.save() order=1,
)
prod.save()
cls.products.append(prod)
cls.PROD_4 = rego.Product.objects.create( cls.PROD_1 = cls.products[0]
name="Product 4", cls.PROD_2 = cls.products[1]
description="This is a test product. It costs $5. " cls.PROD_3 = cls.products[2]
"A user may have 10 of them.", cls.PROD_4 = cls.products[3]
category=cls.CAT_2, cls.PROD_5 = cls.products[4]
price=Decimal("5.00"), cls.PROD_6 = cls.products[5]
limit_per_user=10,
order=10, cls.PROD_4.price = Decimal("5.00")
)
cls.PROD_4.save() cls.PROD_4.save()
@classmethod @classmethod
@ -205,7 +182,7 @@ class BasicCartTests(RegistrationCartTestCase):
current_cart.set_quantity(self.PROD_1, 2) current_cart.set_quantity(self.PROD_1, 2)
self.assertEqual(2, get_item().quantity) self.assertEqual(2, get_item().quantity)
def test_add_to_cart_per_user_limit(self): def test_add_to_cart_product_per_user_limit(self):
current_cart = CartController.for_user(self.USER_1) current_cart = CartController.for_user(self.USER_1)
# User should be able to add 1 of PROD_1 to the current cart. # User should be able to add 1 of PROD_1 to the current cart.