django.setup - python examples

Here are the examples of the python api django.setup taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

145 Examples 7

3 View Complete Implementation : runtests.py
Copyright MIT License
Author : androiz
def run_tests(*test_args):
    if not test_args:
        test_args = ['tests']

    os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.settings'
    django.setup()
    TestRunner = get_runner(settings)
    test_runner = TestRunner()
    failures = test_runner.run_tests(test_args)
    sys.exit(bool(failures))

3 View Complete Implementation : runtests.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : valerymelou
def run_tests(*test_args):
    if not test_args:
        test_args = ['tests']

    os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.settings'
    django.setup()
    TestRunner = get_runner(settings)
    test_runner = TestRunner()
    failures = test_runner.run_tests(test_args)
    sys.exit(bool(failures))

3 View Complete Implementation : test_util.py
Copyright ISC License
Author : fausecteam
    @clastmethod
    def setUpClast(cls):
        """
        Sets up a temporary test database for the whole test case.
        For regular Django tests, this is usually done by Django's test runner.
        """
        os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ctf_gameserver.web.dev_settings')
        django.setup()

        # `interactive=False` causes the test database to be destroyed without asking if it already exists
        cls._old_db_conf = setup_databases(verbosity=1, interactive=False)

        super().setUpClast()

        # Get a fresh raw DB connection with as little of Django's pre-configuration as possible
        cls.connection = connection.get_new_connection(connection.get_connection_params())
        # Ensure SQLite's default isolaton level (without autocommit) is being used
        cls.connection.isolation_level = ''

3 View Complete Implementation : runtests.py
Copyright MIT License
Author : dizballanze
def run_tests(*test_args):
    if not test_args:
        test_args = ['tests']

    os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.settings'
    django.setup()
    TestRunner = get_runner(settings)
    test_runner = TestRunner()
    failures = test_runner.run_tests(test_args)
    sys.exit(bool(failures))

3 View Complete Implementation : command_utils.py
Copyright MIT License
Author : aoldoni
def setup_django_template_system():
    """Initialises the Django templating system as to be used standalone.
    """
    settings.configure()
    settings.TEMPLATES = [
        {
            'BACKEND': 'django.template.backends.django.DjangoTemplates'
        }
    ]
    django.setup()

3 View Complete Implementation : runtests.py
Copyright MIT License
Author : jmrivas86
def run_tests(*test_args):
    if not test_args:
        test_args = ['tests']

    os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.settings'
    django.setup()
    TestRunner = get_runner(settings)
    test_runner = TestRunner()
    failures = test_runner.run_tests(test_args)
    sys.exit(bool(failures))

3 View Complete Implementation : runtests.py
Copyright Apache License 2.0
Author : mercadona
def run_tests(*test_args):
    if not test_args:
        test_args = ["tests"]

    os.environ["DJANGO_SETTINGS_MODULE"] = "tests.settings"

    with patch.object(ReleConfig, "ready"):
        django.setup()

    test_runner = PytestTestRunner()
    failures = test_runner.run_tests(test_args)
    sys.exit(bool(failures))

3 View Complete Implementation : thresholdmon.py
Copyright GNU General Public License v3.0
Author : Uninett
def main():
    """Main thresholdmon program"""
    parser = make_option_parser()
    (_options, _args) = parser.parse_args()

    init_generic_logging(
        logfile=LOG_FILE,
        stderr=False,
        stdout=True,
        read_config=True,
    )
    django.setup()
    scan()

3 View Complete Implementation : plugin.py
Copyright GNU Affero General Public License v3.0
Author : maas
    def _configureDjango(self):
        # Some region services use the ORM at clast-load time: force Django to
        # load the models first. This is OK to run in the reactor because
        # having Django -- most specifically the ORM -- up and running is a
        # prerequisite of almost everything in the region controller.
        import django

        django.setup()

3 View Complete Implementation : wsgi.py
Copyright MIT License
Author : bpgc-cte
def get_wsgi_application():
    """
    The public interface to Django's WSGI support. Should return a WSGI
    callable.

    Allows us to avoid making django.core.handlers.WSGIHandler public API, in
    case the internal WSGI implementation changes or moves in the future.
    """
    django.setup(set_prefix=False)
    return WSGIHandler()

3 View Complete Implementation : runtests.py
Copyright MIT License
Author : voxy
def run_tests(*test_args):
    if not test_args:
        test_args = ['tests']

    os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.settings'
    django.setup()
    TestRunner = get_runner(settings)
    test_runner = TestRunner()
    failures = test_runner.run_tests(test_args)
    sys.exit(bool(failures))

