Fix a bunch of tests.
authorJelmer Vernooij <jelmer@samba.org>
Fri, 3 Dec 2010 22:04:36 +0000 (23:04 +0100)
committerJelmer Vernooij <jelmer@samba.org>
Fri, 3 Dec 2010 22:04:36 +0000 (23:04 +0100)
buildfarm/sqldb.py
buildfarm/tests/__init__.py
buildfarm/tests/test_build.py
buildfarm/tests/test_buildfarm.py
buildfarm/tests/test_sqldb.py

index 4b53049..8c080ec 100644 (file)
@@ -157,7 +157,8 @@ class StormHostDatabase(HostDatabase):
         return self.store.find(StormHost).order_by(StormHost.name)
 
     def __getitem__(self, name):
-        result = self.store.find(StormHost, Cast(StormHost.name, "TEXT") == Cast(name, "TEXT"))
+        result = self.store.find(StormHost,
+            Cast(StormHost.name, "TEXT") == Cast(name, "TEXT"))
         ret = result.one()
         if ret is None:
             raise NoSuchHost(name)
@@ -178,7 +179,8 @@ class StormCachingBuildResultStore(BuildResultStore):
         self.store = store
 
     def get_by_checksum(self, checksum):
-        result = self.store.find(StormBuild, Cast(StormBuild.checksum, "TEXT") == checksum)
+        result = self.store.find(StormBuild,
+            Cast(StormBuild.checksum, "TEXT") == checksum)
         ret = result.one()
         if ret is None:
             raise NoSuchBuildError(None, None, None, None)
@@ -192,20 +194,13 @@ class StormCachingBuildResultStore(BuildResultStore):
             return False
 
     def get_previous_revision(self, tree, host, compiler, revision):
-        result = self.store.find(StormBuild,
-            StormBuild.tree == tree,
-            StormBuild.host == host,
-            StormBuild.compiler == compiler,
-            Cast(StormBuild.revision, "TEXT") == revision)
-        cur_build = result.any()
-        if cur_build is None:
-            raise NoSuchBuildError(tree, host, compiler, revision)
+        cur_build = self.get_build(tree, host, compiler, revision)
 
         result = self.store.find(StormBuild,
-            StormBuild.tree == tree,
-            StormBuild.host == host,
-            StormBuild.compiler == compiler,
-            Cast(StormBuild.revision, "TEXT") != revision,
+            Cast(StormBuild.tree, "TEXT") == Cast(tree, "TEXT"),
+            Cast(StormBuild.host, "TEXT") == Cast(host, "TEXT"),
+            Cast(StormBuild.compiler, "TEXT") == Cast(compiler, "TEXT"),
+            Cast(StormBuild.revision, "TEXT") != Cast(revision, "TEXT"),
             StormBuild.id < cur_build.id)
         result = result.order_by(Desc(StormBuild.id))
         prev_build = result.first()
@@ -245,8 +240,10 @@ class StormCachingBuildResultStore(BuildResultStore):
         new_build.upload_time = build.upload_time
         new_build.status_str = build.status().__serialize__()
         new_build.basename = new_basename
-        new_build.host = self.store.find(
-            StormHost, Cast(StormHost.name, "TEXT") == build.host).one()
+        host = self.store.find(StormHost,
+            Cast(StormHost.name, "TEXT") == Cast(build.host, "TEXT")).one()
+        assert host is not None, "Unable to find host %r" % build.host
+        new_build.host_id = host.id
         self.store.add(new_build)
         return new_build
 
@@ -259,14 +256,14 @@ class StormCachingBuildResultStore(BuildResultStore):
 
     def get_build(self, tree, host, compiler, revision=None, checksum=None):
         expr = [
-            StormBuild.tree == tree,
-            StormBuild.host == host,
-            StormBuild.compiler == compiler,
+            Cast(StormBuild.tree, "TEXT") == Cast(tree, "TEXT"),
+            Cast(StormBuild.host, "TEXT") == Cast(host, "TEXT"),
+            Cast(StormBuild.compiler, "TEXT") == Cast(compiler, "TEXT"),
             ]
         if revision is not None:
-            expr.append(Cast(StormBuild.revision, "TEXT") == revision)
+            expr.append(Cast(StormBuild.revision, "TEXT") == Cast(revision, "TEXT"))
         if checksum is not None:
-            expr.append(Cast(StormBuild.checksum, "TEXT") == checksum)
+            expr.append(Cast(StormBuild.checksum, "TEXT") == Cast(checksum, "TEXT"))
         result = self.store.find(StormBuild, *expr).order_by(Desc(StormBuild.upload_time))
         ret = result.first()
         if ret is None:
@@ -312,7 +309,8 @@ class StormCachingBuildFarm(BuildFarm):
         return distinct_builds(result.order_by(Desc(StormBuild.upload_time)))
 
     def get_tree_builds(self, tree):
-        result = self._get_store().find(StormBuild, Cast(StormBuild.tree, "TEXT") == tree)
+        result = self._get_store().find(StormBuild,
+            Cast(StormBuild.tree, "TEXT") == Cast(tree, "TEXT"))
         return distinct_builds(result.order_by(Desc(StormBuild.upload_time)))
 
     def get_last_builds(self):
