예제 #1
0
    def import_file(self, media):
        try:
            media_type, media_manager = (
                #get_media_type_and_manager(media.filename))
                type_match_handler(media,media.filename))
        except FileTypeNotSupported:
            print u"File type not supported: {0}".format(media.filename)
            return
        entry = self.db.MediaEntry()
        entry.media_type = unicode(media_type)
        entry.title = unicode(
            os.path.basename(os.path.splitext(media.filename)[0]))

        entry.uploader = 1
        # Process the user's folksonomy "tags"
        entry.tags = convert_to_tag_list_of_dicts("")
        # Generate a slug from the title
        entry.generate_slug()

        task_id = unicode(uuid.uuid4())
        entry.queued_media_file = media.filename.split("/")
        entry.queued_task_id = task_id

        try:
            entry.save()
            entry_id = entry.id
            run_process_media(entry)
            Session.commit()
            return entry_id
        except Exception:
            Session.rollback()
            raise
예제 #2
0
def get_app(request, paste_config=None, mgoblin_config=None):
    """Create a MediaGoblin app for testing.

    Args:
     - request: Not an http request, but a pytest fixture request.  We
       use this to make temporary directories that pytest
       automatically cleans up as needed.
     - paste_config: particular paste config used by this application.
     - mgoblin_config: particular mediagoblin config used by this
       application.
    """
    paste_config = paste_config or TEST_SERVER_CONFIG
    mgoblin_config = mgoblin_config or TEST_APP_CONFIG

    # This is the directory we're copying the paste/mgoblin config stuff into
    run_dir = request.config._tmpdirhandler.mktemp('mgoblin_app',
                                                   numbered=True)
    user_dev_dir = run_dir.mkdir('user_dev').strpath

    new_paste_config = run_dir.join('paste.ini').strpath
    new_mgoblin_config = run_dir.join('mediagoblin.ini').strpath
    shutil.copyfile(paste_config, new_paste_config)
    shutil.copyfile(mgoblin_config, new_mgoblin_config)

    Session.rollback()
    Session.remove()

    # install user_dev directories
    for directory in USER_DEV_DIRECTORIES_TO_SETUP:
        full_dir = os.path.join(user_dev_dir, directory)
        os.makedirs(full_dir)

    # Get app config
    global_config, validation_result = read_mediagoblin_config(
        new_mgoblin_config)
    app_config = global_config['mediagoblin']

    # Run database setup/migrations
    # @@: The *only* test that doesn't pass if we remove this is in
    #   test_persona.py... why?
    run_dbupdate(app_config, global_config)

    # setup app and return
    test_app = loadapp('config:' + new_paste_config)

    # Insert the TestingMeddleware, which can do some
    # sanity checks on every request/response.
    # Doing it this way is probably not the cleanest way.
    # We'll fix it, when we have plugins!
    mg_globals.app.meddleware.insert(0, TestingMeddleware(mg_globals.app))

    app = TestApp(test_app)
    return app
예제 #3
0
파일: tools.py 프로젝트: ausbin/mediagoblin
def get_app(request, paste_config=None, mgoblin_config=None):
    """Create a MediaGoblin app for testing.

    Args:
     - request: Not an http request, but a pytest fixture request.  We
       use this to make temporary directories that pytest
       automatically cleans up as needed.
     - paste_config: particular paste config used by this application.
     - mgoblin_config: particular mediagoblin config used by this
       application.
    """
    paste_config = paste_config or TEST_SERVER_CONFIG
    mgoblin_config = mgoblin_config or TEST_APP_CONFIG

    # This is the directory we're copying the paste/mgoblin config stuff into
    run_dir = request.config._tmpdirhandler.mktemp(
        'mgoblin_app', numbered=True)
    user_dev_dir = run_dir.mkdir('user_dev').strpath

    new_paste_config = run_dir.join('paste.ini').strpath
    new_mgoblin_config = run_dir.join('mediagoblin.ini').strpath
    shutil.copyfile(paste_config, new_paste_config)
    shutil.copyfile(mgoblin_config, new_mgoblin_config)

    Session.rollback()
    Session.remove()

    # install user_dev directories
    for directory in USER_DEV_DIRECTORIES_TO_SETUP:
        full_dir = os.path.join(user_dev_dir, directory)
        os.makedirs(full_dir)

    # Get app config
    global_config, validation_result = read_mediagoblin_config(new_mgoblin_config)
    app_config = global_config['mediagoblin']

    # Run database setup/migrations
    # @@: The *only* test that doesn't pass if we remove this is in
    #   test_persona.py... why?
    run_dbupdate(app_config, global_config)

    # setup app and return
    test_app = loadapp(
        'config:' + new_paste_config)

    # Insert the TestingMeddleware, which can do some
    # sanity checks on every request/response.
    # Doing it this way is probably not the cleanest way.
    # We'll fix it, when we have plugins!
    mg_globals.app.meddleware.insert(0, TestingMeddleware(mg_globals.app))

    app = TestApp(test_app)
    return app