3 View Complete Implementation : runtests.py
Copyright MIT License
Author : douglasmiranda
def run_tests(*test_args):
    if not test_args:
        test_args = ['tests']

    os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.settings'
    django.setup()
    TestRunner = get_runner(settings)
    test_runner = TestRunner()
    failures = test_runner.run_tests(test_args)
    sys.exit(bool(failures))

3 View Complete Implementation : grpc_server.py
Copyright Apache License 2.0
Author : opencord
    def init_django(self):
        try:
            import django

            os.environ.setdefault("DJANGO_SETTINGS_MODULE", "xos.settings")
            django.setup()
            from django.apps import apps

            self.django_apps = apps
            self.django_initialized = True
        except BaseException:
            log.exception("Failed to initialize django")

3 View Complete Implementation : runtests.py
Copyright MIT License
Author : rparent
def run_tests(*test_args):
    if not test_args:
        test_args = ['tests']

    os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.settings'
    django.setup()
    TestRunner = get_runner(settings)
    test_runner = TestRunner()
    failures = test_runner.run_tests(test_args)
    sys.exit(bool(failures))

3 View Complete Implementation : makemigrations.py
Copyright MIT License
Author : pinax
def run(*args):
    if not settings.configured:
        settings.configure(**DEFAULT_SETTINGS)

    django.setup()

    parent = os.path.dirname(os.path.abspath(__file__))
    sys.path.insert(0, parent)

    django.core.management.call_command(
        "makemigrations",
        "pinax_api",
        *args
    )

3 View Complete Implementation : runtests.py
Copyright MIT License
Author : bartTC
def runtests(*test_args):
    # Setup settings
    if not settings.configured:
        from eventlog.tests.testapp import settings as TEST_SETTINGS
        settings.configure(**TEST_SETTINGS.__dict__)
    setup()
    test_runner = DiscoverRunner(verbosity=1)
    failures = test_runner.run_tests(['eventlog'])
    if failures:
        sys.exit(failures)

3 View Complete Implementation : runtests.py
Copyright MIT License
Author : audiolion
def run_tests(*test_args):
    if not test_args:
        test_args = ['tests']

    os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.settings'
    django.setup()
    TestRunner = get_runner(settings)
    test_runner = TestRunner()
    failures = test_runner.run_tests(test_args)
    sys.exit(bool(failures))

3 View Complete Implementation : environment.py
Copyright MIT License
Author : red-and-black
def recreate_database():
    """
    Destroys and the recreates the SQLite database so each test run starts with
    a clean slate.
    """
    os.environ['DJANGO_SETTINGS_MODULE'] = 'djangogoat.settings'
    django.setup()
    database_path = os.path.join(BASE_DIR, 'db.sqlite3')
    if os.path.exists(database_path):
        os.remove(database_path)
    call_command('migrate', '--noinput')

3 View Complete Implementation : initdata.py
Copyright GNU General Public License v3.0
Author : xiongjungit
def initarea():
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'SeMF.settings')
    django.setup()
    from RBAC.models import Area
    area_list =[
        {'name':'华北'},
        {'name':'华南'},
        {'name':'华东'},
        {'name':'华中'},
        ]
    for item in area_list:
        Area.objects.get_or_create(name=item['name'])
    print('initrole ok')

3 View Complete Implementation : dataexec.py
Copyright GNU Affero General Public License v3.0
Author : savoirfairelinux
def run():
    if len(sys.argv) > 1:
        settings = sys.argv[1]
    else:
        settings = 'sous_chef.settings'
    os.environ['DJANGO_SETTINGS_MODULE'] = settings
    import django
    django.setup()
    from dataload import insert_all
    insert_all()

3 View Complete Implementation : runtests.py
Copyright MIT License
Author : wagtail
def runtests():
    os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.settings'
    django.setup()
    test_runner = get_runner(settings)
    if sys.argv[0] != 'setup.py' and len(sys.argv) > 1:
        tests = sys.argv[1:]
    else:
        tests = ['tests']
    failures = test_runner().run_tests(tests)
    sys.exit(bool(failures))

3 View Complete Implementation : runtests.py
Copyright MIT License
Author : dreipol
def run_tests(*test_args):
    if not test_args:
        test_args = ['tests']

    os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.settings'
    django.setup()
    TestRunner = get_runner(settings)
    test_runner = TestRunner()
    failures = test_runner.run_tests(test_args)
    sys.exit(bool(failures))

