コード例 #1
0
ファイル: __init__.py プロジェクト: FieldDB/old
    def tearDown(self, **kwargs):
        clear_all_tables = kwargs.get('clear_all_tables', False)
        dirs_to_clear = kwargs.get('dirs_to_clear', [])
        del_global_app_set = kwargs.get('del_global_app_set', False)
        dirs_to_destroy = kwargs.get('dirs_to_destroy', [])

        if clear_all_tables:
            h.clear_all_tables(['language'])
        else:
            h.clear_all_models()
        administrator = h.generate_default_administrator()
        contributor = h.generate_default_contributor()
        viewer = h.generate_default_viewer()
        Session.add_all([administrator, contributor, viewer])
        Session.commit()

        for dir_path in dirs_to_clear:
            h.clear_directory_of_files(getattr(self, dir_path))

        for dir_name in dirs_to_destroy:
            {
                'user': lambda: h.destroy_all_directories('users', 'test.ini'),
                'corpus': lambda: h.destroy_all_directories('corpora', 'test.ini'),
                'phonology': lambda: h.destroy_all_directories('phonologies', 'test.ini'),
                'morphology': lambda: h.destroy_all_directories('morphologies', 'test.ini'),
                'morphological_parser': lambda: h.destroy_all_directories('morphological_parsers', 'test.ini'),
                'morpheme_language_model': lambda: h.destroy_all_directories('morpheme_language_models', 'test.ini')
            }.get(dir_name, lambda: None)()

        if del_global_app_set:
            # Perform a vacuous GET just to delete app_globals.application_settings
            # to clean up for subsequent tests.
            self.app.get(url('new_form'), extra_environ=self.extra_environ_admin_appset)
コード例 #2
0
ファイル: test_corpora_large.py プロジェクト: FieldDB/old
 def test_zzz_cleanup(self):
     """Clean up after the tests."""
     # Destruction
     h.clear_all_tables()
     h.destroy_all_directories(directory_name='users', config_filename='test.ini')
     h.destroy_all_directories(directory_name='corpora', config_filename='test.ini')
     # Creation
     languages = h.get_language_objects('test.ini', self.config)
     administrator = h.generate_default_administrator()
     contributor = h.generate_default_contributor()
     viewer = h.generate_default_viewer()
     Session.add_all([administrator, contributor, viewer] + languages)
     Session.commit()
コード例 #3
0
ファイル: test_rememberedforms.py プロジェクト: jrwdunham/old
    def test_e_cleanup(self):
        """Clean up the database after /rememberedforms tests."""

        h.clear_all_models()
        administrator = h.generate_default_administrator()
        contributor = h.generate_default_contributor()
        viewer = h.generate_default_viewer()
        Session.add_all([administrator, contributor, viewer])
        Session.commit()

        # Perform a vacuous GET just to delete app_globals.application_settings
        # to clean up for subsequent tests.
        extra_environ = {'test.authentication.role': u'administrator',
                         'test.application_settings': True}
        self.app.get(url('forms'), extra_environ=extra_environ)
コード例 #4
0
 def test_zzz_cleanup(self):
     """Clean up after the tests."""
     # Destruction
     h.clear_all_tables()
     h.destroy_all_directories(directory_name='users',
                               config_filename='test.ini')
     h.destroy_all_directories(directory_name='corpora',
                               config_filename='test.ini')
     # Creation
     languages = h.get_language_objects('test.ini', self.config)
     administrator = h.generate_default_administrator()
     contributor = h.generate_default_contributor()
     viewer = h.generate_default_viewer()
     Session.add_all([administrator, contributor, viewer] + languages)
     Session.commit()
コード例 #5
0
    def test_e_cleanup(self):
        """Clean up the database after /rememberedforms tests."""

        h.clear_all_models()
        administrator = h.generate_default_administrator()
        contributor = h.generate_default_contributor()
        viewer = h.generate_default_viewer()
        Session.add_all([administrator, contributor, viewer])
        Session.commit()

        # Perform a vacuous GET just to delete app_globals.application_settings
        # to clean up for subsequent tests.
        extra_environ = {
            'test.authentication.role': u'administrator',
            'test.application_settings': True
        }
        self.app.get(url('forms'), extra_environ=extra_environ)
