Esempio n. 1
0
def do_syncdb (devel_username, projname):
    class helper (object):
        def __init__ (self):
            self.s = ''
        def write (self, s):
            self.s += s

    h = helper ()
    oldpath = list (sys.path)

    # Setup Flume-Django environment # If this is running as
    # user=djangotools, then djantools is already in the path, and
    # this will end up adding djangotools to the sys.path a second
    # time.  But it also adds django.zip which might not be in the
    # path.
    from w5djangoutil import setup_django_path_and_environ
    setup_django_path_and_environ (devel_username, projname)

    # Redirect django's output to this cgi program and then run syncdb.
    from django.core.management import syncdb, set_output
    set_output (h)
    syncdb ()

    sys.path = oldpath
    return h.s
Esempio n. 2
0
                        print "Destroying old test database..."                
                    cursor.execute("DROP DATABASE %s" % backend.quote_name(TEST_DATABASE_NAME))
                    if verbosity >= 1:
                        print "Creating test database..."
                    cursor.execute("CREATE DATABASE %s %s" % (backend.quote_name(TEST_DATABASE_NAME), suffix))
                except Exception, e:
                    sys.stderr.write("Got an error recreating the test database: %s\n" % e)
                    sys.exit(2)
            else:
                print "Tests cancelled."
                sys.exit(1)
               
    connection.close()
    settings.DATABASE_NAME = TEST_DATABASE_NAME

    management.syncdb(verbosity, interactive=False)

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

def destroy_test_db(old_database_name, verbosity=1):
    # Unless we're using SQLite, remove the test database to clean up after
    # ourselves. Connect to the previous database (not the test database)
    # to do so, because it's not allowed to delete a database while being
    # connected to it.
    if verbosity >= 1:
        print "Destroying test database..."
    connection.close()
    TEST_DATABASE_NAME = settings.DATABASE_NAME
    settings.DATABASE_NAME = old_database_name
Esempio n. 3
0
                        print "Creating test database..."
                    cursor.execute(
                        "CREATE DATABASE %s %s" %
                        (backend.quote_name(TEST_DATABASE_NAME), suffix))
                except Exception, e:
                    sys.stderr.write(
                        "Got an error recreating the test database: %s\n" % e)
                    sys.exit(2)
            else:
                print "Tests cancelled."
                sys.exit(1)

    connection.close()
    settings.DATABASE_NAME = TEST_DATABASE_NAME

    management.syncdb(verbosity, interactive=False)

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


def destroy_test_db(old_database_name, verbosity=1):
    # Unless we're using SQLite, remove the test database to clean up after
    # ourselves. Connect to the previous database (not the test database)
    # to do so, because it's not allowed to delete a database while being
    # connected to it.
    if verbosity >= 1:
        print "Destroying test database..."
    connection.close()
    TEST_DATABASE_NAME = settings.DATABASE_NAME
Esempio n. 4
0
def run_syncdb(verbosity=0):
    management.syncdb(verbosity, interactive=False)