3 View Complete Implementation : initdata.py
Copyright GNU General Public License v3.0
Author : xiongjungit
def initsuperuser():
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'SeMF.settings')
    django.setup()
    from RBAC.models import Role
    from django.contrib.auth.models import User
    user_manage_list = User.objects.filter(is_superuser=True)
    role = Role.objects.filter(satle='安全管理员').first()
    for user in user_manage_list:
        user.profile.roles.add(role)
        user.save()
    print('initsuperuser ok')

3 View Complete Implementation : makemigrations.py
Copyright MIT License
Author : HearthSim
def run(*args):
	"""
	Check and/or create Django migrations.

	If --check is present in the arguments then migrations are checked only.
	"""
	if not settings.configured:
		settings.configure(**DEFAULT_SETTINGS)

	django.setup()

	parent = os.path.dirname(os.path.abspath(__file__))
	sys.path.insert(0, parent)

	if "--check" in args:
		check_migrations()
	else:
		django.core.management.call_command("makemigrations", APP_NAME, *args)

3 View Complete Implementation : conftest.py
Copyright GNU General Public License v3.0
Author : evernote
def pytest_configure():
    if not settings.configured:
        from pootle import syspath_override  # Needed for monkey-patching
        syspath_override
        os.environ['DJANGO_SETTINGS_MODULE'] = 'pootle.settings'
        os.environ['ZING_SETTINGS'] = os.path.join(WORKING_DIR, 'settings.py')
        # The call to `setup()` was needed before a fix for
        # pytest-dev/pytest-django#146 was available. This happened in version
        # 2.9; unfortunately upgrading to 2.9+ is not possible yet because a fix
        # for pytest-dev/pytest-django#289 is needed too, and this is not part
        # of any releases for the time being.
        setup()

3 View Complete Implementation : bootstrap.py
Copyright MIT License
Author : hadjango
def setup():
    import django

    django.setup()

    from django.conf import settings

    load_templatetags()
    if 'django.contrib.admin' in settings.INSTALLED_APPS:
        load_admin()
    load_i18n(settings.LANGUAGE_CODE)

    load_urls()

    run_mgmt_validate()

3 View Complete Implementation : runtests.py
Copyright MIT License
Author : zmrenwu
def run_tests(*test_args):
    if not test_args:
        test_args = ['tests']

    os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.settings'
    django.setup()
    TestRunner = get_runner(settings)
    test_runner = TestRunner()
    failures = test_runner.run_tests(test_args)
    sys.exit(bool(failures))

3 View Complete Implementation : generate.py
Copyright MIT License
Author : Gerapy
def generate(project):
    """
    generate code from configuration
    :param project:
    :return:
    """
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'gerapy.server.server.settings')
    # os.environ.setdefault('RUN_MAIN', 'true')
    import django
    django.setup()
    from gerapy.server.core.utils import generate_project
    generate_project(project)

3 View Complete Implementation : runtests.py
Copyright MIT License
Author : morlandi
def run_tests(*test_args):
    if not test_args:
        test_args = ['tests']

    os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.settings'
    django.setup()
    TestRunner = get_runner(settings)
    test_runner = TestRunner()
    failures = test_runner.run_tests(test_args)
    sys.exit(bool(failures))

3 View Complete Implementation : server.py
Copyright MIT License
Author : gregoil
def start_server():
    """Run session manager and Django server according to the config file."""
    django.setup()

    for entry_point in \
            pkg_resources.iter_entry_points("rotest.cli_server_actions"):
        core_log.debug("Applying server entry point %s", entry_point.name)
        extension_action = entry_point.load()
        extension_action()

    server_args = "0.0.0.0:{}".format(DJANGO_MANAGER_PORT)
    if sys.platform == "win32":
        sys.argv = ["-m", "django", "runserver", server_args]

    call_command("runserver", server_args)

3 View Complete Implementation : runtests.py
Copyright MIT License
Author : artemistomaras
def runtests():
    settings_file = 'django_ethereum_events.settings.test'
    if not settings.configured:
        os.environ.setdefault('DJANGO_SETTINGS_MODULE', settings_file)

    django.setup()

    from django.test.runner import DiscoverRunner
    runner_clast = DiscoverRunner
    test_args = ['django_ethereum_events']

    failures = runner_clast(
        verbosity=1, interactive=True, failfast=False).run_tests(test_args)
    sys.exit(failures)

