Add buildfarm.web tests.
authorJelmer Vernooij <jelmer@samba.org>
Mon, 15 Nov 2010 15:30:50 +0000 (16:30 +0100)
committerJelmer Vernooij <jelmer@samba.org>
Mon, 15 Nov 2010 15:30:50 +0000 (16:30 +0100)
buildfarm/web/__init__.py
buildfarm/web/tests/__init__.py [new file with mode: 0644]
buildfarm/web/tests/test_util.py [new file with mode: 0644]

index 33165dca8b8a0dc75d66de2560a168ff95c19df3..dda4b17ee026d23ffa195ba3106658d0b329dd85 100755 (executable)
@@ -682,6 +682,41 @@ class ViewRecentBuildsPage(BuildFarmPage):
 
 class ViewHostPage(BuildFarmPage):
 
+    def _render_build(self, myself, build):
+        try:
+            (revision, revision_time) = build.revision_details()
+        except data.MissingRevisionInfo:
+            revision = None
+        age_mtime = build.age_mtime()
+        age_ctime = build.age_ctime()
+        warnings = build.err_count()
+        status = build_status_html(myself, build)
+        if row == 0:
+            if output_type == 'text':
+                yield "%-12s %-10s %-10s %-10s %-10s\n" % (
+                        "Tree", "Compiler", "Build Age", "Status", "Warnings")
+            else:
+                yield "<div class='host summary'>"
+                yield "<a id='host' name='host'/>"
+                yield "<h3>%s - %s</h3>" % (host, self.buildfarm.hostdb.host(host).platform.encode("utf-8"))
+                yield "<table class='real'>"
+                yield "<thead><tr><th>Target</th><th>Build<br/>Revision</th><th>Build<br />Age</th><th>Status<br />config/build<br />install/test</th><th>Warnings</th></tr></thead>"
+                yield "<tbody>"
+
+        if output_type == 'text':
+            yield "%-12s %-10s %-10s %-10s %-10s\n" % (
+                    tree, compiler, util.dhm_time(age_mtime),
+                    util.strip_html(status), warnings)
+        else:
+            yield "<tr>"
+            yield "<td><span class='tree'>" + self.tree_link(myself, tree) +"</span>/" + compiler + "</td>"
+            yield "<td>" + revision_link(myself, revision, tree) + "</td>"
+            yield "<td><div class='age'>" + self.red_age(age_mtime) + "</div></td>"
+            yield "<td><div class='status'>%s</div></td>" % status
+            yield "<td>%s</td>" % warnings
+            yield "</tr>"
+        row+=1
+
     def render(self, myself, output_type, *requested_hosts):
         """print the host's table of information"""
 
@@ -699,7 +734,6 @@ class ViewHostPage(BuildFarmPage):
                 continue
 
             row = 0
-
             for compiler in self.buildfarm.compilers:
                 for tree in sorted(self.buildfarm.trees.keys()):
                     try:
@@ -707,39 +741,8 @@ class ViewHostPage(BuildFarmPage):
                     except data.NoSuchBuildError:
                         pass
                     else:
-                        try:
-                            (revision, revision_time) = build.revision_details()
-                        except data.MissingRevisionInfo:
-                            revision = None
-                        age_mtime = build.age_mtime()
-                        age_ctime = build.age_ctime()
-                        warnings = build.err_count()
-                        status = build_status_html(myself, build)
-                        if row == 0:
-                            if output_type == 'text':
-                                yield "%-12s %-10s %-10s %-10s %-10s\n" % (
-                                        "Tree", "Compiler", "Build Age", "Status", "Warnings")
-                            else:
-                                yield "<div class='host summary'>"
-                                yield "<a id='host' name='host'/>"
-                                yield "<h3>%s - %s</h3>" % (host, self.buildfarm.hostdb.host(host).platform.encode("utf-8"))
-                                yield "<table class='real'>"
-                                yield "<thead><tr><th>Target</th><th>Build<br/>Revision</th><th>Build<br />Age</th><th>Status<br />config/build<br />install/test</th><th>Warnings</th></tr></thead>"
-                                yield "<tbody>"
-
-                        if output_type == 'text':
-                            yield "%-12s %-10s %-10s %-10s %-10s\n" % (
-                                    tree, compiler, util.dhm_time(age_mtime),
-                                    util.strip_html(status), warnings)
-                        else:
-                            yield "<tr>"
-                            yield "<td><span class='tree'>" + self.tree_link(myself, tree) +"</span>/" + compiler + "</td>"
-                            yield "<td>" + revision_link(myself, revision, tree) + "</td>"
-                            yield "<td><div class='age'>" + self.red_age(age_mtime) + "</div></td>"
-                            yield "<td><div class='status'>%s</div></td>" % status
-                            yield "<td>%s</td>" % warnings
-                            yield "</tr>"
-                        row+=1
+                        self._render_build(myself, build)
+
             if row != 0:
                 if output_type == 'text':
                     yield "\n"
diff --git a/buildfarm/web/tests/__init__.py b/buildfarm/web/tests/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/buildfarm/web/tests/test_util.py b/buildfarm/web/tests/test_util.py
new file mode 100644 (file)
index 0000000..d507edd
--- /dev/null
@@ -0,0 +1,29 @@
+#!/usr/bin/python
+# Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2010
+#
+#   This program is free software; you can redistribute it and/or modify
+#   it under the terms of the GNU General Public License as published by
+#   the Free Software Foundation; either version 3 of the License, or
+#   (at your option) any later version.
+#
+#   This program is distributed in the hope that it will be useful,
+#   but WITHOUT ANY WARRANTY; without even the implied warranty of
+#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#   GNU General Public License for more details.
+#
+#   You should have received a copy of the GNU General Public License
+#   along with this program; if not, write to the Free Software
+#   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+import testtools
+from buildfarm.web import build_link
+
+
+class BuildLinkTests(testtools.TestCase):
+
+    def test_build_link_no_rev(self):
+        self.assertEquals("<a href='myself?function=View+Build;host=charis;tree=tdb;compiler=gcc'>status</a>", build_link("myself", "tdb", "charis", "gcc", None, "status"))
+
+
+    def test_build_link_rev(self):
+        self.assertEquals("<a href='myself?function=View+Build;host=charis;tree=tdb;compiler=gcc;revision=42'>status</a>", build_link("myself", "tdb", "charis", "gcc", "42", "status"))