コード例 #6
0
ファイル: test_rememberedforms.py プロジェクト: jrwdunham/old
    def test_a_initialize(self):
        """Initialize the database for /rememberedforms tests."""
        h.clear_all_models()
        administrator = h.generate_default_administrator()
        contributor = h.generate_default_contributor()
        viewer = h.generate_default_viewer()
        Session.add_all([administrator, contributor, viewer])
        Session.commit()

        _create_test_data(self.n)
        self._add_SEARCH_to_web_test_valid_methods()

        # Create an application settings where the contributor is unrestricted
        viewer, contributor, administrator = get_users()
        application_settings = h.generate_default_application_settings()
        application_settings.unrestricted_users = [contributor]
        Session.add(application_settings)
        Session.commit()
コード例 #7
0
    def test_a_initialize(self):
        """Initialize the database for /rememberedforms tests."""
        h.clear_all_models()
        administrator = h.generate_default_administrator()
        contributor = h.generate_default_contributor()
        viewer = h.generate_default_viewer()
        Session.add_all([administrator, contributor, viewer])
        Session.commit()

        _create_test_data(self.n)
        self._add_SEARCH_to_web_test_valid_methods()

        # Create an application settings where the contributor is unrestricted
        viewer, contributor, administrator = get_users()
        application_settings = h.generate_default_application_settings()
        application_settings.unrestricted_users = [contributor]
        Session.add(application_settings)
        Session.commit()
コード例 #8
0
    def tearDown(self, **kwargs):
        clear_all_tables = kwargs.get('clear_all_tables', False)
        dirs_to_clear = kwargs.get('dirs_to_clear', [])
        del_global_app_set = kwargs.get('del_global_app_set', False)
        dirs_to_destroy = kwargs.get('dirs_to_destroy', [])

        if clear_all_tables:
            h.clear_all_tables(['language'])
        else:
            h.clear_all_models()
        administrator = h.generate_default_administrator()
        contributor = h.generate_default_contributor()
        viewer = h.generate_default_viewer()
        Session.add_all([administrator, contributor, viewer])
        Session.commit()

        for dir_path in dirs_to_clear:
            h.clear_directory_of_files(getattr(self, dir_path))

        for dir_name in dirs_to_destroy:
            {
                'user':
                lambda: h.destroy_all_directories('users', 'test.ini'),
                'corpus':
                lambda: h.destroy_all_directories('corpora', 'test.ini'),
                'phonology':
                lambda: h.destroy_all_directories('phonologies', 'test.ini'),
                'morphology':
                lambda: h.destroy_all_directories('morphologies', 'test.ini'),
                'morphological_parser':
                lambda: h.destroy_all_directories('morphological_parsers',
                                                  'test.ini'),
                'morpheme_language_model':
                lambda: h.destroy_all_directories('morpheme_language_models',
                                                  'test.ini')
            }.get(dir_name, lambda: None)()

        if del_global_app_set:
            # Perform a vacuous GET just to delete app_globals.application_settings
            # to clean up for subsequent tests.
            self.app.get(url('new_form'),
                         extra_environ=self.extra_environ_admin_appset)
コード例 #9
0
ファイル: websetup.py プロジェクト: jrwdunham/old
def setup_app(command, conf, vars):
    """Commands to setup onlinelinguisticdatabase."""

    config = load_environment(conf.global_conf, conf.local_conf)
    log.info('Environment loaded.')

    Base.metadata.create_all(bind=Session.bind)
    filename = os.path.split(conf.filename)[-1] # e.g., production.ini, development.ini, test.ini, ...

    # Create the ``store`` directory and those for file, analysis and corpora
    # objects and their subdirectories.  See ``lib.utils.py`` for details.
    h.create_OLD_directories(config=config)

    # ISO-639-3 Language data for the languages table
    log.info("Retrieving ISO-639-3 languages data.")
    languages = h.get_language_objects(filename, config)

    # Get default users.
    log.info("Creating a default administrator, contributor and viewer.")
    administrator = h.generate_default_administrator(config_filename=filename)
    contributor = h.generate_default_contributor(config_filename=filename)
    viewer = h.generate_default_viewer(config_filename=filename)

    # If we are running tests, make sure the test db contains only language data.
    if filename == 'test.ini':
        # Permanently drop any existing tables
        Base.metadata.drop_all(bind=Session.bind, checkfirst=True)
        log.info("Existing tables dropped.")

        # Create the tables if they don't already exist
        Base.metadata.create_all(bind=Session.bind, checkfirst=True)
        log.info('Tables created.')

        Session.add_all(languages + [administrator, contributor, viewer])
        Session.commit()

    # Not a test: add a bunch of nice defaults.
    else:
        # Create the _requests_tests.py script
        requests_tests_path = os.path.join(config['pylons.paths']['root'], 'tests',
                                         'scripts', '_requests_tests.py')

        # This line is problematic in production apps because the
        # _requests_tests.py file is not included in the build. So, I'm
        # commenting it out by default.
        # copyfile(requests_tests_path, '_requests_tests.py')

        # Create the tables if they don't already exist
        Base.metadata.create_all(bind=Session.bind, checkfirst=True)
        log.info('Tables created.')

        # Get default home & help pages.
        log.info("Creating default home and help pages.")
        homepage = h.generate_default_home_page()
        helppage = h.generate_default_help_page()
    
        # Get default application settings.
        log.info("Generating default application settings.")
        application_settings = h.generate_default_application_settings()
    
        # Get default tags and categories
        log.info("Creating some useful tags and categories.")
        restricted_tag = h.generate_restricted_tag()
        foreign_word_tag = h.generate_foreign_word_tag()
        S = h.generate_s_syntactic_category()
        N = h.generate_n_syntactic_category()
        V = h.generate_v_syntactic_category()
    
        # Initialize the database
        log.info("Adding defaults.")
        data = [administrator, contributor, viewer, homepage, helppage,
                application_settings, restricted_tag, foreign_word_tag]
        if config['add_language_data'] != '0':
            data += languages
        if config['empty_database'] == '0':
            Session.add_all(data)
            Session.commit()
        log.info("OLD successfully set up.")
