Python django.conf.settings.configure() Examples

The following are 30 code examples of django.conf.settings.configure(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module django.conf.settings , or try the search function .
Example #1
Source File: quicktest.py    From django-classified with MIT License 6 votes vote down vote up
def _tests(self):
        settings.configure(
            DEBUG=True,
            DATABASES={
                'default': {
                    'ENGINE': 'django.db.backends.sqlite3',
                    'NAME': os.path.join(self.DIRNAME, 'database.db'),
                }
            },
            INSTALLED_APPS=self.INSTALLED_APPS + self.apps,
            MIDDLEWARE=self.MIDDLEWARE,
            ROOT_URLCONF='django_classified.tests.urls',
            STATIC_URL='/static/',
            TEMPLATES=self.TEMPLATES,
            SITE_ID=1
        )

        from django.test.runner import DiscoverRunner
        test_runner = DiscoverRunner()
        django.setup()

        failures = test_runner.run_tests(self.apps)
        if failures:
            sys.exit(failures) 
Example #2
Source File: runtests.py    From pwned-passwords-django with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def run_tests():
    # Making Django run this way is a two-step process. First, call
    # settings.configure() to give Django settings to work with:
    from django.conf import settings

    settings.configure(**SETTINGS_DICT)

    # Then, call django.setup() to initialize the application registry
    # and other bits:
    import django

    django.setup()

    # Now we instantiate a test runner...
    from django.test.utils import get_runner

    TestRunner = get_runner(settings)

    # And then we run tests and return the results.
    test_runner = TestRunner(verbosity=2, interactive=True)
    failures = test_runner.run_tests(["tests"])
    sys.exit(failures) 
Example #3
Source File: conftest.py    From django-elevate with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def pytest_configure(config):
    from django.conf import settings

    settings.configure(
        AUTHENTICATION_BACKENDS=[
            'tests.base.FooPasswordBackend',
            'tests.base.StubPasswordBackend',
        ],
        DEBUG=True,
        DATABASE_ENGINE='sqlite3',
        DATABASES={
            'default': {
                'NAME': ':memory:',
                'ENGINE': 'django.db.backends.sqlite3',
                'TEST_NAME': ':memory:',
            },
        },
        DATABASE_NAME=':memory:',
        TEST_DATABASE_NAME=':memory:',
        INSTALLED_APPS=INSTALLED_APPS,
        MIDDLEWARE_CLASSES=MIDDLEWARE_CLASSES,
        PASSWORD_HASHERS=['django.contrib.auth.hashers.MD5PasswordHasher'],
        ROOT_URLCONF='tests.urls',
    ) 
Example #4
Source File: runtests.py    From pinax-documents with MIT License 6 votes vote down vote up
def runtests(*test_args):
    if not settings.configured:
        settings.configure(**DEFAULT_SETTINGS)

    # Compatibility with Django 1.7's stricter initialization
    if hasattr(django, "setup"):
        django.setup()

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

    try:
        from django.test.runner import DiscoverRunner
        runner_class = DiscoverRunner
        test_args = ["pinax.documents.tests"]
    except ImportError:
        from django.test.simple import DjangoTestSuiteRunner
        runner_class = DjangoTestSuiteRunner
        test_args = ["tests"]

    failures = runner_class(verbosity=1, interactive=True, failfast=False).run_tests(test_args)
    sys.exit(failures) 
Example #5
Source File: runtests.py    From django-seed with MIT License 6 votes vote down vote up
def configure():
    from faker import Faker
    fake = Faker()

    settings.configure(
        DATABASES={
            'default': {
                'ENGINE': 'django.db.backends.sqlite3',
                'NAME': ':memory:',
            }
        },
        INSTALLED_APPS=(
            'django_seed',
            'django_nose',
        ),
        TEST_RUNNER = 'django_nose.NoseTestSuiteRunner',
        NOSE_ARGS = [
            '--with-coverage',
            '--cover-package=django_seed',
        ],
        SITE_ID=1,
        SECRET_KEY=fake.sha1(),
    ) 
Example #6
Source File: conftest.py    From django-rest-assured with BSD 2-Clause "Simplified" License 6 votes vote down vote up
def pytest_configure():
    settings.configure(
        ROOT_URLCONF='tests.urls',

        ALLOWED_HOSTS=['testserver'],

        DATABASES={
            'default': {
                'ENGINE': 'django.db.backends.sqlite3',
                'NAME': 'test_db'
            }
        },

        INSTALLED_APPS=[
            'django.contrib.auth',
            'django.contrib.contenttypes',
            'django.contrib.sessions',

            'rest_framework',
            'tests',
        ]
    ) 
Example #7
Source File: runtests.py    From pinax-teams with MIT License 6 votes vote down vote up
def runtests(*test_args):
    if not settings.configured:
        settings.configure(**DEFAULT_SETTINGS)

    django.setup()

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

    try:
        from django.test.runner import DiscoverRunner
        runner_class = DiscoverRunner
        test_args = ["pinax.teams.tests"]
    except ImportError:
        from django.test.simple import DjangoTestSuiteRunner
        runner_class = DjangoTestSuiteRunner
        test_args = ["tests"]

    failures = runner_class(
        verbosity=1, interactive=True, failfast=False).run_tests(test_args)
    sys.exit(failures) 
Example #8
Source File: setup.py    From django-calaccess-campaign-browser with MIT License 6 votes vote down vote up
def run(self):
        from django.conf import settings
        settings.configure(
            DATABASES={
                'default': {
                    'NAME': ':memory:',
                    'ENGINE': 'django.db.backends.sqlite3'
                }
            },
            INSTALLED_APPS=('calaccess_campaign_browser',),
            MIDDLEWARE_CLASSES=()
        )
        from django.core.management import call_command
        import django
        if django.VERSION[:2] >= (1, 7):
            django.setup()
        call_command('test', 'calaccess_campaign_browser') 
Example #9
Source File: conftest.py    From djangorestframework-expander with MIT License 6 votes vote down vote up
def pytest_configure():
    from django.conf import settings

    settings.configure(
        ROOT_URLCONF='tests.project.urls',
        SECRET_KEY='not so secret',
        DATABASES={
            'default': {
                'ENGINE': 'django.db.backends.sqlite3',
                'NAME': 'db.sqlite',
            }
        },
        INSTALLED_APPS=[
            'django.contrib.auth',
            'django.contrib.contenttypes',
            'rest_framework',
            'tests.project'
        ],
    ) 
Example #10
Source File: conftest.py    From django-session-timeout with MIT License 6 votes vote down vote up
def pytest_configure():
    settings.configure(
        INSTALLED_APPS=[
            "django.contrib.contenttypes",
            "django.contrib.auth",
            "django.contrib.sessions",
        ],
        MIDDLEWARE_CLASSES=[],
        ROOT_URLCONF="tests.urls",
        CACHES={
            "default": {
                "BACKEND": "django.core.cache.backends.locmem.LocMemCache",
                "LOCATION": "unique-snowflake",
            }
        },
        SESSION_ENGINE="django.contrib.sessions.backends.cache",
        DATABASES={
            "default": {"ENGINE": "django.db.backends.sqlite3", "NAME": "db.sqlite"}
        },
    ) 
Example #11
Source File: run_tests.py    From django-websocket-request with MIT License 6 votes vote down vote up
def main():
    settings.configure(
        ROOT_URLCONF='wsrequest.tests',
        INSTALLED_APPS=[
            'django.contrib.auth',
            'django.contrib.contenttypes',
            'django.contrib.sessions',
        ],
        DATABASES={
            'default': {
                'ENGINE': 'django.db.backends.sqlite3',
                'NAME':  'db.sqlite3',
            }
        }
    )

    from django.test.utils import get_runner

    test_runner = get_runner(settings)(verbosity=1, interactive=True)

    failures = test_runner.run_tests(['wsrequest.tests'])

    sys.exit(failures) 
Example #12
Source File: conftest.py    From django-cognito-jwt with MIT License 6 votes vote down vote up
def pytest_configure():
    settings.configure(
        COGNITO_AWS_REGION="eu-central-1",
        COGNITO_USER_POOL="bla",
        COGNITO_AUDIENCE="my-client-id",
        INSTALLED_APPS=["django.contrib.auth", "django.contrib.contenttypes"],
        MIDDLEWARE_CLASSES=[],
        CACHES={
            "default": {
                "BACKEND": "django.core.cache.backends.locmem.LocMemCache",
                "LOCATION": "unique-snowflake",
            }
        },
        DATABASES={
            "default": {"ENGINE": "django.db.backends.sqlite3", "NAME": "db.sqlite"}
        },
        ROOT_URLCONF="urls",
    ) 
Example #13
Source File: conf.py    From django-rest-framework-simplejwt with MIT License 6 votes vote down vote up
def django_configure():
    from django.conf import settings

    settings.configure(
        INSTALLED_APPS=(
            'django.contrib.admin',
            'django.contrib.auth',
            'django.contrib.contenttypes',
            'django.contrib.sessions',
            'django.contrib.sites',
            'django.contrib.staticfiles',

            'rest_framework',
            'rest_framework_simplejwt',
            'rest_framework_simplejwt.token_blacklist',
        ),
    )

    try:
        import django
        django.setup()
    except AttributeError:
        pass 
Example #14
Source File: conftest.py    From django-sudo with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def pytest_configure(config):
    from django.conf import settings

    settings.configure(
        AUTHENTICATION_BACKENDS=[
            "tests.base.FooPasswordBackend",
            "tests.base.StubPasswordBackend",
        ],
        DEBUG=True,
        DATABASE_ENGINE="sqlite3",
        DATABASES={
            "default": {
                "NAME": ":memory:",
                "ENGINE": "django.db.backends.sqlite3",
                "TEST_NAME": ":memory:",
            },
        },
        DATABASE_NAME=":memory:",
        TEST_DATABASE_NAME=":memory:",
        INSTALLED_APPS=INSTALLED_APPS,
        MIDDLEWARE_CLASSES=MIDDLEWARE_CLASSES,
        PASSWORD_HASHERS=["django.contrib.auth.hashers.MD5PasswordHasher"],
        ROOT_URLCONF="tests.urls",
    ) 
Example #15
Source File: test.py    From propublica-congress with MIT License 6 votes vote down vote up
def test_django_cache(self):
        try:
            from django.conf import settings
            settings.configure(CACHE_BACKEND = 'locmem://')
            from django.core.cache import cache
        except ImportError:
            # no Django, so nothing to test
            return
        
        congress = Congress(API_KEY, cache)
        
        self.assertEqual(congress.http.cache, cache)
        self.assertEqual(congress.members.http.cache, cache)
        self.assertEqual(congress.bills.http.cache, cache)
        self.assertEqual(congress.votes.http.cache, cache)
        
        try:
            bills = congress.bills.introduced('house')
        except Exception as e:
            self.fail(e) 
Example #16
Source File: runtests.py    From django-spillway with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def runtests():
    if not settings.configured:
        settings.configure(**DEFAULT_SETTINGS)
    django.setup()
    from spillway.models import upload_to
    os.mkdir(os.path.join(TMPDIR, upload_to.path))
    parent = os.path.dirname(os.path.abspath(__file__))
    sys.path.insert(0, parent)
    try:
        from django.test.runner import DiscoverRunner
        runner_class = DiscoverRunner
    except ImportError:
        from django.test.simple import DjangoTestSuiteRunner
        runner_class = DjangoTestSuiteRunner
    try:
        status = runner_class(
            verbosity=1, interactive=True, failfast=False).run_tests(['tests'])
    except Exception:
        traceback.print_exc()
        status = 1
    finally:
        teardown()
    sys.exit(status) 
Example #17
Source File: runtests.py    From django-subscriptions with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def run_tests():
    # First configure settings, then call django.setup() to initialise
    from django.conf import settings

    settings.configure(**SETTINGS_DICT)
    import django

    django.setup()

    # Now create the test runner
    from django.test.utils import get_runner

    TestRunner = get_runner(settings)

    # And then we run tests and return the results.
    test_runner = TestRunner(verbosity=2, interactive=True)
    failures = test_runner.run_tests(["tests"])
    sys.exit(failures) 
Example #18
Source File: runtests.py    From pinax-forums with MIT License 6 votes vote down vote up
def runtests(*test_args):
    if not settings.configured:
        settings.configure(**DEFAULT_SETTINGS)

    django.setup()

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

    try:
        from django.test.runner import DiscoverRunner
        runner_class = DiscoverRunner
        if not test_args:
            test_args = ["pinax.forums.tests"]
    except ImportError:
        from django.test.simple import DjangoTestSuiteRunner
        runner_class = DjangoTestSuiteRunner
        test_args = ["tests"]

    failures = runner_class(verbosity=1, interactive=True, failfast=False).run_tests(test_args)
    sys.exit(failures) 
Example #19
Source File: conftest.py    From django-webdav-storage with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def pytest_configure():
    from django.conf import settings

    WEBDAV_URL = os.getenv('WEBDAV_URL', 'http://127.0.0.1:8080/')
    WEBDAV_PUBLIC_URL = os.getenv('WEBDAV_PUBLIC_URL',
                                  'http://127.0.0.1:8080/')
    WEBDAV_LISTING_BACKEND = os.getenv('WEBDAV_LISTING_BACKEND')

    settings.configure(
        INSTALLED_APPS=['django_webdav_storage'],
        MIDDLEWARE_CLASSES=['django.middleware.common.CommonMiddleware'],
        MIDDLEWARES=['django.middleware.common.CommonMiddleware'],
        DATABASES={
            'default': {
                'ENGINE': 'django.db.backends.sqlite3',
                'NAME': ':MEMORY:'
            }
        },
        WEBDAV_URL=WEBDAV_URL,
        WEBDAV_PUBLIC_URL=WEBDAV_PUBLIC_URL,
        WEBDAV_RECURSIVE_MKCOL=True,
        WEBDAV_LISTING_BACKEND=WEBDAV_LISTING_BACKEND
    ) 
Example #20
Source File: conftest.py    From django-taggit-labels with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def pytest_configure():
    from django.conf import settings

    settings.configure(
        DEBUG=True,
        USE_TZ=True,
        DATABASES={
            "default": {"ENGINE": "django.db.backends.sqlite3", "NAME": "test.sqlite3"}
        },
        INSTALLED_APPS=[
            "django.contrib.auth",
            "django.contrib.contenttypes",
            # "django.contrib.sites",
            "taggit",
            "taggit_labels",
            "test_app",
        ],
        MIDDLEWARE_CLASSES=(),
        SITE_ID=1,
    )
    try:
        django.setup()
    except AttributeError:
        # Django 1.7 or lower
        pass 
Example #21
Source File: conf.py    From django-ftpserver with MIT License 6 votes vote down vote up
def setup_django():
    import django
    from django.conf import settings
    if not settings.configured:
        settings.configure(
            DEBUG=True,
            DATABASES={
                'default': {
                    'ENGINE': 'django.db.backends.sqlite3',
                    'NAME': ':memory:',
                }
            },
            INSTALLED_APPS=(
                'django.contrib.admin',
                'django.contrib.auth',
                'django.contrib.contenttypes',
                'django.contrib.sessions',
                'django.contrib.messages',
                'django_ftpserver',
            )
        )
    django.setup()
    from django.apps import apps
    if not apps.ready:
        apps.populate() 
Example #22
Source File: __init__.py    From django-rest-framework-cache with GNU General Public License v3.0 6 votes vote down vote up
def configure():
    from django.conf import settings

    settings.configure(
        DATABASES={'default': {'ENGINE': 'django.db.backends.sqlite3',
                               'NAME': ':memory:'}},
        INSTALLED_APPS=(
            'django.contrib.auth',
            'django.contrib.contenttypes',
            'django.contrib.sessions',
            'django.contrib.sites',
            'django.contrib.staticfiles',

            'rest_framework',
            'tests',
        ),
    )

    import django
    django.setup() 
Example #23
Source File: plugin.py    From django_coverage_plugin with Apache License 2.0 6 votes vote down vote up
def read_template_source(filename):
    """Read the source of a Django template, returning the Unicode text."""
    # Import this late to be sure we don't trigger settings machinery too
    # early.
    from django.conf import settings

    if not settings.configured:
        settings.configure()

    with open(filename, "rb") as f:
        # The FILE_CHARSET setting will be removed in 3.1:
        # https://docs.djangoproject.com/en/3.0/ref/settings/#file-charset
        if django.VERSION >= (3, 1):
            charset = 'utf-8'
        else:
            charset = settings.FILE_CHARSET
        text = f.read().decode(charset)

    return text 
Example #24
Source File: tests.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_configure(self):
        s = LazySettings()
        s.configure(SECRET_KEY='foo')

        self.assertTrue(s.is_overridden('SECRET_KEY')) 
Example #25
Source File: tests.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_already_configured(self):
        with self.assertRaisesMessage(RuntimeError, 'Settings already configured.'):
            settings.configure() 
Example #26
Source File: test_django_db_middleware.py    From opencensus-python with Apache License 2.0 5 votes vote down vote up
def setUp(self):
        from django.conf import settings as django_settings
        from django.test.utils import setup_test_environment

        if not django_settings.configured:
            django_settings.configure()
        setup_test_environment() 
Example #27
Source File: conftest.py    From django-selectel-storage with MIT License 5 votes vote down vote up
def pytest_configure():
    """
    Create an MVP of a django test project
    """
    from django.conf import settings

    username = os.getenv('SELECTEL_USERNAME')
    password = os.getenv('SELECTEL_PASSWORD')
    container = os.getenv('SELECTEL_CONTAINER_NAME')

    settings.configure(
        INSTALLED_APPS=['django_selectel_storage'],
        DATABASES={
            'default': {
                'ENGINE': 'django.db.backends.sqlite3',
                'NAME': ':MEMORY:'
            }
        },
        SELECTEL_STORAGES={
            'default': {
                'USERNAME': username,
                'PASSWORD': password,
                'CONTAINER': container,
            },
            'customized': {
                'USERNAME': username,
                'PASSWORD': password,
                'CONTAINER': container,
            },
            'static': 'selectel://user'
        },
    ) 
Example #28
Source File: tests.py    From djongo with GNU Affero General Public License v3.0 5 votes vote down vote up
def test_no_settings_module(self):
        msg = (
            'Requested setting%s, but settings are not configured. You '
            'must either define the environment variable DJANGO_SETTINGS_MODULE '
            'or call settings.configure() before accessing settings.'
        )
        orig_settings = os.environ[ENVIRONMENT_VARIABLE]
        os.environ[ENVIRONMENT_VARIABLE] = ''
        try:
            with self.assertRaisesMessage(ImproperlyConfigured, msg % 's'):
                settings._setup()
            with self.assertRaisesMessage(ImproperlyConfigured, msg % ' TEST'):
                settings._setup('TEST')
        finally:
            os.environ[ENVIRONMENT_VARIABLE] = orig_settings 
Example #29
Source File: conftest.py    From django-rest-marshmallow with ISC License 5 votes vote down vote up
def pytest_configure():
    from django.conf import settings

    settings.configure()

    try:
        import django
        django.setup()
    except AttributeError:
        pass 
Example #30
Source File: test_django.py    From openapi-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def django_settings(self):
        import django
        from django.conf import settings
        from django.contrib import admin
        from django.urls import path

        if settings.configured:
            return

        settings.configure(
            ALLOWED_HOSTS=[
                'testserver',
            ],
            INSTALLED_APPS=[
                'django.contrib.admin',
                'django.contrib.auth',
                'django.contrib.contenttypes',
                'django.contrib.messages',
                'django.contrib.sessions',
            ],
            MIDDLEWARE=[
                'django.contrib.sessions.middleware.SessionMiddleware',
                'django.contrib.auth.middleware.AuthenticationMiddleware',
                'django.contrib.messages.middleware.MessageMiddleware',
            ]
        )
        django.setup()
        settings.ROOT_URLCONF = (
            path('admin/', admin.site.urls),
        )