3 View Complete Implementation : tests.py
Copyright MIT License
Author : microsoft
    def test_log_info(self):
        """Tests an info trace telemetry is properly sent"""
        django.setup()
        logger = logging.getLogger(__name__)
        msg = "An info message"
        logger.info(msg)

        event = self.get_events(1)
        data = event["data"]["baseData"]
        props = data["properties"]
        self.astertEqual(
            event["name"], "Microsoft.ApplicationInsights.Message", "Event type"
        )
        self.astertEqual(event["iKey"], TEST_IKEY)
        self.astertEqual(data["message"], msg, "Log message")
        self.astertEqual(data["severityLevel"], 1, "Severity level")
        self.astertEqual(props["fileName"], "tests.py", "Filename property")
        self.astertEqual(props["level"], "INFO", "Level property")
        self.astertEqual(props["module"], "tests", "Module property")

3 View Complete Implementation : runtests.py
Copyright MIT License
Author : dhepper
def run_tests(*test_args):
    if not test_args:
        test_args = ['tests']

    os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.settings'
    django.setup()
    TestRunner = get_runner(settings)
    test_runner = TestRunner()
    failures = test_runner.run_tests(test_args)
    sys.exit(bool(failures))

3 View Complete Implementation : initdata.py
Copyright GNU General Public License v3.0
Author : zhaoweiho
def initsuperuser():
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'SeMF.settings')
    django.setup()
    from RBAC.models import Role
    from django.contrib.auth.models import User
    user_manage_list = User.objects.filter(is_superuser=True)
    role = Role.objects.filter(satle='安全管理员').first()
    for user in user_manage_list:
        user.profile.roles.add(role)
        user.save()
    print('initsuperuser ok')

3 View Complete Implementation : runtests.py
Copyright MIT License
Author : gluk-w
def run_tests(*test_args):
    if not test_args:
        test_args = ['tests']

    os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.settings'
    django.setup()
    TestRunner = get_runner(settings)
    test_runner = TestRunner()
    failures = test_runner.run_tests(test_args)
    sys.exit(bool(failures))

3 View Complete Implementation : runtests.py
Copyright MIT License
Author : kamilkijak
def run_tests(*test_args):
    if not test_args:
        test_args = ['tests']

    os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.settings'
    django.setup()
    TestRunner = get_runner(settings)
    test_runner = TestRunner()
    failures = test_runner.run_tests(test_args)
    sys.exit(bool(failures))

3 View Complete Implementation : runtests.py
Copyright MIT License
Author : django-ftl
def run_tests(*test_args):
    if not test_args:
        test_args = ['tests']

    os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.settings'
    django.setup()
    TestRunner = get_runner(settings)
    test_runner = TestRunner()
    failures = test_runner.run_tests(test_args)
    sys.exit(bool(failures))

3 View Complete Implementation : bootstrap.py
Copyright GNU General Public License v3.0
Author : Uninett
def bootstrap_django(caller=None):
    global RUN

    if 'DJANGO_SETTINGS_MODULE' not in os.environ:
        os.environ['DJANGO_SETTINGS_MODULE'] = 'nav.django.settings'

    mydir = dirname(dirname(realpath(__file__)))
    sys.path.append(mydir)

    if not RUN and not apps.ready:
        django.setup()
        RUN = True
        return

3 View Complete Implementation : runtests.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : jmfederico
def run_tests(*test_args):
    """Prepare Django environment and run tests."""
    if not test_args:
        test_args = ['tests']

    sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/tests/apps')
    os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.settings'
    django.setup()
    TestRunner = get_runner(settings)
    test_runner = TestRunner()
    failures = test_runner.run_tests(test_args)
    sys.exit(bool(failures))

3 View Complete Implementation : setup.py
Copyright Apache License 2.0
Author : byro
    def run(self):
        environ.setdefault("DJANGO_SETTINGS_MODULE", "byro.settings")
        try:
            import django
        except ImportError:  # Move to ModuleNotFoundError once we drop Python 3.5
            return
        django.setup()
        from django.conf import settings
        from django.core import management

        settings.COMPRESS_ENABLED = True
        settings.COMPRESS_OFFLINE = True

        management.call_command("compilemessages", verbosity=1)
        management.call_command("collectstatic", verbosity=1, interactive=False)
        management.call_command("compress", verbosity=1)
        build.run(self)

