Fixed failing tests under django 3.2 (#67945)

This commit is contained in:
Agate 2022-08-04 15:02:17 +02:00
parent b2cb4d9b2c
commit ba138c8090
2 changed files with 49 additions and 6 deletions

View File

@ -916,14 +916,32 @@ def test_detail_agenda_pricing_test_tool_for_event(
adult_external_id='adult:1',
)
]
# XXX Compat: html entities are slightly different under django 2 and django 3
# the following code ensure tests pass under both versions.
# The output looks exactly the same to an end user.
assert '<p>Pricing: 42.00</p>' in resp
assert '<pre>{&#39;foo&#39;: &#39;bar&#39;, &#39;pricing&#39;: Decimal(&#39;42&#39;)}</pre>' in resp
django2_match = (
'<pre>{&#39;foo&#39;: &#39;bar&#39;, &#39;pricing&#39;: Decimal(&#39;42&#39;)}</pre>' in resp
)
django3_match = (
'<pre>{&#x27;foo&#x27;: &#x27;bar&#x27;, &#x27;pricing&#x27;: Decimal(&#x27;42&#x27;)}</pre>' in resp
)
assert django2_match or django3_match
mock_pricing_data_event.side_effect = PricingError(details={'foo': 'error'})
resp = resp.form.submit().follow()
assert 'Computed pricing data' in resp
assert '&#39;error&#39;: &lt;class &#39;lingo.pricing.models.PricingError&#39;&gt;' in resp
assert '&#39;error_details&#39;: {&#39;foo&#39;: &#39;error&#39;}' in resp
django2_match = '&#39;error&#39;: &lt;class &#39;lingo.pricing.models.PricingError&#39;&gt;' in resp
django3_match = '&#x27;error&#x27;: &lt;class &#x27;lingo.pricing.models.PricingError&#x27;&gt;' in resp
assert django2_match or django3_match
django2_match = '&#39;error_details&#39;: {&#39;foo&#39;: &#39;error&#39;}' in resp
django3_match = '&#x27;error_details&#x27;: {&#x27;foo&#x27;: &#x27;error&#x27;}' in resp
assert django2_match or django3_match
@mock.patch('lingo.pricing.forms.get_event')
@ -1142,13 +1160,28 @@ def test_detail_agenda_pricing_test_tool_for_flat_fee_schedule(
)
]
assert '<p>Pricing: 42.00</p>' in resp
assert '<pre>{&#39;foo&#39;: &#39;bar&#39;, &#39;pricing&#39;: Decimal(&#39;42&#39;)}</pre>' in resp
django2_match = (
'<pre>{&#39;foo&#39;: &#39;bar&#39;, &#39;pricing&#39;: Decimal(&#39;42&#39;)}</pre>' in resp
)
django3_match = (
'<pre>{&#x27;foo&#x27;: &#x27;bar&#x27;, &#x27;pricing&#x27;: Decimal(&#x27;42&#x27;)}</pre>' in resp
)
assert django2_match or django3_match
mock_pricing_data.side_effect = PricingError(details={'foo': 'error'})
resp = resp.form.submit().follow()
assert 'Computed pricing data' in resp
assert '&#39;error&#39;: &lt;class &#39;lingo.pricing.models.PricingError&#39;&gt;' in resp
assert '&#39;error_details&#39;: {&#39;foo&#39;: &#39;error&#39;}' in resp
django2_match = '&#39;error&#39;: &lt;class &#39;lingo.pricing.models.PricingError&#39;&gt;' in resp
django3_match = '&#x27;error&#x27;: &lt;class &#x27;lingo.pricing.models.PricingError&#x27;&gt;' in resp
assert django2_match or django3_match
django2_match = '&#39;error_details&#39;: {&#39;foo&#39;: &#39;error&#39;}' in resp
django3_match = '&#x27;error_details&#x27;: {&#x27;foo&#x27;: &#x27;error&#x27;}' in resp
assert django2_match or django3_match
billing_date1 = agenda_pricing.billingdates.create(
date_start=datetime.date(2021, 9, 1),

View File

@ -55,3 +55,13 @@ KNOWN_SERVICES = {
}
PASSWORD_HASHERS = ["django.contrib.auth.hashers.MD5PasswordHasher"]
REST_FRAMEWORK = {
'EXCEPTION_HANDLER': 'lingo.api.utils.exception_handler',
# this is the default value but by explicitely setting it
# we avoid a collision with django-webtest erasing the setting
# while patching it
'DEFAULT_AUTHENTICATION_CLASSES': [
'rest_framework.authentication.SessionAuthentication',
'rest_framework.authentication.BasicAuthentication',
],
}