Add order-level telephone field to core (#1872)

Co-authored-by: Martin Gross <gross@rami.io>
This commit is contained in:
Raphael Michel
2020-12-15 09:20:44 +01:00
committed by GitHub
parent c47e41ac8a
commit 4240ad43d0
27 changed files with 507 additions and 69 deletions

View File

@@ -211,6 +211,7 @@ TEST_ORDER_RES = {
"testmode": False,
"secret": "k24fiuwvu8kxz3y1",
"email": "dummy@dummy.test",
"phone": None,
"locale": "en",
"datetime": "2017-12-01T10:00:00Z",
"expires": "2017-12-10T10:00:00Z",
@@ -1528,6 +1529,7 @@ def test_order_invalid_state_deny(token_client, organizer, event, order):
ORDER_CREATE_PAYLOAD = {
"email": "dummy@dummy.test",
"phone": "+49622112345",
"locale": "en",
"sales_channel": "web",
"fees": [
@@ -1589,6 +1591,7 @@ def test_order_create(token_client, organizer, event, item, quota, question):
with scopes_disabled():
o = Order.objects.get(code=resp.data['code'])
assert o.email == "dummy@dummy.test"
assert o.phone == "+49622112345"
assert o.locale == "en"
assert o.total == Decimal('23.25')
assert o.status == Order.STATUS_PENDING
@@ -1657,6 +1660,7 @@ def test_order_create_simulate(token_client, organizer, event, item, quota, ques
'status': 'n',
'testmode': False,
'email': 'dummy@dummy.test',
'phone': '+49622112345',
'locale': 'en',
'datetime': None,
'payment_date': None,
@@ -4107,6 +4111,7 @@ def test_order_update_allowed_fields(token_client, organizer, event, order):
'comment': 'Here is a comment',
'checkin_attention': True,
'email': 'foo@bar.com',
'phone': '+4962219999',
'locale': 'de',
'invoice_address': {
"is_business": False,
@@ -4128,6 +4133,7 @@ def test_order_update_allowed_fields(token_client, organizer, event, order):
assert order.comment == 'Here is a comment'
assert order.checkin_attention
assert order.email == 'foo@bar.com'
assert order.phone == '+4962219999'
assert order.locale == 'de'
assert order.invoice_address.company == "This is my company name"
assert order.invoice_address.name_cached == "John Doe"
@@ -4139,6 +4145,7 @@ def test_order_update_allowed_fields(token_client, organizer, event, order):
assert order.all_logentries().get(action_type='pretix.event.order.comment')
assert order.all_logentries().get(action_type='pretix.event.order.checkin_attention')
assert order.all_logentries().get(action_type='pretix.event.order.contact.changed')
assert order.all_logentries().get(action_type='pretix.event.order.phone.changed')
assert order.all_logentries().get(action_type='pretix.event.order.locale.changed')
assert order.all_logentries().get(action_type='pretix.event.order.modified')

View File

@@ -33,7 +33,7 @@ def extract_form_fields(soup):
continue
if field['type'] in ('checkbox', 'radio'):
if field.has_attr('checked'):
if field.has_attr('checked') and field.has_attr('name'):
data[field['name']] = field.get('value', 'on')
continue
elif field.has_attr('name'):

View File

@@ -568,6 +568,44 @@ class CheckoutTestCase(BaseCheckoutTestCase, TestCase):
assert not cr1.answers.exists()
assert not os.path.exists(os.path.join(settings.MEDIA_ROOT, a.file.name))
def test_phone_required(self):
self.event.settings.set('order_phone_asked', True)
self.event.settings.set('order_phone_required', True)
with scopes_disabled():
CartPosition.objects.create(
event=self.event, cart_id=self.session_key, item=self.ticket,
price=23, expires=now() + timedelta(minutes=10)
)
response = self.client.get('/%s/%s/checkout/questions/' % (self.orga.slug, self.event.slug), follow=True)
doc = BeautifulSoup(response.rendered_content, "lxml")
self.assertEqual(len(doc.select('input[name="phone_1"]')), 1)
# Not all required fields filled out, expect failure
response = self.client.post('/%s/%s/checkout/questions/' % (self.orga.slug, self.event.slug), {
'email': 'admin@localhost',
}, follow=True)
doc = BeautifulSoup(response.rendered_content, "lxml")
self.assertGreaterEqual(len(doc.select('.has-error')), 1)
# Corrected request
response = self.client.post('/%s/%s/checkout/questions/' % (self.orga.slug, self.event.slug), {
'email': 'admin@localhost',
'phone_0': '+49',
'phone_1': '0622199999', # yeah the 0 is wrong but users don't know that so it should work fine
}, follow=True)
self.assertRedirects(response, '/%s/%s/checkout/payment/' % (self.orga.slug, self.event.slug),
target_status_code=200)
self.client.post('/%s/%s/checkout/payment/' % (self.orga.slug, self.event.slug), {
'payment': 'banktransfer',
}, follow=True)
response = self.client.post('/%s/%s/checkout/confirm/' % (self.orga.slug, self.event.slug), follow=True)
doc = BeautifulSoup(response.rendered_content, "lxml")
self.assertEqual(len(doc.select(".thank-you")), 1)
with scopes_disabled():
o = Order.objects.last()
assert o.phone == '+49622199999'
def test_attendee_email_required(self):
self.event.settings.set('attendee_emails_asked', True)
self.event.settings.set('attendee_emails_required', True)