def test_unavailable_site_model(self): """ #24075 - A Site shouldn't be created if the model isn't available. """ apps = Apps() create_default_site(self.app_config, verbosity=0, apps=apps) self.assertFalse(Site.objects.exists())
def test_no_site_id(self): """ #24488 - The pk should default to 1 if no ``SITE_ID`` is configured. """ del settings.SITE_ID create_default_site(self.app_config, verbosity=0) self.assertEqual(Site.objects.get().pk, 1)
def test_multi_db_with_router(self): """ #16353, #16828 - The default site creation should respect db routing. """ create_default_site(self.app_config, using='default', verbosity=0) create_default_site(self.app_config, using='other', verbosity=0) self.assertFalse(Site.objects.using('default').exists()) self.assertTrue(Site.objects.using('other').exists())
def test_save_another(self): """ #17415 - Another site can be created right after the default one. On some backends the sequence needs to be reset after saving with an explicit ID. There shouldn't be a sequence collisions by saving another site. This test is only meaningful with databases that use sequences for automatic primary keys such as PostgreSQL and Oracle. """ create_default_site(self.app_config, verbosity=0) Site(domain='example2.com', name='example2.com').save()
def test_basic(self): """ #15346, #15573 - create_default_site() creates an example site only if none exist. """ with captured_stdout() as stdout: create_default_site(self.app_config) self.assertEqual(Site.objects.count(), 1) self.assertIn("Creating example.com", stdout.getvalue()) with captured_stdout() as stdout: create_default_site(self.app_config) self.assertEqual(Site.objects.count(), 1) self.assertEqual("", stdout.getvalue())
def init_siteconfig(app, created_models, verbosity, db=None, **kwargs): """Initialize the site configuration. This will create a SiteConfiguration object if one does not exist, or update the existing one with the current version number. """ try: site = Site.objects.get_current() except Site.DoesNotExist: # This is an initial syncdb and we got called before Site's post_syncdb # handler did, so invoke it directly. from django.contrib.sites.management import create_default_site create_default_site(app, created_models, verbosity, db=db) site = Site.objects.get_current() siteconfig, is_new = SiteConfiguration.objects.get_or_create(site=site) new_version = get_version_string() if is_new: # Check the Site to see if this is a brand new installation. If so, # don't talk to the user about upgrades or other such nonsense. if Site not in created_models: print("*** Migrating settings from settings_local.py to the " "database.") migrate_settings(siteconfig) if Site not in created_models: print("*** If you have previously configured Review Board " "through a ") print("*** settings_local.py file, please ensure that the " "migration ") print("*** was successful by verifying your settings at") print("*** %s://%s%sadmin/settings/" % (siteconfig.get("site_domain_method"), site.domain, settings.SITE_ROOT)) siteconfig.version = new_version siteconfig.save() elif siteconfig.version != new_version: print("Upgrading Review Board from %s to %s" % (siteconfig.version, new_version)) siteconfig.version = new_version siteconfig.save()
def test_custom_site_id(self): """ #23945 - The configured ``SITE_ID`` should be respected. """ create_default_site(self.app_config, verbosity=0) self.assertEqual(Site.objects.get().pk, 35696)
def test_multi_db(self): create_default_site(self.app_config, using='default', verbosity=0) create_default_site(self.app_config, using='other', verbosity=0) self.assertTrue(Site.objects.using('default').exists()) self.assertTrue(Site.objects.using('other').exists())
def test_multi_db(self): create_default_site(self.app_config, using="default", verbosity=0) create_default_site(self.app_config, using="other", verbosity=0) self.assertTrue(Site.objects.using("default").exists()) self.assertTrue(Site.objects.using("other").exists())
def _fixture_setup(self): super(AskbotTestCase, self)._fixture_setup() for app_config in apps.get_app_configs(): update_contenttypes(app_config) create_permissions(app_config) create_default_site(app_config)
def test_multi_db(self): create_default_site(self.app_config, using='default', verbosity=0) create_default_site(self.app_config, using='other', verbosity=0) self.assertTrue(Site.objects.using('default').exists()) self.assertTrue(Site.objects.using('other').exists())
def test_custom_site_id(self): """ #23945 - The configured ``SITE_ID`` should be respected. """ create_default_site(self.app_config, verbosity=0) self.assertEqual(Site.objects.get().pk, 35696)
def _fixture_setup(self): super(AskbotTestCase, self)._fixture_setup() for app_config in apps.get_app_configs(): update_contenttypes(app_config) create_permissions(app_config) create_default_site(app_config)
def sites_patch_django17(apps, schema_editor): if django.VERSION[:2] == (1,7): from django.contrib.sites.management import create_default_site from django.apps import apps create_default_site(apps.get_app_configs()[0])