Beispiel #1
0
 def setUp(self):
     super(TestMetaData, self).setUp()
     set_up_storage(
         website.models.MODELS,
         storage.MongoStorage,
         addons=settings.ADDONS_AVAILABLE,
     )
Beispiel #2
0
    def setUpClass(cls):
        super(DbTestCase, cls).setUpClass()

        for (short_name, options) in cls.ADDONS_UNDER_TEST.iteritems():
            cls.__ADDONS_UNDER_TEST.append(
                init_mock_addon(short_name, **options)
            )

        cls._original_db_name = settings.DB_NAME
        settings.DB_NAME = cls.DB_NAME
        cls._original_piwik_host = settings.PIWIK_HOST
        settings.PIWIK_HOST = None
        cls._original_enable_email_subscriptions = settings.ENABLE_EMAIL_SUBSCRIPTIONS
        settings.ENABLE_EMAIL_SUBSCRIPTIONS = False

        cls._original_bcrypt_log_rounds = settings.BCRYPT_LOG_ROUNDS
        settings.BCRYPT_LOG_ROUNDS = 1

        teardown_database(database=database_proxy._get_current_object())
        # TODO: With `database` as a `LocalProxy`, we should be able to simply
        # this logic
        set_up_storage(
            website.models.MODELS,
            storage.MongoStorage,
            addons=settings.ADDONS_AVAILABLE,
        )
        cls.db = database_proxy
Beispiel #3
0
def do_set_backends(settings):
    logger.debug('Setting storage backends')
    set_up_storage(
        website.models.MODELS,
        storage.MongoStorage,
        addons=settings.ADDONS_AVAILABLE,
    )
Beispiel #4
0
    def setUpClass(cls):
        super(DbTestCase, cls).setUpClass()

        for (short_name, options) in cls.ADDONS_UNDER_TEST.iteritems():
            cls.__ADDONS_UNDER_TEST.append(
                init_mock_addon(short_name, **options))

        cls._original_db_name = settings.DB_NAME
        settings.DB_NAME = cls.DB_NAME
        cls._original_piwik_host = settings.PIWIK_HOST
        settings.PIWIK_HOST = None
        cls._original_enable_email_subscriptions = settings.ENABLE_EMAIL_SUBSCRIPTIONS
        settings.ENABLE_EMAIL_SUBSCRIPTIONS = False

        cls._original_bcrypt_log_rounds = settings.BCRYPT_LOG_ROUNDS
        settings.BCRYPT_LOG_ROUNDS = 1

        teardown_database(database=database_proxy._get_current_object())
        # TODO: With `database` as a `LocalProxy`, we should be able to simply
        # this logic
        set_up_storage(
            website.models.MODELS,
            storage.MongoStorage,
            addons=settings.ADDONS_AVAILABLE,
        )
        cls.db = database_proxy
Beispiel #5
0
def do_set_backends(settings):
    logger.debug('Setting storage backends')
    set_up_storage(
        website.models.MODELS,
        storage.MongoStorage,
        addons=settings.ADDONS_AVAILABLE,
    )
Beispiel #6
0
def attach_models(*args, **kwargs):
    """Attach models to database collections on worker initialization.
    """
    if settings.USE_POSTGRES:
        logger.debug(
            'Not setting storage backends because USE_POSTGRES = True')
        return
    set_up_storage(models.MODELS, storage.MongoStorage)
Beispiel #7
0
def do_set_backends(settings):
    logger.debug('Setting storage backends')
    maintenance.ensure_maintenance_collection()
    set_up_storage(
        website.models.MODELS,
        storage.MongoStorage,
        addons=settings.ADDONS_AVAILABLE,
    )
Beispiel #8
0
def do_set_backends(settings):
    logger.debug('Setting storage backends')
    maintenance.ensure_maintenance_collection()
    set_up_storage(
        website.models.MODELS,
        storage.MongoStorage,
        addons=settings.ADDONS_AVAILABLE,
    )
Beispiel #9
0
def do_set_backends(settings):
    if settings.USE_POSTGRES:
        logger.debug(
            'Not setting storage backends because USE_POSTGRES = True')
        return
    logger.debug('Setting storage backends')
    maintenance.ensure_maintenance_collection()
    set_up_storage(
        website.models.MODELS,
        storage.MongoStorage,
        addons=settings.ADDONS_AVAILABLE,
    )
Beispiel #10
0
def init_app(settings_module='website.settings',
             set_backends=True,
             routes=True,
             mfr=False,
             attach_request_handlers=True):
    """Initializes the OSF. A sort of pseudo-app factory that allows you to
    bind settings, set up routing, and set storage backends, but only acts on
    a single app instance (rather than creating multiple instances).

    :param settings_module: A string, the settings module to use.
    :param set_backends: Whether to set the database storage backends.
    :param routes: Whether to set the url map.

    """
    # The settings module
    settings = importlib.import_module(settings_module)

    build_log_templates(settings)
    init_addons(settings, routes)
    build_js_config_files(settings)

    app.debug = settings.DEBUG_MODE

    if mfr:
        init_mfr(app)

    if set_backends:
        logger.debug('Setting storage backends')
        set_up_storage(
            website.models.MODELS,
            storage.MongoStorage,
            addons=settings.ADDONS_AVAILABLE,
        )
    if routes:
        try:
            make_url_map(app)
        except AssertionError:  # Route map has already been created
            pass

    if attach_request_handlers:
        attach_handlers(app, settings)

    if app.debug:
        logger.info("Sentry disabled; Flask's debug mode enabled")
    else:
        sentry.init_app(app)
        logger.info("Sentry enabled; Flask's debug mode disabled")

    if set_backends:
        ensure_schemas()
    apply_middlewares(app, settings)
    return app
