Example #1
0
    def setup_db(self, package_name):
        """
        Drops and re-installs the database found at "arches_<package_name>"
        WARNING: This will destroy data

        """

        db_settings = settings.DATABASES['default']
        truncate_path = os.path.join(settings.ROOT_DIR, 'db', 'install',
                                     'truncate_db.sql')
        install_path = os.path.join(settings.ROOT_DIR, 'db', 'install',
                                    'install_db.sql')
        db_settings['truncate_path'] = truncate_path
        db_settings['install_path'] = install_path

        truncate_db.create_sqlfile(db_settings, truncate_path)
        install_db.create_sqlfile(db_settings, install_path)

        os.system(
            'psql -h %(HOST)s -p %(PORT)s -U %(USER)s -d postgres -f "%(truncate_path)s"'
            % db_settings)
        os.system(
            'psql -h %(HOST)s -p %(PORT)s -U %(USER)s -d %(NAME)s -f "%(install_path)s"'
            % db_settings)

        create_default_auth_system()
Example #2
0
    def setup_db(self, package_name):
        """
        Drops and re-installs the database found at "arches_<package_name>"
        WARNING: This will destroy data

        """

        db_settings = settings.DATABASES['default']
        truncate_path = os.path.join(settings.ROOT_DIR, 'db', 'install', 'truncate_db.sql')
        install_path = os.path.join(settings.ROOT_DIR, 'db', 'install', 'install_db.sql')  
        db_settings['truncate_path'] = truncate_path
        db_settings['install_path'] = install_path   
        
        truncate_db.create_sqlfile(db_settings, truncate_path)
        install_db.create_sqlfile(db_settings, install_path)
        
        os.system('psql -h %(HOST)s -p %(PORT)s -U %(USER)s -d postgres -f "%(truncate_path)s"' % db_settings)
        os.system('psql -h %(HOST)s -p %(PORT)s -U %(USER)s -d %(NAME)s -f "%(install_path)s"' % db_settings)

        self.create_groups()
        self.create_users()
Example #3
0
def setup_db(connection):
    """
    Taken from the setup_db management command but slightly edited to run using the test database name. It will
    also run the test_setup.install() function that will edit and add concepts into the database.
    """

    test_database_name = connection.creation._get_test_db_name()

    db_settings = settings.DATABASES['default']
    db_settings['NAME'] = test_database_name

    truncate_path = os.path.join(settings.ROOT_DIR, 'db', 'install',
                                 'truncate_db.sql')
    install_path = os.path.join(settings.ROOT_DIR, 'db', 'install',
                                'install_db.sql')
    db_settings['truncate_path'] = truncate_path
    db_settings['install_path'] = install_path

    truncate_db.create_sqlfile(db_settings, truncate_path)
    install_db.create_sqlfile(db_settings, install_path)

    os.system(
        'psql -h %(HOST)s -p %(PORT)s -U %(USER)s -d postgres -f "%(truncate_path)s"'
        % db_settings)
    os.system(
        'psql -h %(HOST)s -p %(PORT)s -U %(USER)s -d %(NAME)s -f "%(install_path)s"'
        % db_settings)

    create_groups()
    create_users()

    settings.DATABASES['default']["NAME"] = test_database_name
    connection.settings_dict["NAME"] = test_database_name

    print "DATABASE CREATION STEP DONE - NOW ADDING DATA"

    test_setup.install()

    return test_database_name
