Skip to content
This repository has been archived by the owner on Sep 15, 2021. It is now read-only.

Commit

Permalink
Bug 666276: update unit tests to run against new clobberer; r=bhearsum
Browse files Browse the repository at this point in the history
  • Loading branch information
djmitche committed Jun 27, 2011
1 parent 02a8afc commit 858925f
Showing 1 changed file with 50 additions and 2 deletions.
52 changes: 50 additions & 2 deletions clobberer/test_clobberer.py
@@ -1,4 +1,5 @@
from unittest import TestCase
import textwrap
import sqlite3
import os
import subprocess
Expand All @@ -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("""\
<?php
// generated by test_clobberer.py
$CLOBBERER_DSN = "sqlite:%s";
$CLOBBERER_USERNAME = null;
$CLOBBERER_PASSWORD = null;
// for MySQL, use array(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => 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."""
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 858925f

Please sign in to comment.