Beispiel #11
0
def init_app(settings_module='website.settings', set_backends=True, routes=True, mfr=False,
        attach_request_handlers=True):
    """Initializes the OSF. A sort of pseudo-app factory that allows you to
    bind settings, set up routing, and set storage backends, but only acts on
    a single app instance (rather than creating multiple instances).

    :param settings_module: A string, the settings module to use.
    :param set_backends: Whether to set the database storage backends.
    :param routes: Whether to set the url map.

    """
    # The settings module
    settings = importlib.import_module(settings_module)

    build_log_templates(settings)
    init_addons(settings, routes)
    build_js_config_files(settings)

    app.debug = settings.DEBUG_MODE

    if mfr:
        init_mfr(app)

    if set_backends:
        logger.debug('Setting storage backends')
        set_up_storage(
            website.models.MODELS,
            storage.MongoStorage,
            addons=settings.ADDONS_AVAILABLE,
        )
    if routes:
        try:
            make_url_map(app)
        except AssertionError:  # Route map has already been created
            pass

    if attach_request_handlers:
        attach_handlers(app, settings)

    if app.debug:
        logger.info("Sentry disabled; Flask's debug mode enabled")
    else:
        sentry.init_app(app)
        logger.info("Sentry enabled; Flask's debug mode disabled")

    if set_backends:
        ensure_schemas()
    apply_middlewares(app, settings)
    return app
Beispiel #12
0
def main():
    dry_run = '--dry' in sys.argv
    if not dry_run:
        script_utils.add_file_logger(logger, __file__)
    set_up_storage([Subject], storage.MongoStorage)
    with TokuTransaction():
        update_taxonomies('bepress_taxonomy.json')
        # Now that all subjects have been added to the db, compute and set
        # the 'children' field for every subject
        logger.info('Setting "children" field for each Subject')
        for subject in Subject.find():
            subject.children = Subject.find(Q('parents', 'eq', subject))
            subject.save()

        if dry_run:
            raise RuntimeError('Dry run, transaction rolled back')
Beispiel #13
0
    def setUpClass(cls):
        super(DbTestCase, cls).setUpClass()

        cls._original_db_name = settings.DB_NAME
        settings.DB_NAME = cls.DB_NAME
        cls._original_piwik_host = settings.PIWIK_HOST
        settings.PIWIK_HOST = None

        teardown_database(database=database_proxy._get_current_object())
        # TODO: With `database` as a `LocalProxy`, we should be able to simply
        # this logic
        set_up_storage(
            website.models.MODELS,
            storage.MongoStorage,
            addons=settings.ADDONS_AVAILABLE,
        )
        cls.db = database_proxy
Beispiel #14
0
    def setUpClass(cls):
        super(DbTestCase, cls).setUpClass()

        cls._original_db_name = settings.DB_NAME
        settings.DB_NAME = cls.DB_NAME
        cls._original_piwik_host = settings.PIWIK_HOST
        settings.PIWIK_HOST = None

        teardown_database(database=database_proxy._get_current_object())
        # TODO: With `database` as a `LocalProxy`, we should be able to simply
        # this logic
        set_up_storage(
            website.models.MODELS,
            storage.MongoStorage,
            addons=settings.ADDONS_AVAILABLE,
        )
        cls.db = database_proxy
def set_backend():
    """Ensure a storage backend is set up for this model"""
    set_up_storage([ApiOAuth2Scope], storage.MongoStorage)
Beispiel #16
0
def attach_models(*args, **kwargs):
    """Attach models to database collections on worker initialization.
    """
    set_up_storage(models.MODELS, storage.MongoStorage)
Beispiel #17
0
def set_backend():
    """Ensure a storage backend is set up for this model"""
    set_up_storage([ApiOAuth2Scope], storage.MongoStorage)
Beispiel #18
0
def init_storage():
    set_up_storage(MODELS, storage_class=storage.MongoStorage)
Beispiel #19
0
def init_storage():
    set_up_storage(MODELS, storage_class=storage.MongoStorage)
Beispiel #20
0
 def setUpClass(cls):
     super(OsfTestCase, cls).setUpClass()
     set_up_storage([DummyGuidFile], storage.MongoStorage)
Beispiel #21
0
 def setUpClass(cls):
     super(OsfTestCase, cls).setUpClass()
     set_up_storage([DummyGuidFile], storage.MongoStorage)