コード例 #10
0
ファイル: websetup.py プロジェクト: dativebase/old
def setup_app(command, conf, vars):
    """Commands to setup onlinelinguisticdatabase."""

    config = load_environment(conf.global_conf, conf.local_conf)
    log.info('Environment loaded.')

    Base.metadata.create_all(bind=Session.bind)
    filename = os.path.split(conf.filename)[
        -1]  # e.g., production.ini, development.ini, test.ini, ...

    # Create the ``store`` directory and those for file, analysis and corpora
    # objects and their subdirectories.  See ``lib.utils.py`` for details.
    h.create_OLD_directories(config=config)

    # ISO-639-3 Language data for the languages table
    log.info("Retrieving ISO-639-3 languages data.")
    languages = h.get_language_objects(filename, config)

    # Get default users.
    log.info("Creating a default administrator, contributor and viewer.")
    administrator = h.generate_default_administrator(config_filename=filename)
    contributor = h.generate_default_contributor(config_filename=filename)
    viewer = h.generate_default_viewer(config_filename=filename)

    # If we are running tests, make sure the test db contains only language data.
    if filename == 'test.ini':
        # Permanently drop any existing tables
        Base.metadata.drop_all(bind=Session.bind, checkfirst=True)
        log.info("Existing tables dropped.")

        # Create the tables if they don't already exist
        Base.metadata.create_all(bind=Session.bind, checkfirst=True)
        log.info('Tables created.')

        Session.add_all(languages + [administrator, contributor, viewer])
        Session.commit()

    # Not a test: add a bunch of nice defaults.
    else:
        # Create the _requests_tests.py script
        requests_tests_path = os.path.join(config['pylons.paths']['root'],
                                           'tests', 'scripts',
                                           '_requests_tests.py')

        # This line is problematic in production apps because the
        # _requests_tests.py file is not included in the build. So, I'm
        # commenting it out by default.
        # copyfile(requests_tests_path, '_requests_tests.py')

        # Create the tables if they don't already exist
        Base.metadata.create_all(bind=Session.bind, checkfirst=True)
        log.info('Tables created.')

        # Get default home & help pages.
        log.info("Creating default home and help pages.")
        homepage = h.generate_default_home_page()
        helppage = h.generate_default_help_page()

        # Get default application settings.
        log.info("Generating default application settings.")
        application_settings = h.generate_default_application_settings()

        # Get default tags and categories
        log.info("Creating some useful tags and categories.")
        restricted_tag = h.generate_restricted_tag()
        foreign_word_tag = h.generate_foreign_word_tag()
        S = h.generate_s_syntactic_category()
        N = h.generate_n_syntactic_category()
        V = h.generate_v_syntactic_category()

        # Initialize the database
        log.info("Adding defaults.")
        data = [
            administrator, contributor, viewer, homepage, helppage,
            application_settings, restricted_tag, foreign_word_tag
        ]
        if config['add_language_data'] != '0':
            data += languages
        if config['empty_database'] == '0':
            Session.add_all(data)
            Session.commit()
        log.info("OLD successfully set up.")