1from django.http import HttpRequest 2 3from wagtail.core.models import Page, Site 4from wagtail.tests.testapp.models import TestSetting 5 6 7class SettingsTestMixin: 8 9 def setUp(self): 10 root = Page.objects.first() 11 other_home = Page(title='Other Root') 12 root.add_child(instance=other_home) 13 14 self.default_site = Site.objects.get(is_default_site=True) 15 self.default_site_settings = TestSetting.objects.create( 16 title='Site title', 17 email='initial@example.com', 18 site=self.default_site) 19 20 self.other_site = Site.objects.create(hostname='other', root_page=other_home) 21 self.other_site_settings = TestSetting.objects.create( 22 title='Other title', 23 email='other@other.com', 24 site=self.other_site) 25 26 def get_request(self, site=None): 27 if site is None: 28 site = self.default_site 29 request = HttpRequest() 30 request.META['HTTP_HOST'] = site.hostname 31 request.META['SERVER_PORT'] = site.port 32 return request 33