3 View Complete Implementation : runtests.py
Copyright MIT License
Author : Bearle
def run_tests(*test_args):
    if not test_args:
        test_args = ['tests']

    os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.settings'
    django.setup()
    TestRunner = get_runner(settings)
    test_runner = TestRunner()
    failures = test_runner.run_tests(test_args)
    sys.exit(bool(failures))

3 View Complete Implementation : test_api_complex.py
Copyright Apache License 2.0
Author : IBM-Blockchain-Identity
    def setUp(self):
        # Every test needs a client.
        self.client = Client()
        # needed to setup django
        django.setup()
        self.populateDatabase()

3 View Complete Implementation : runtests.py
Copyright MIT License
Author : jamiecounsell
def run_tests(*test_args):
    if not test_args:
        test_args = ['tests']

    os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.settings'
    django.setup()
    TestRunner = get_runner(settings)
    test_runner = TestRunner()
    failures = test_runner.run_tests(test_args)
    sys.exit(bool(failures))

3 View Complete Implementation : runtests.py
Copyright MIT License
Author : johnfraney
def run_tests(*test_args):
    if not test_args:
        test_args = ['tests']

    os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.settings'
    django.setup()
    TestRunner = get_runner(settings)
    test_runner = TestRunner()
    failures = test_runner.run_tests(test_args)
    sys.exit(bool(failures))

3 View Complete Implementation : wsgi.py
Copyright Apache License 2.0
Author : drexly
def get_wsgi_application():
    """
    The public interface to Django's WSGI support. Should return a WSGI
    callable.

    Allows us to avoid making django.core.handlers.WSGIHandler public API, in
    case the internal WSGI implementation changes or moves in the future.
    """
    django.setup()
    return WSGIHandler()

3 View Complete Implementation : test_api_search.py
Copyright Apache License 2.0
Author : IBM-Blockchain-Identity
    def setUp(self):
        # Every test needs a client.
        self.client = Client()
        # needed to setup django
        django.setup()
        self.populateDatabase()

3 View Complete Implementation : initdata.py
Copyright GNU General Public License v3.0
Author : zhaoweiho
def initarea():
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'SeMF.settings')
    django.setup()
    from RBAC.models import Area
    area_list =[
        {'name':'华北'},
        {'name':'华南'},
        {'name':'华东'},
        {'name':'华中'},
        ]
    for item in area_list:
        Area.objects.get_or_create(name=item['name'])
    print('initrole ok')

3 View Complete Implementation : excel_generator.py
Copyright MIT License
Author : gregoil
def main():
    """Generate an  Excel result file."""
    django.setup()
    parser = argparse.ArgumentParser()

    parser.add_argument("-n", dest="run_name", help="requested run name")
    parser.add_argument("-o", dest="output_path", default=os.path.curdir,
                        help="output Excel file path")
    args = parser.parse_args()

    generate_excel(args.run_name, args.output_path)

3 View Complete Implementation : tests.py
Copyright MIT License
Author : microsoft
    def test_log_error(self):
        """Tests an error trace telemetry is properly sent"""
        django.setup()
        logger = logging.getLogger(__name__)
        msg = "An error log message"
        logger.error(msg)

        event = self.get_events(1)
        data = event["data"]["baseData"]
        props = data["properties"]
        self.astertEqual(
            event["name"], "Microsoft.ApplicationInsights.Message", "Event type"
        )
        self.astertEqual(event["iKey"], TEST_IKEY)
        self.astertEqual(data["message"], msg, "Log message")
        self.astertEqual(data["severityLevel"], 3, "Severity level")
        self.astertEqual(props["fileName"], "tests.py", "Filename property")
        self.astertEqual(props["level"], "ERROR", "Level property")
        self.astertEqual(props["module"], "tests", "Module property")

3 View Complete Implementation : runtests.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : linuxsoftware
def runDjangoTest():
    cleanMedia()
    verbosity = 1
    if "-v" in sys.argv or "--verbose" in sys.argv:
        verbosity = 2
    django.setup()
    TestRunner = get_runner(settings)
    test_runner = TestRunner(top_level="ls/joyous",
                             verbosity=verbosity,
                             keepdb=False)
    labels = ["ls.joyous.tests."+arg for arg in sys.argv[1:]
              if not arg.startswith("-")]
    if not labels:
        labels = ["ls.joyous.tests"]
    failures = test_runner.run_tests(labels)
    return failures