From ba138c80906256917a38bcacc7a626c5edda1849 Mon Sep 17 00:00:00 2001 From: Agate Berriot Date: Thu, 4 Aug 2022 15:02:17 +0200 Subject: [PATCH] Fixed failing tests under django 3.2 (#67945) --- tests/pricing/manager/test_agenda_pricing.py | 45 +++++++++++++++++--- tests/settings.py | 10 +++++ 2 files changed, 49 insertions(+), 6 deletions(-) diff --git a/tests/pricing/manager/test_agenda_pricing.py b/tests/pricing/manager/test_agenda_pricing.py index 6ec7f9f..6254568 100644 --- a/tests/pricing/manager/test_agenda_pricing.py +++ b/tests/pricing/manager/test_agenda_pricing.py @@ -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 '

Pricing: 42.00

' in resp - assert '
{'foo': 'bar', 'pricing': Decimal('42')}
' in resp + django2_match = ( + '
{'foo': 'bar', 'pricing': Decimal('42')}
' in resp + ) + django3_match = ( + '
{'foo': 'bar', 'pricing': Decimal('42')}
' 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 ''error': <class 'lingo.pricing.models.PricingError'>' in resp - assert ''error_details': {'foo': 'error'}' in resp + + django2_match = ''error': <class 'lingo.pricing.models.PricingError'>' in resp + django3_match = ''error': <class 'lingo.pricing.models.PricingError'>' in resp + + assert django2_match or django3_match + + django2_match = ''error_details': {'foo': 'error'}' in resp + django3_match = ''error_details': {'foo': 'error'}' 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 '

Pricing: 42.00

' in resp - assert '
{'foo': 'bar', 'pricing': Decimal('42')}
' in resp + django2_match = ( + '
{'foo': 'bar', 'pricing': Decimal('42')}
' in resp + ) + django3_match = ( + '
{'foo': 'bar', 'pricing': Decimal('42')}
' 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 ''error': <class 'lingo.pricing.models.PricingError'>' in resp - assert ''error_details': {'foo': 'error'}' in resp + + django2_match = ''error': <class 'lingo.pricing.models.PricingError'>' in resp + django3_match = ''error': <class 'lingo.pricing.models.PricingError'>' in resp + + assert django2_match or django3_match + + django2_match = ''error_details': {'foo': 'error'}' in resp + django3_match = ''error_details': {'foo': 'error'}' in resp + + assert django2_match or django3_match billing_date1 = agenda_pricing.billingdates.create( date_start=datetime.date(2021, 9, 1), diff --git a/tests/settings.py b/tests/settings.py index 1c45c63..8081ed0 100644 --- a/tests/settings.py +++ b/tests/settings.py @@ -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', + ], +}