From 858925fcd34cc8ce58f73dae268be91a1a2c40bb Mon Sep 17 00:00:00 2001 From: "Dustin J. Mitchell" Date: Mon, 27 Jun 2011 18:13:46 -0500 Subject: [PATCH] Bug 666276: update unit tests to run against new clobberer; r=bhearsum --- clobberer/test_clobberer.py | 52 +++++++++++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/clobberer/test_clobberer.py b/clobberer/test_clobberer.py index 1f1c98ba8..b4c57ffce 100644 --- a/clobberer/test_clobberer.py +++ b/clobberer/test_clobberer.py @@ -1,4 +1,5 @@ from unittest import TestCase +import textwrap import sqlite3 import os import subprocess @@ -17,6 +18,52 @@ ### # Various utility functions for setting up a test case ### +def createDb(): + """Creates a test DB""" + db = sqlite3.connect(dbFile) + + creates = [ """\ + CREATE TABLE builds ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + master VARCHAR(100), + branch VARCHAR(50), + buildername VARCHAR(100), + builddir VARCHAR(100), + slave VARCHAR(30), + last_build_time INTEGER) + """, """ + CREATE TABLE clobber_times ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + master VARCHAR(100), + branch VARCHAR(50), + builddir VARCHAR(100), + slave VARCHAR(30), + lastclobber INTEGER, + who VARCHAR(50)) + """ ] + for cr in creates: + db.execute(cr) + db.commit() + +def setupCreds(): + creds_file = os.path.join(os.path.dirname(os.path.dirname(dbFile)), + "clobberer_creds.php") + if os.path.exists(creds_file): + # make sure it's a test creds, or don't delete it + if "generated by test_clobberer.py" not in open(creds_file).read(): + raise RuntimeError("foreign clobberer_creds.php file found") + open(creds_file, "w").write(textwrap.dedent("""\ + true) + $CLOBBERER_PDO_OPTIONS = array(); + ?> + """ % dbFile)) + def updateBuild(branch, buildername, builddir, slave, master): """Send an update to the server to indicate that a slave is doing a build. Returns the server's response.""" @@ -85,8 +132,9 @@ class TestClobber(TestCase): def setUp(self): if os.path.exists(dbFile): os.unlink(dbFile) - # Hit the clobberURL to create the database file - urllib.urlopen(clobberURL).read() + + createDb() + setupCreds() # Create a working directory if os.path.exists(testDir):