@@ -321,8 +319,8 @@ class StormCachingBuildFarm(BuildFarm):
 
     def get_revision_builds(self, tree, revision=None):
         return self._get_store().find(StormBuild,
-            Cast(StormBuild.tree, "TEXT") == tree,
-            Cast(StormBuild.revision, "TEXT") == revision)
+            Cast(StormBuild.tree, "TEXT") == Cast(tree, "TEXT"),
+            Cast(StormBuild.revision, "TEXT") == Cast(revision, "TEXT"))
 
     def commit(self):
         self.store.commit()
index 964e750..6cbad64 100644 (file)
@@ -101,6 +101,8 @@ class BuildFarmTestCase(TestCase):
         store = Store(db)
         setup_schema(store)
         store.commit()
+        self.write_compilers([])
+        self.write_hosts({})
 
     def tearDown(self):
         shutil.rmtree(self.path)
index 2dce9a3..9b173ec 100755 (executable)
@@ -29,6 +29,7 @@ from buildfarm.build import (
     build_status_from_logs,
     )
 
+from buildfarm import BuildFarm
 from buildfarm.tests import BuildFarmTestCase
 
 
@@ -41,6 +42,11 @@ class NonexistantTests(unittest.TestCase):
 
 class BuildResultStoreTestBase(object):
 
+    def setUp(self):
+        self.write_compilers(["cc", "gcc"])
+        self.write_hosts({"charis": "Some machine",
+                          "myhost": "Another host"})
+
     def test_build_fname(self):
         self.assertEquals(
             self.x.build_fname("mytree", "myhost", "cc", 123),
@@ -172,7 +178,10 @@ BUILD COMMIT REVISION: 15
 class BuildResultStoreTests(BuildFarmTestCase,BuildResultStoreTestBase):
 
     def setUp(self):
-        super(BuildResultStoreTests, self).setUp()
+        BuildFarmTestCase.setUp(self)
+        BuildResultStoreTestBase.setUp(self)
+
+        self.buildfarm = BuildFarm(self.path)
 
         self.x = BuildResultStore(
             os.path.join(self.path, "data", "oldrevs"))
index 70b8cce..49e5051 100644 (file)
@@ -75,7 +75,8 @@ class BuildFarmTestBase(object):
 
     def setUp(self):
         self.write_compilers(["cc"])
-        self.write_hosts({"myhost": "Fedora"})
+        self.write_hosts({"myhost": "Fedora",
+                          "charis": "Debian"})
         self.write_trees({"trivial": {"scm": "git", "repo": "git://foo", "branch": "master"},
                           "other": {"scm": "git", "repo": "other.git", "branch": "HEAD"}})
 
@@ -129,7 +130,7 @@ class BuildFarmTestBase(object):
 
     def test_get_build_rev(self):
         path = self.upload_mock_logfile(self.x.builds, "tdb", "charis", "cc",
-            stdout_contents="This is what a log file looks like.\n"
+            stdout_contents="tHIS is what a log file looks like.\n"
             "BUILD COMMIT REVISION: 12\n")
         build = self.x.get_build("tdb", "charis", "cc", "12")
         self.assertEquals("tdb", build.tree)
index 0b5dc64..42b0f1d 100644 (file)
@@ -25,14 +25,23 @@ from buildfarm.tests.test_build import BuildResultStoreTestBase
 from buildfarm.tests.test_hostdb import HostDatabaseTests
 from buildfarm.sqldb import (
     StormHostDatabase,
-    StormCachingBuildResultStore,
     StormCachingBuildFarm,
     )
 
-import os
 import testtools
 
 
+class StormCachingBuildFarmTestCase(BuildFarmTestCase):
+
+    def setUp(self):
+        super(StormCachingBuildFarmTestCase, self).setUp()
+        self.buildfarm = StormCachingBuildFarm(self.path)
+
+    def write_hosts(self, hosts):
+        for host in hosts:
+            self.buildfarm.hostdb.createhost(host)
+
+
 class StormHostDatabaseTests(testtools.TestCase, HostDatabaseTests):
 
     def setUp(self):
@@ -40,13 +49,12 @@ class StormHostDatabaseTests(testtools.TestCase, HostDatabaseTests):
         self.db = StormHostDatabase()
 
 
-class StormCachingBuildResultStoreTests(BuildFarmTestCase,BuildResultStoreTestBase):
+class StormCachingBuildResultStoreTests(StormCachingBuildFarmTestCase,BuildResultStoreTestBase):
 
     def setUp(self):
-        super(StormCachingBuildResultStoreTests, self).setUp()
-
-        self.x = StormCachingBuildResultStore(
-            os.path.join(self.path, "data", "oldrevs"))
+        StormCachingBuildFarmTestCase.setUp(self)
+        BuildResultStoreTestBase.setUp(self)
+        self.x = self.buildfarm.builds
 
     def test_get_previous_revision_result(self):
         path = self.create_mock_logfile("tdb", "charis", "cc", contents="""
@@ -70,9 +78,9 @@ BUILD COMMIT REVISION: myrev
 
 
 
-class StormCachingBuildFarmTests(BuildFarmTestBase, BuildFarmTestCase):
+class StormCachingBuildFarmTests(BuildFarmTestBase, StormCachingBuildFarmTestCase):
 
     def setUp(self):
-        BuildFarmTestCase.setUp(self)
+        StormCachingBuildFarmTestCase.setUp(self)
         BuildFarmTestBase.setUp(self)
-        self.x = StormCachingBuildFarm(self.path)
+        self.x = self.buildfarm