def test_get_site_creates_routing_settings_if_none_exist(root_page, django_assert_num_queries): page = InternationalArticlePageFactory(parent=root_page, slug='industry') site = Site.objects.create(hostname='example.gov', root_page=page) # running this first so that the query doesn't count toward # the total query count (the value is usually cached) page._get_site_root_paths() with django_assert_num_queries(2): # 1 query to get the site, 1 to create routing settings result_site = page.get_site() # Check the correct site was returned assert result_site == site # This attribute is set to reference the newly created object, # so this shouldn't result in another query result_site.routingsettings
def test_get_site_returns_none_when_page_not_routable(root_page): Site.objects.all().delete() # ensures pages are not routable page = InternationalArticlePageFactory(parent=root_page, slug='industry') result = page.get_site() assert result is None