Week calendar and more improvements to subevent calendars (#1672)

This commit is contained in:
Raphael Michel
2020-05-07 15:48:47 +02:00
committed by GitHub
parent 6a4c81ff3c
commit de9c450648
28 changed files with 796 additions and 106 deletions

View File

@@ -4,13 +4,12 @@ from datetime import timedelta
from decimal import Decimal
from bs4 import BeautifulSoup
from django.dispatch import receiver
from django.test import TestCase
from django.utils.timezone import now
from django_countries.fields import Country
from django_scopes import scopes_disabled
from tests.testdummy.signals import FoobarSalesChannel
from pretix.base.channels import SalesChannel
from pretix.base.decimal import round_decimal
from pretix.base.models import (
CartPosition, Event, InvoiceAddress, Item, ItemCategory, ItemVariation,
@@ -22,26 +21,10 @@ from pretix.base.models.items import (
from pretix.base.services.cart import (
CartError, CartManager, error_messages, update_tax_rates,
)
from pretix.base.signals import register_sales_channels
from pretix.testutils.scope import classscope
from pretix.testutils.sessions import get_cart_session_key
class FoobarSalesChannel(SalesChannel):
identifier = "bar"
verbose_name = "Foobar"
icon = "home"
testmode_supported = False
unlimited_items_per_order = True
@receiver(register_sales_channels, dispatch_uid="test_cart_register_sales_channels")
def base_sales_channels(sender, **kwargs):
return (
FoobarSalesChannel(),
)
class CartTestMixin:
@scopes_disabled()
def setUp(self):

View File

@@ -11,8 +11,8 @@ from django.utils.timezone import now
from django_scopes import scopes_disabled
from pytz import timezone
from tests.base import SoupTest
from tests.testdummy.signals import FoobarSalesChannel
from pretix.base.channels import SalesChannel
from pretix.base.models import (
Event, Item, ItemCategory, ItemVariation, Order, Organizer, Quota, Team,
User, WaitingListEntry,
@@ -20,13 +20,6 @@ from pretix.base.models import (
from pretix.base.models.items import SubEventItem, SubEventItemVariation
class FoobarSalesChannel(SalesChannel):
identifier = "bar"
verbose_name = "Foobar"
icon = "home"
testmode_supported = True
class EventTestMixin:
@scopes_disabled()
def setUp(self):
@@ -228,6 +221,25 @@ class ItemDisplayTest(EventTestMixin, SoupTest):
self.assertIn("Foo SE1", resp.rendered_content)
self.assertNotIn("Foo SE2", resp.rendered_content)
def test_subevent_week_calendar(self):
self.event.settings.event_list_type = 'week'
self.event.has_subevents = True
self.event.save()
with scopes_disabled():
se1 = self.event.subevents.create(name='Foo SE1', date_from=now() + datetime.timedelta(days=24),
active=True)
self.event.subevents.create(name='Foo SE2', date_from=now() + datetime.timedelta(days=12),
active=True)
resp = self.client.get('/%s/%s/' % (self.orga.slug, self.event.slug))
print(resp.rendered_content)
self.assertIn("Foo SE2", resp.rendered_content)
self.assertNotIn("Foo SE1", resp.rendered_content)
resp = self.client.get('/%s/%s/?year=%d&week=%d' % (self.orga.slug, self.event.slug,
se1.date_from.isocalendar()[0],
se1.date_from.isocalendar()[1]))
self.assertIn("Foo SE1", resp.rendered_content)
self.assertNotIn("Foo SE2", resp.rendered_content)
def test_subevents(self):
self.event.has_subevents = True
self.event.save()

View File

@@ -138,6 +138,24 @@ def test_calendar(env, client):
assert 'October 2017' in r.rendered_content
@pytest.mark.django_db
def test_week_calendar(env, client):
env[0].settings.event_list_type = 'calendar'
e = Event.objects.create(
organizer=env[0], name='MRMCD2017', slug='2017',
date_from=datetime(now().year + 1, 9, 1, tzinfo=UTC),
live=True, is_public=False
)
r = client.get('/mrmcd/?style=week')
assert 'MRMCD2017' not in r.rendered_content
e.is_public = True
e.save()
r = client.get('/mrmcd/?style=week')
assert 'MRMCD2017' in r.rendered_content
r = client.get('/mrmcd/?style=week&week=2&year=2017')
assert 'MRMCD2017' not in r.rendered_content
@pytest.mark.django_db
def test_attributes_in_calendar(env, client):
env[0].settings.event_list_type = 'calendar'

View File

@@ -555,6 +555,44 @@ class WidgetCartTest(CartTestMixin, TestCase):
]
}
def test_subevent_week_calendar(self):
self.event.has_subevents = True
self.event.settings.timezone = 'Europe/Berlin'
self.event.save()
with freeze_time("2019-01-01 10:00:00"):
with scopes_disabled():
self.event.subevents.create(name="Past", active=True, date_from=now() - datetime.timedelta(days=3))
se1 = self.event.subevents.create(name="Present", active=True, date_from=now())
se2 = self.event.subevents.create(name="Future", active=True, date_from=now() + datetime.timedelta(days=3))
self.event.subevents.create(name="Disabled", active=False, date_from=now() + datetime.timedelta(days=3))
self.event.subevents.create(name="Hidden", active=True, is_public=False, date_from=now() + datetime.timedelta(days=3))
response = self.client.get('/%s/%s/widget/product_list?style=week' % (self.orga.slug, self.event.slug))
settings.SITE_URL = 'http://example.com'
data = json.loads(response.content.decode())
assert data == {
'list_type': 'week',
'week': [2019, 1],
'poweredby': '<a href="https://pretix.eu" target="_blank" rel="noopener">event ticketing powered by pretix</a>',
'days': [
{'day_formatted': 'Mon, Dec 31st', 'date': '2018-12-31', 'events': []},
{'day_formatted': 'Tue, Jan 1st', 'date': '2019-01-01', 'events': [
{'name': 'Present', 'time': '11:00', 'continued': False, 'date_range': 'Jan. 1, 2019 11:00',
'location': '',
'availability': {'color': 'green', 'text': 'Book now'},
'event_url': 'http://example.com/ccc/30c3/', 'subevent': se1.pk}]},
{'day_formatted': 'Wed, Jan 2nd', 'date': '2019-01-02', 'events': []},
{'day_formatted': 'Thu, Jan 3rd', 'date': '2019-01-03', 'events': []},
{'day_formatted': 'Fri, Jan 4th', 'date': '2019-01-04', 'events': [
{'name': 'Future', 'time': '11:00', 'continued': False, 'date_range': 'Jan. 4, 2019 11:00',
'location': '',
'availability': {'color': 'green', 'text': 'Book now'},
'event_url': 'http://example.com/ccc/30c3/', 'subevent': se2.pk}]},
{'day_formatted': 'Sat, Jan 5th', 'date': '2019-01-05', 'events': []},
{'day_formatted': 'Sun, Jan 6th', 'date': '2019-01-06', 'events': []}
],
}
def test_event_list(self):
self.event.has_subevents = True
self.event.settings.timezone = 'Europe/Berlin'