Upgrade to Django 4.2 (#3497)

This commit is contained in:
Raphael Michel
2023-08-09 14:47:41 +02:00
committed by GitHub
parent 0853296663
commit b51c9f7552
12 changed files with 76 additions and 52 deletions

View File

@@ -940,8 +940,8 @@ def test_rules_reasoning_prefer_number_over_date(event, position, clist):
@pytest.mark.django_db(transaction=True)
def test_position_queries(django_assert_num_queries, position, clist):
with django_assert_num_queries(12 if 'sqlite' in settings.DATABASES['default']['ENGINE'] else 11) as captured:
def test_position_queries(django_assert_max_num_queries, position, clist):
with django_assert_max_num_queries(13) as captured:
perform_checkin(position, clist, {})
if 'sqlite' not in settings.DATABASES['default']['ENGINE']:
assert any('FOR UPDATE' in s['sql'] for s in captured)

View File

@@ -38,10 +38,10 @@ class I18nStringTest(TestCase):
'en': 'Hello'
}
s = LazyI18nString(data)
translation.activate('en')
self.assertEqual(str(s), 'Hello')
translation.activate('de')
self.assertEqual(str(s), 'Hallo')
with translation.override('en'):
self.assertEqual(str(s), 'Hello')
with translation.override('de'):
self.assertEqual(str(s), 'Hallo')
def test_similar_translations(self):
data = {
@@ -50,57 +50,57 @@ class I18nStringTest(TestCase):
'de-informal': 'Du'
}
s = LazyI18nString(data)
translation.activate('de')
self.assertEqual(str(s), 'Sie')
translation.activate('de-informal')
self.assertEqual(str(s), 'Du')
with translation.override('de'):
self.assertEqual(str(s), 'Sie')
with translation.override('de-informal'):
self.assertEqual(str(s), 'Du')
data = {
'en': 'You',
'de-informal': 'Du'
}
s = LazyI18nString(data)
translation.activate('de')
self.assertEqual(str(s), 'Du')
translation.activate('de-informal')
self.assertEqual(str(s), 'Du')
with translation.override('de'):
self.assertEqual(str(s), 'Du')
with translation.override('de-informal'):
self.assertEqual(str(s), 'Du')
data = {
'en': 'You',
'de': 'Sie'
}
s = LazyI18nString(data)
translation.activate('de')
self.assertEqual(str(s), 'Sie')
translation.activate('de-informal')
self.assertEqual(str(s), 'Sie')
with translation.override('de'):
self.assertEqual(str(s), 'Sie')
with translation.override('de-informal'):
self.assertEqual(str(s), 'Sie')
def test_missing_default_translation(self):
data = {
'de': 'Hallo',
}
s = LazyI18nString(data)
translation.activate('en')
self.assertEqual(str(s), 'Hallo')
translation.activate('de')
self.assertEqual(str(s), 'Hallo')
with translation.override('en'):
self.assertEqual(str(s), 'Hallo')
with translation.override('de'):
self.assertEqual(str(s), 'Hallo')
def test_missing_translation(self):
data = {
'en': 'Hello',
}
s = LazyI18nString(data)
translation.activate('en')
self.assertEqual(str(s), 'Hello')
translation.activate('de')
self.assertEqual(str(s), 'Hello')
with translation.override('en'):
self.assertEqual(str(s), 'Hello')
with translation.override('de'):
self.assertEqual(str(s), 'Hello')
def test_legacy_string(self):
s = LazyI18nString("Hello")
translation.activate('en')
self.assertEqual(str(s), 'Hello')
translation.activate('de')
self.assertEqual(str(s), 'Hello')
with translation.override('en'):
self.assertEqual(str(s), 'Hello')
with translation.override('de'):
self.assertEqual(str(s), 'Hello')
def test_none(self):
s = LazyI18nString(None)
@@ -124,10 +124,10 @@ class I18nFieldTest(TestCase):
obj = ItemCategory.objects.create(event=self.event, name="Hello")
obj = ItemCategory.objects.get(id=obj.id)
self.assertIsInstance(obj.name, LazyI18nString)
translation.activate('en')
self.assertEqual(str(obj.name), "Hello")
translation.activate('de')
self.assertEqual(str(obj.name), "Hello")
with translation.override('en'):
self.assertEqual(str(obj.name), "Hello")
with translation.override('de'):
self.assertEqual(str(obj.name), "Hello")
def test_save_load_cycle_i18n_string(self):
obj = ItemCategory.objects.create(event=self.event,
@@ -139,7 +139,7 @@ class I18nFieldTest(TestCase):
))
obj = ItemCategory.objects.get(id=obj.id)
self.assertIsInstance(obj.name, LazyI18nString)
translation.activate('en')
self.assertEqual(str(obj.name), "Hello")
translation.activate('de')
self.assertEqual(str(obj.name), "Hallo")
with translation.override('en'):
self.assertEqual(str(obj.name), "Hello")
with translation.override('de'):
self.assertEqual(str(obj.name), "Hallo")

View File

@@ -22,6 +22,7 @@
import inspect
import pytest
from django.utils import translation
from django_scopes import scopes_disabled
from xdist.dsession import DSession
@@ -68,3 +69,8 @@ def pytest_fixture_setup(fixturedef, request):
else:
with scopes_disabled():
yield
@pytest.fixture(autouse=True)
def reset_locale():
translation.activate("en")