Additional tests for the item list

This commit is contained in:
Raphael Michel
2015-02-18 21:37:12 +01:00
parent 1d6232f30b
commit 9a2e75cbfb
3 changed files with 31 additions and 2 deletions

View File

@@ -921,7 +921,7 @@ class Item(Versionable):
This method is used to determine whether this Item is currently available
for sale. It may return any of the return codes of Quota.availability()
"""
if self.properties.count() > 0:
if self.properties.count() > 0: # NOQA
raise ValueError('Do not call this directly on items which have properties '
'but call this on their ItemVariation objects')
return min([q.availability() for q in self.quotas.all()])
@@ -933,7 +933,7 @@ class Item(Versionable):
It returns False, if the item is unavailable or the item's price, if it is
available.
"""
if self.properties.count() > 0:
if self.properties.count() > 0: # NOQA
raise ValueError('Do not call this directly on items which have properties '
'but call this on their ItemVariation objects')
from .signals import determine_availability

View File

@@ -93,3 +93,30 @@ class ItemDisplayTest(BrowserTest):
self.driver.find_element_by_css_selector("section:nth-of-type(1)").text)
self.assertNotIn("Black",
self.driver.find_element_by_css_selector("section:nth-of-type(1)").text)
def test_variation_prices_in_quota(self):
c = ItemCategory.objects.create(event=self.event, name="Entry tickets", position=0)
q = Quota.objects.create(event=self.event, name='Quota', size=2)
item = Item.objects.create(event=self.event, name='Early-bird ticket', category=c, default_price=12)
prop1 = Property.objects.create(event=self.event, name="Color")
item.properties.add(prop1)
val1 = PropertyValue.objects.create(prop=prop1, value="Red", position=0)
val2 = PropertyValue.objects.create(prop=prop1, value="Black", position=1)
q.items.add(item)
var1 = ItemVariation.objects.create(item=item, default_price=14)
var1.values.add(val1)
var2 = ItemVariation.objects.create(item=item)
var2.values.add(val2)
q.variations.add(var1)
q.variations.add(var2)
self.driver.get('%s/%s/%s/' % (self.live_server_url, self.orga.slug, self.event.slug))
self.assertIn("Early-bird",
self.driver.find_element_by_css_selector("section:nth-of-type(1) div:nth-of-type(1)").text)
self.assertIn("Red",
self.driver.find_elements_by_css_selector("section:nth-of-type(1) div.variation")[0].text)
self.assertIn("14.00",
self.driver.find_elements_by_css_selector("section:nth-of-type(1) div.variation")[0].text)
self.assertIn("Black",
self.driver.find_elements_by_css_selector("section:nth-of-type(1) div.variation")[1].text)
self.assertIn("12.00",
self.driver.find_elements_by_css_selector("section:nth-of-type(1) div.variation")[1].text)

View File

@@ -46,6 +46,8 @@ class EventIndex(EventViewMixin, CartDisplayMixin, TemplateView):
var.cached_availability[1] = min(var.cached_availability[1],
self.request.event.max_items_per_order)
items = [item for item in items if len(item.available_variations) > 0]
# Regroup those by category
context['items_by_category'] = sorted([
# a group is a tuple of a category and a list of items