Fix queryset ordering and add a test to confirm ordering matches expectation in all setups

pull/4633/merge
Andy Babic 2018-06-17 22:51:26 +01:00 zatwierdzone przez Loic Teixeira
rodzic 4539ced8cc
commit 5151c5cff2
4 zmienionych plików z 30 dodań i 1 usunięć

Wyświetl plik

@ -19,6 +19,7 @@ Changelog
* Fix: Handle all exceptions from `Image.get_file_size` (Andrew Plummer)
* Fix: Fix display of breadcrumbs in ModelAdmin (LB (Ben Johnston))
* Fix: Remove duplicate border radius of avatars (Benjamin Thurm)
* Fix: Site.get_site_root_paths() preferring other sites over the default when some sites share the same root_page (Andy Babic)
2.1 (22.05.2018)

Wyświetl plik

@ -32,6 +32,7 @@ Bug fixes
* Handle all exceptions from ``Image.get_file_size`` (Andrew Plummer)
* Fix display of breadcrumbs in ModelAdmin (LB (Ben Johnston))
* Remove duplicate border radius of avatars (Benjamin Thurm)
* Site.get_site_root_paths() preferring other sites over the default when some sites share the same root_page (Andy Babic)
Upgrade considerations
======================

Wyświetl plik

@ -161,7 +161,7 @@ class Site(models.Model):
result = [
(site.id, site.root_page.url_path, site.root_url)
for site in Site.objects.select_related('root_page').order_by(
'-root_page__url_path', 'is_default_site', 'hostname')
'-root_page__url_path', '-is_default_site', 'hostname')
]
cache.set('wagtail_site_root_paths', result, 3600)

Wyświetl plik

@ -122,3 +122,30 @@ class TestDefaultSite(TestCase):
with self.assertRaises(Site.MultipleObjectsReturned):
# If there already are multiple default sites, you're in trouble
site.clean_fields()
class TestGetSiteRootPaths(TestCase):
def setUp(self):
self.default_site = Site.objects.get()
self.abc_site = Site.objects.create(
hostname='abc.com', root_page=self.default_site.root_page
)
self.def_site = Site.objects.create(
hostname='def.com', root_page=self.default_site.root_page
)
# Changing the hostname to show that being the default site takes
# promotes a site over the alphabetical ordering of hostname
self.default_site.hostname = 'xyz.com'
self.default_site.save()
def test_result_order_when_multiple_sites_share_the_same_root_page(self):
result = Site.get_site_root_paths()
# An entry for the default site should come first
self.assertEqual(result[0][0], self.default_site.id)
# Followed by entries for others in 'host' alphabetical order
self.assertEqual(result[1][0], self.abc_site.id)
self.assertEqual(result[2][0], self.def_site.id)