def test_media_data_init(test_app):
    Session.rollback()
    Session.remove()
    media = MediaEntry()
    media.media_type = u"mediagoblin.media_types.image"
    assert media.media_data is None
    media.media_data_init()
    assert media.media_data is not None
    obj_in_session = 0
    for obj in Session():
        obj_in_session += 1
        print(repr(obj))
    assert obj_in_session == 0
예제 #5
0
def get_test_app(dump_old_app=True):
    suicide_if_bad_celery_environ()

    # Make sure we've turned on testing
    testing._activate_testing()

    # Leave this imported as it sets up celery.
    from mediagoblin.init.celery import from_tests

    global MGOBLIN_APP

    # Just return the old app if that exists and it's okay to set up
    # and return
    if MGOBLIN_APP and not dump_old_app:
        return MGOBLIN_APP

    Session.rollback()
    Session.remove()

    # Remove and reinstall user_dev directories
    if os.path.exists(TEST_USER_DEV):
        shutil.rmtree(TEST_USER_DEV)

    for directory in USER_DEV_DIRECTORIES_TO_SETUP:
        full_dir = os.path.join(TEST_USER_DEV, directory)
        os.makedirs(full_dir)

    # Get app config
    global_config, validation_result = read_mediagoblin_config(TEST_APP_CONFIG)
    app_config = global_config["mediagoblin"]

    # Run database setup/migrations
    run_dbupdate(app_config, global_config)

    # setup app and return
    test_app = loadapp("config:" + TEST_SERVER_CONFIG)

    # Re-setup celery
    setup_celery_app(app_config, global_config)

    # Insert the TestingMeddleware, which can do some
    # sanity checks on every request/response.
    # Doing it this way is probably not the cleanest way.
    # We'll fix it, when we have plugins!
    mg_globals.app.meddleware.insert(0, TestingMeddleware(mg_globals.app))

    app = TestApp(test_app)
    MGOBLIN_APP = app

    return app
예제 #6
0
def check_db_up_to_date():
    """Check if the database is up to date and quit if not"""
    dbdatas = gather_database_data(mgg.global_config.get('plugins', {}).keys())

    for dbdata in dbdatas:
        session = Session()
        try:
            migration_manager = dbdata.make_migration_manager(session)
            if migration_manager.database_current_migration is None or \
                    migration_manager.migrations_to_run():
                sys.exit("Your database is not up to date. Please run "
                         "'gmg dbupdate' before starting MediaGoblin.")
        finally:
            Session.rollback()
            Session.remove()
예제 #7
0
파일: util.py 프로젝트: ausbin/mediagoblin
def check_db_up_to_date():
    """Check if the database is up to date and quit if not"""
    dbdatas = gather_database_data(mgg.global_config.get('plugins', {}).keys())

    for dbdata in dbdatas:
        session = Session()
        try:
            migration_manager = dbdata.make_migration_manager(session)
            if migration_manager.database_current_migration is None or \
                    migration_manager.migrations_to_run():
                sys.exit("Your database is not up to date. Please run "
                         "'gmg dbupdate' before starting MediaGoblin.")
        finally:
            Session.rollback()
            Session.remove()
예제 #8
0
 def add_to_collection(self, collection_title, entries):
     if not entries:
         return
     collection = (self.db.Collection.query
                   .filter_by(creator=1, title=collection_title)
                   .first())
     if not collection:
         collection = self.db.Collection()
         collection.title = collection_title
         collection.creator = 1
         collection.generate_slug()
         collection.save()
         Session.commit()
     for entry in entries:
         add_media_to_collection(collection, entry, commit=False)
     try:
         Session.commit()
     except Exception as exc:
         print (u"Could add media to collection {}: {}"
                "".format(collection_title, exc))
         Session.rollback()
예제 #9
0
 def reset_after_request(self):
     Session.rollback()
     Session.remove()
예제 #10
0
 def reset_after_request(self):
     Session.rollback()
     Session.remove()