Introduce country-specific address validation (#2945)

Co-authored-by: Richard Schreiber <schreiber@rami.io>
This commit is contained in:
Raphael Michel
2022-12-05 12:42:46 +01:00
committed by GitHub
parent 6a8df75a9f
commit 04df1c2032
7 changed files with 467 additions and 21 deletions

View File

@@ -170,7 +170,7 @@ class CheckoutTestCase(BaseCheckoutTestCase, TestCase):
'company': 'Foo',
'name': 'Bar',
'street': 'Baz',
'zipcode': '12345',
'zipcode': '1234',
'city': 'Here',
'country': 'AT',
'vat_id': 'AT123456',
@@ -193,7 +193,7 @@ class CheckoutTestCase(BaseCheckoutTestCase, TestCase):
'is_business': 'individual',
'name': 'Bar',
'street': 'Baz',
'zipcode': '12345',
'zipcode': '1234',
'city': 'Here',
'country': 'AT',
'vat_id': '',
@@ -229,7 +229,7 @@ class CheckoutTestCase(BaseCheckoutTestCase, TestCase):
'company': 'Foo',
'name': 'Bar',
'street': 'Baz',
'zipcode': '12345',
'zipcode': '1234',
'city': 'Here',
'country': 'AT',
'vat_id': 'AT123456',
@@ -259,7 +259,7 @@ class CheckoutTestCase(BaseCheckoutTestCase, TestCase):
'company': 'Foo',
'name': 'Bar',
'street': 'Baz',
'zipcode': '12345',
'zipcode': '3000',
'city': 'Here',
'country': 'AU',
'state': 'QLD',
@@ -293,7 +293,7 @@ class CheckoutTestCase(BaseCheckoutTestCase, TestCase):
'company': 'Foo',
'name': 'Bar',
'street': 'Baz',
'zipcode': '12345',
'zipcode': '1234',
'city': 'Here',
'country': 'AT',
'vat_id': 'AT123456',
@@ -324,7 +324,7 @@ class CheckoutTestCase(BaseCheckoutTestCase, TestCase):
'company': 'Foo',
'name': 'Bar',
'street': 'Baz',
'zipcode': '12345',
'zipcode': '1234',
'city': 'Here',
'country': 'FR',
'vat_id': 'AT123456',
@@ -357,7 +357,7 @@ class CheckoutTestCase(BaseCheckoutTestCase, TestCase):
'company': 'Foo',
'name': 'Bar',
'street': 'Baz',
'zipcode': '12345',
'zipcode': '1234',
'city': 'Here',
'country': 'AT',
'vat_id': 'AT123456',
@@ -391,7 +391,7 @@ class CheckoutTestCase(BaseCheckoutTestCase, TestCase):
'company': 'Foo',
'name': 'Bar',
'street': 'Baz',
'zipcode': '12345',
'zipcode': '1234',
'city': 'Here',
'country': 'AT',
'vat_id': 'AT123456',
@@ -428,7 +428,7 @@ class CheckoutTestCase(BaseCheckoutTestCase, TestCase):
'company': 'Foo',
'name': 'Bar',
'street': 'Baz',
'zipcode': '12345',
'zipcode': '1234',
'city': 'Here',
'country': 'AT',
'vat_id': 'AT123456',
@@ -492,7 +492,7 @@ class CheckoutTestCase(BaseCheckoutTestCase, TestCase):
'company': 'Foo',
'name': 'Bar',
'street': 'Baz',
'zipcode': '12345',
'zipcode': '1234',
'city': 'Here',
'country': 'AT',
'vat_id': 'AT123456',
@@ -551,7 +551,7 @@ class CheckoutTestCase(BaseCheckoutTestCase, TestCase):
'is_business': 'individual',
'name': 'Bar',
'street': 'Baz',
'zipcode': '12345',
'zipcode': '1234',
'city': 'Here',
'country': 'AT',
'email': 'admin@localhost'
@@ -603,7 +603,7 @@ class CheckoutTestCase(BaseCheckoutTestCase, TestCase):
'is_business': 'individual',
'name': 'Bar',
'street': 'Baz',
'zipcode': '12345',
'zipcode': '1234',
'city': 'Here',
'country': 'AT',
'email': 'admin@localhost'
@@ -631,7 +631,7 @@ class CheckoutTestCase(BaseCheckoutTestCase, TestCase):
'is_business': 'individual',
'name': 'Bar',
'street': 'Baz',
'zipcode': '12345',
'zipcode': '99501',
'city': 'Here',
'country': 'US',
'state': 'CA',
@@ -684,7 +684,7 @@ class CheckoutTestCase(BaseCheckoutTestCase, TestCase):
'company': 'Foo',
'name': 'Bar',
'street': 'Baz',
'zipcode': '12345',
'zipcode': '1345',
'city': 'Here',
'country': 'AT',
'vat_id': 'AT123456',
@@ -748,7 +748,7 @@ class CheckoutTestCase(BaseCheckoutTestCase, TestCase):
'company': 'Foo',
'name': 'Bar',
'street': 'Baz',
'zipcode': '12345',
'zipcode': '1234',
'city': 'Here',
'country': 'AT',
'vat_id': 'AT123456',
@@ -1102,6 +1102,57 @@ class CheckoutTestCase(BaseCheckoutTestCase, TestCase):
}
assert ia.name_cached == 'Mr John Kennedy'
def test_invoice_address_validated(self):
self.event.settings.invoice_address_asked = True
self.event.settings.invoice_address_required = True
self.event.settings.invoice_address_not_asked_free = True
self.event.settings.set('name_scheme', 'title_given_middle_family')
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.content.decode(), "lxml")
self.assertEqual(len(doc.select('input[name="city"]')), 1)
# Not all required fields filled out correctly, expect failure
response = self.client.post('/%s/%s/checkout/questions/' % (self.orga.slug, self.event.slug), {
'is_business': 'business',
'company': 'Foo',
'name_parts_0': 'Mr',
'name_parts_1': 'John',
'name_parts_2': '',
'name_parts_3': 'Kennedy',
'street': 'Baz',
'zipcode': '123456',
'city': 'Here',
'country': 'DE',
'vat_id': 'DE123456',
'email': 'admin@localhost'
}, follow=True)
doc = BeautifulSoup(response.content.decode(), "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), {
'is_business': 'business',
'company': 'Foo',
'name_parts_0': 'Mr',
'name_parts_1': 'John',
'name_parts_2': '',
'name_parts_3': 'Kennedy',
'street': 'Baz',
'zipcode': '12345',
'city': 'Here',
'country': 'DE',
'vat_id': 'DE123456',
'email': 'admin@localhost'
}, follow=True)
self.assertRedirects(response, '/%s/%s/checkout/payment/' % (self.orga.slug, self.event.slug),
target_status_code=200)
def test_invoice_address_hidden_for_free(self):
self.event.settings.invoice_address_asked = True
self.event.settings.invoice_address_required = True
@@ -1136,10 +1187,19 @@ class CheckoutTestCase(BaseCheckoutTestCase, TestCase):
doc = BeautifulSoup(response.content.decode(), "lxml")
self.assertEqual(len(doc.select('input[name="city"]')), 1)
# Not all required fields filled out, expect failure
# Partial address is not allowed
response = self.client.post('/%s/%s/checkout/questions/' % (self.orga.slug, self.event.slug), {
'is_business': 'business',
'country': 'DE',
'city': 'Musterstadt',
'email': 'admin@localhost'
}, follow=True)
doc = BeautifulSoup(response.content.decode(), "lxml")
self.assertGreaterEqual(len(doc.select('.has-error')), 1)
# No address works
response = self.client.post('/%s/%s/checkout/questions/' % (self.orga.slug, self.event.slug), {
'is_business': 'business',
'city': 'Here',
'country': 'DE',
'vat_id': 'DE123456',
'email': 'admin@localhost'

View File

@@ -345,6 +345,35 @@ class OrdersTest(BaseOrdersTest):
with scopes_disabled():
assert self.ticket_pos.answers.get(question=self.question).answer == 'ABC'
def test_modify_invoice_address_validated(self):
self.event.settings.set('invoice_reissue_after_modify', True)
self.event.settings.set('invoice_address_asked', True)
with scopes_disabled():
generate_invoice(self.order)
response = self.client.post(
'/%s/%s/order/%s/%s/modify' % (self.orga.slug, self.event.slug, self.order.code, self.order.secret), {
'%s-question_%s' % (self.ticket_pos.id, self.question.id): 'ABC',
}, follow=True)
self.assertRedirects(response,
'/%s/%s/order/%s/%s/' % (self.orga.slug, self.event.slug, self.order.code,
self.order.secret),
target_status_code=200)
# Only questions changed
with scopes_disabled():
assert self.order.invoices.count() == 1
response = self.client.post(
'/%s/%s/order/%s/%s/modify' % (self.orga.slug, self.event.slug, self.order.code, self.order.secret), {
'%s-question_%s' % (self.ticket_pos.id, self.question.id): 'ABC',
'zipcode': 'XXINVALIDXX',
'street': 'Main Street',
'city': 'Heidelberg',
'country': 'DE',
}, follow=True)
doc = BeautifulSoup(response.content.decode(), "lxml")
self.assertGreaterEqual(len(doc.select('.has-error')), 1)
def test_modify_invoice_regenerate(self):
self.event.settings.set('invoice_reissue_after_modify', True)
self.event.settings.set('invoice_address_asked', True)
@@ -366,7 +395,10 @@ class OrdersTest(BaseOrdersTest):
response = self.client.post(
'/%s/%s/order/%s/%s/modify' % (self.orga.slug, self.event.slug, self.order.code, self.order.secret), {
'%s-question_%s' % (self.ticket_pos.id, self.question.id): 'ABC',
'zipcode': '1234',
'zipcode': '12345',
'street': 'Main Street',
'city': 'Heidelberg',
'country': 'DE',
}, follow=True)
self.assertRedirects(response,
'/%s/%s/order/%s/%s/' % (self.orga.slug, self.event.slug, self.order.code,
@@ -381,6 +413,9 @@ class OrdersTest(BaseOrdersTest):
'/%s/%s/order/%s/%s/modify' % (self.orga.slug, self.event.slug, self.order.code, self.order.secret), {
'%s-question_%s' % (self.ticket_pos.id, self.question.id): 'ABC',
'zipcode': '54321',
'street': 'Main Street',
'city': 'Heidelberg',
'country': 'DE',
}, follow=True)
self.assertRedirects(response,
'/%s/%s/order/%s/%s/' % (self.orga.slug, self.event.slug, self.order.code,