Example #4
0
    def create_test_db(self, verbosity=1, autoclobber=False):
        """
        Creates a test database, prompting the user for confirmation if the
        database already exists. Returns the name of the test database created.
        """
        # Don't import django.core.management if it isn't needed.
        from django.core.management import call_command

        test_database_name = self._get_test_db_name()

        if verbosity >= 1:
            test_db_repr = ''
            if verbosity >= 2:
                test_db_repr = " ('%s')" % test_database_name
            print("Creating test database for alias '%s'%s..." %
                  (self.connection.alias, test_db_repr))

        self._create_test_db(verbosity, autoclobber)

        # Create the base arches database and connect to it.
        install_path = os.path.join(settings.ROOT_DIR, 'db', 'install',
                                    'install_db.sql')

        db_settings = settings.DATABASES['default']
        db_settings['NAME'] = test_database_name
        db_settings['install_path'] = install_path

        install_db.create_sqlfile(db_settings, install_path)

        os.system(
            'psql -h %(HOST)s -p %(PORT)s -U %(USER)s -d %(NAME)s -f "%(install_path)s"'
            % db_settings)

        self.connection.close()
        settings.DATABASES[self.connection.alias]["NAME"] = test_database_name
        self.connection.settings_dict["NAME"] = test_database_name

        # Report syncdb messages at one level lower than that requested.
        # This ensures we don't get flooded with messages during testing
        # (unless you really ask to be flooded)
        # call_command('syncdb',
        #     verbosity=max(verbosity - 1, 0),
        #     interactive=False,
        #     database=self.connection.alias,
        #     load_initial_data=False)

        # We need to then do a flush to ensure that any data installed by
        # custom SQL has been removed. The only test data should come from
        # test fixtures, or autogenerated from post_syncdb triggers.
        # This has the side effect of loading initial data (which was
        # intentionally skipped in the syncdb).
        # call_command('flush',
        #     verbosity=max(verbosity - 1, 0),
        #     interactive=False,
        #     database=self.connection.alias)

        from django.core.cache import get_cache
        from django.core.cache.backends.db import BaseDatabaseCache
        for cache_alias in settings.CACHES:
            cache = get_cache(cache_alias)
            if isinstance(cache, BaseDatabaseCache):
                call_command('createcachetable',
                             cache._table,
                             database=self.connection.alias)

        # Get a cursor (even though we don't need one yet). This has
        # the side effect of initializing the test database.
        self.connection.cursor()

        return test_database_name
Example #5
0
    def create_test_db(self, verbosity=1, autoclobber=False):
        """
        Creates a test database, prompting the user for confirmation if the
        database already exists. Returns the name of the test database created.
        """
        # Don't import django.core.management if it isn't needed.
        from django.core.management import call_command

        test_database_name = self._get_test_db_name()

        if verbosity >= 1:
            test_db_repr = ""
            if verbosity >= 2:
                test_db_repr = " ('%s')" % test_database_name
            print("Creating test database for alias '%s'%s..." % (self.connection.alias, test_db_repr))

        self._create_test_db(verbosity, autoclobber)

        # Create the base arches database and connect to it.
        install_path = os.path.join(settings.ROOT_DIR, "db", "install", "install_db.sql")

        db_settings = settings.DATABASES["default"]
        db_settings["NAME"] = test_database_name
        db_settings["install_path"] = install_path

        install_db.create_sqlfile(db_settings, install_path)

        os.system('psql -h %(HOST)s -p %(PORT)s -U %(USER)s -d %(NAME)s -f "%(install_path)s"' % db_settings)

        self.connection.close()
        settings.DATABASES[self.connection.alias]["NAME"] = test_database_name
        self.connection.settings_dict["NAME"] = test_database_name

        # Report syncdb messages at one level lower than that requested.
        # This ensures we don't get flooded with messages during testing
        # (unless you really ask to be flooded)
        # call_command('syncdb',
        #     verbosity=max(verbosity - 1, 0),
        #     interactive=False,
        #     database=self.connection.alias,
        #     load_initial_data=False)

        # We need to then do a flush to ensure that any data installed by
        # custom SQL has been removed. The only test data should come from
        # test fixtures, or autogenerated from post_syncdb triggers.
        # This has the side effect of loading initial data (which was
        # intentionally skipped in the syncdb).
        # call_command('flush',
        #     verbosity=max(verbosity - 1, 0),
        #     interactive=False,
        #     database=self.connection.alias)

        from django.core.cache import get_cache
        from django.core.cache.backends.db import BaseDatabaseCache

        for cache_alias in settings.CACHES:
            cache = get_cache(cache_alias)
            if isinstance(cache, BaseDatabaseCache):
                call_command("createcachetable", cache._table, database=self.connection.alias)

        # Get a cursor (even though we don't need one yet). This has
        # the side effect of initializing the test database.
        self.connection.cursor()

        return test_database_name