]> scripts.mit.edu Git - wizard.git/commitdiff
Use legit drop-database interface.
authorEdward Z. Yang <ezyang@mit.edu>
Mon, 7 Dec 2009 07:55:51 +0000 (02:55 -0500)
committerEdward Z. Yang <ezyang@mit.edu>
Mon, 7 Dec 2009 18:55:16 +0000 (13:55 -0500)
* Remove accidentally committed tests/prepare file.
* Remove spurious prepare script; move the functionality
  into the dsn callback.

Signed-off-by: Edward Z. Yang <ezyang@mit.edu>
doc/testing.rst
tests/clean.sh
tests/prepare [deleted file]
tests/setup
wizard/app/__init__.py
wizard/install/__init__.py

index cabe3a989523de28dfaef6b85ec0edbd4eb9eb24..81d91fb6bae049a69738a90fa65e6a208fdd6aa1 100644 (file)
@@ -34,12 +34,14 @@ scripts servers, so long as the Wizard source tree is inside of your
 :file:`web_scripts` directory, and require some configuration if you
 plan on running them locally.
 
-Custom configuration can be specified in the :file:`config` file (located
-at :file:`tests/config`.  This is actually a Bash script to be sourced
-by the real test script (:file:`tests/setup`), which exports various
-environment variables that Wizard will use during installation.
+Custom configuration can be specified in the :file:`config` file (located at
+:file:`tests/config`).  This is actually a Bash script to be sourced by the
+real test script (:file:`tests/setup`), which exports various environment
+variables that Wizard will use during installation.  You should only need to
+set these variables if you're attempting to run these tests off of a
+non-scripts server.
 
-Here is a sample file::
+Here is a sample :file:`config` file::
 
     MYSQL_ARGS="-uroot -ppassword"
 
@@ -48,11 +50,11 @@ Here is a sample file::
     export WIZARD_DSN="mysql://root:password@localhost/wizard_test_$TESTID"
     export WIZARD_EMAIL="bob@example.com"
 
-You will need to specify all of these environment variables.  Those prefixed
-with ``WIZARD`` are directly used by Wizard, while the ``MYSQL`` environment
-variables are used if a test script wants to interactive directly with a
-MYSQL database.  We don't quite have a good story for alternative databases
-in test scripts.
+You will need to specify all of the environment variables in the
+:file:`config`.  Those prefixed with ``WIZARD`` are directly used by Wizard,
+while the ``MYSQL`` environment variables are used if a test script wants to
+interactive directly with a MYSQL database.  We don't quite have a good story
+for alternative databases in test scripts.
 
 * :envvar:`WIZARD_WEB_HOST` and :envvar:`WIZARD_WEB_PATH`  indicate Wizard's
   configuration with respect to your web server.
@@ -66,4 +68,3 @@ in test scripts.
   identify any particular test.
 * :envvar:`WIZARD_EMAIL` is any email address you
   own that will be configured as an administrative email.
-
index 26249265b5af81b6d5e3ab646acda874d199bc83..d0069edd51e50ed8c0602deaa231f784bfc630f7 100755 (executable)
@@ -1,2 +1,4 @@
 #!/bin/sh
-rm -Rf testdir*
+for i in testdir*; do
+    wizard remove "$i"
+done
diff --git a/tests/prepare b/tests/prepare
deleted file mode 100644 (file)
index 35ef0d9..0000000
+++ /dev/null
@@ -1 +0,0 @@
-mysql $MYSQL_ARGS -e "CREATE DATABASE \`wizard_test_$TESTID\`;"
index 5ad70ccbad46267174b50604b9f51635a5bc6e07..9e3d535f4c06b78d0e2e5bf979e7b6718a571524 100644 (file)
@@ -34,7 +34,3 @@ if [ -e "$TESTDIR" ]; then
     wizard remove "$TESTDIR" || rm -Rf "$TESTDIR"
 fi
 
-if [ -e "prepare" ]; then
-    source ./prepare
-fi
-
index a289cef4d237b82719a02cb6c002e44d33fefee6..597dbc0c9465d2181073cd9480b70a760c08ab4f 100644 (file)
@@ -603,8 +603,16 @@ def restore_mysql_database(backup_dir, deployment):
 
 def remove_database(deployment):
     """
-    Generic database removal function.
+    Generic database removal function.  Actually, not so generic because we
+    go and check if we're on scripts and if we are run a different command.
     """
+    sh = shell.Shell()
+    if deployment.dsn.host == "sql.mit.edu":
+        try:
+            sh.call("/mit/scripts/sql/bin/drop-database", deployment.dsn.database)
+            return
+        except shell.CallError:
+            pass
     engine = sqlalchemy.create_engine(deployment.dsn)
     engine.execute("DROP DATABASE `%s`" % deployment.dsn.database)
 
index 3c214a872e823f741050698fdc160dec57921cc8..2cac842bcdf43642db572e48de04df91ccec5b6f 100644 (file)
@@ -30,6 +30,14 @@ from wizard import scripts, shell, util
 def dsn_callback(options):
     if not isinstance(options.dsn, sqlalchemy.engine.url.URL):
         options.dsn = sqlalchemy.engine.url.make_url(options.dsn)
+    # perform some sanity checks on the database
+    database = options.dsn.database
+    options.dsn.database = None
+    engine = sqlalchemy.create_engine(options.dsn)
+    # generates warnings yeah yeah
+    engine.execute("CREATE DATABASE IF NOT EXISTS `%s`" % database)
+    options.dsn.database = database
+    # XXX: another good thing to check might be that the database is empty
 
 # XXX: This is in the wrong place
 def fetch(options, path, post=None):