def test_local_conf_option_not_in_settings_module(self):
        global_conf = get_global_conf('empty_module2')
        local_conf = get_local_conf(setting1='String')
        get_configured_django_wsgi_app(global_conf, **local_conf)

        from tests.mock_django_settings import empty_module2

        ok_(hasattr(empty_module2, 'setting1'))
        eq_(empty_module2.setting1, 'String')
    def test_existing_module(self):
        global_conf = get_global_conf('empty_module')
        local_conf = get_local_conf()
        get_configured_django_wsgi_app(global_conf, **local_conf)

        assert_in('DJANGO_SETTINGS_MODULE', os.environ)
        eq_(
            os.environ['DJANGO_SETTINGS_MODULE'],
            'tests.mock_django_settings.empty_module',
            )
    def test_local_conf_list_option_in_settings_module(self):
        """
        Additional settings can extend lists or tuples in the original module.

        """
        global_conf = get_global_conf('iterables_module')
        local_conf = get_local_conf(LIST=[8, 9], TUPLE=(6, 7))
        get_configured_django_wsgi_app(global_conf, **local_conf)

        from tests.mock_django_settings import iterables_module

        eq_(iterables_module.LIST, (1, 2, 3, 8, 9))
        eq_(iterables_module.TUPLE, (1, 2, 3, 6, 7))
    def test_local_conf_option_in_settings_module(self):
        global_conf = get_global_conf('one_member_module')
        local_conf = get_local_conf(MEMBER='FOO')
        get_configured_django_wsgi_app(global_conf, **local_conf)

        from tests.mock_django_settings import one_member_module

        eq_(one_member_module.MEMBER, "MEMBER")
        ok_(len(self.logs['warning']), 1)
        eq_(
            '"MEMBER" will not be overridden in ' \
                'tests.mock_django_settings.one_member_module',
            self.logs['warning'][0],
            )
Пример #5
0
def make_application(global_config, **local_conf):

    db_host = global_config.get("db_host", None)
    db_port = global_config.get("db_port", None)
    db_name = global_config.get("db_name", None)

    # Set db user and db password
    db_account = fetch_pass(keyword="postgres",
                            host=db_host,
                            port=db_port,
                            db=db_name)
    global_config["db_user"] = db_account.user
    global_config["db_pass"] = db_account.passwd

    # Set influxdb user and password
    influx_account = fetch_pass(keyword="influxdb",
                                host=db_host,
                                port=db_port,
                                db=db_name)
    global_config["influx_username"] = influx_account.user
    global_config["influx_password"] = influx_account.passwd

    # Set confluent user and password
    confluent_account = fetch_pass(keyword="confluent",
                                   host=db_host,
                                   port=db_port,
                                   db=db_name)
    global_config["confluent_user"] = confluent_account.user
    global_config["confluent_pass"] = confluent_account.passwd

    app = get_configured_django_wsgi_app(global_config, **local_conf)

    return app
 def test_custom_application(self):
     global_conf = get_global_conf('settings6')
     app = get_configured_django_wsgi_app(
         global_conf,
         WSGI_APPLICATION='"tests.utils.MOCK_WSGI_APP"',
         )
     ok_(isinstance(app, MockApp))
Пример #7
0
def make_application(global_config, **local_conf):

    # print(global_config)
    # print(local_conf)

    app = get_configured_django_wsgi_app(global_config, **local_conf)

    return app
Пример #8
0
def make_wsgi_application(global_config, **local_conf):
    """
    generic function to create a wsgi application out of a given paster config

    :param global_config:
    :param local_conf:
    :return:
    """

    # monkeypatching psycopg2 compatibility
    # https://github.com/chtd/psycopg2cffi
    from psycopg2cffi import compat
    compat.register()

    # Do something before importing Django and your settings have been applied.
    if global_config['__file__'] not in __apps_by_ini_configuration__:
        log.debug('create django wsgi app from ini-file %s...', global_config['__file__'])
        app = get_configured_django_wsgi_app(global_config, **local_conf)

        # Do something right after your application has been set up (e.g., add WSGI middleware).
        # http://rhodesmill.org/brandon/2011/wsgi-under-cherrypy/

        # non-standard customization: we want to be able to switch a function via ini-configuration
        from django.conf import settings as django_settings

        # TODO amb: tiny hack: cookie-domain must be a string. dunno where this becomes a unicode
        django_settings.SESSION_COOKIE_DOMAIN = str(django_settings.SESSION_COOKIE_DOMAIN)

        log.debug('FIXTURE_DIRS:    %s', getattr(django_settings, 'FIXTURE_DIRS', None))

        debug_flag = global_config['debug'] == 'true' or False
        if debug_flag:
            log.debug('add `TransLogger` to see all requests')
            app = TransLogger(app)
        __apps_by_ini_configuration__[global_config['__file__']] = app
    else:
        log.warn('reuse django wsgi app from ini-file %s to avoid ``django.conf`` collisions',
                 global_config['__file__'])
    return __apps_by_ini_configuration__[global_config['__file__']]
    def test_default_application(self):
        global_conf = get_global_conf('settings5')
        app = get_configured_django_wsgi_app(global_conf)

        eq_(app.__class__, WSGIHandler)