summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSenko Rasic <senko.rasic@dobarkod.hr>2011-07-27 09:36:13 (GMT)
committerSenko Rasic <senko.rasic@dobarkod.hr>2011-07-27 14:05:55 (GMT)
commitdf1aa272038a32ed519ae06ce0df6a7f553eb8ef (patch)
tree72c2412ef4181e4228b0b65231f6d06d66d45eb3
parent021df7ce9673b8e17241d857a5d24f3e13561446 (diff)
downloadgst-qa-system-df1aa272038a32ed519ae06ce0df6a7f553eb8ef.tar.gz
gst-qa-system-df1aa272038a32ed519ae06ce0df6a7f553eb8ef.tar.xz
web: add test runner based on insanity.TestClient
-rw-r--r--web/insanityweb/management/commands/daemon.py7
-rw-r--r--web/insanityweb/runner.py130
2 files changed, 137 insertions, 0 deletions
diff --git a/web/insanityweb/management/commands/daemon.py b/web/insanityweb/management/commands/daemon.py
index 7d341ff..ccad625 100644
--- a/web/insanityweb/management/commands/daemon.py
+++ b/web/insanityweb/management/commands/daemon.py
@@ -10,6 +10,11 @@ import gobject
import sys
import os
+# Need to initialise it immediately because insanity.Client runs its
+# own mainloop, creates DBus service, etc. We also need to properly
+# quit it before exiting
+from insanityweb.runner import runner
+
class Command(BaseRunserverCommand):
args = ''
help = 'Start the Insanity integrated web + test runner'
@@ -19,6 +24,7 @@ class Command(BaseRunserverCommand):
server = WSGIServer((self.addr, int(self.port)), WSGIRequestHandler)
except WSGIServerException, e:
sys.stderr.write("ERROR: " + str(e) + "\n")
+ runner.quit()
return
# alidate models
@@ -45,6 +51,7 @@ class Command(BaseRunserverCommand):
server.handle_request()
except KeyboardInterrupt:
sys.stdout.write("Stopping the server...\n")
+ runner.quit()
gtk.main_quit()
return False
except Exception, e:
diff --git a/web/insanityweb/runner.py b/web/insanityweb/runner.py
new file mode 100644
index 0000000..9e78e9d
--- /dev/null
+++ b/web/insanityweb/runner.py
@@ -0,0 +1,130 @@
+from django.conf import settings
+
+import insanity
+import insanity.utils
+from insanity.client import TesterClient
+from insanity.testrun import TestRun
+from insanity.generators.filesystem import URIFileSystemGenerator
+
+from insanity.storage.sqlite import SQLiteStorage
+from insanity.log import debug
+
+import gobject
+
+class Client(TesterClient):
+
+ __software_name__ = 'Insanity web service'
+
+ def __init__(self, runner):
+ self.runner = runner
+ self.current_run = None
+ super(Client, self).__init__(singlerun=True)
+
+ def stop(self):
+ debug("Stopping...")
+ if not self._running:
+ debug("We were already stopping...")
+ return
+ self._running = False
+ try:
+ if self._current:
+ self._current.abort()
+ except Exception, e:
+ debug("Exception while aborting the current test: " + str(e))
+
+ def clearTestRuns(self):
+ if self._running:
+ self.stop()
+ self._testruns = []
+
+ def test_run_start(self, run):
+ self.current_run = run
+ run.connect('single-test-start', self.single_test_start_cb)
+ run.connect('single-test-done', self.single_test_done_cb)
+
+ def test_run_done(self, testrun):
+ debug("Test run done")
+ self.runner.test_run_done()
+
+ def single_test_start_cb(self, run, test):
+ debug("Test started: " + repr(test))
+ test.connect('check', self.test_check_cb)
+
+ def single_test_done_cb(self, run, test):
+ debug("Test done: " + repr(test))
+
+ def test_check_cb(self, test, item, validated):
+ run = self.current_run
+ run_index = run.getCurrentBatchPosition() - 1
+ run_length = run.getCurrentBatchLength()
+ test_pct = test.getSuccessPercentage()
+
+ pct = int((100.0 * run_index + test_pct) / run_length)
+ self.runner.test_progress_cb(run, test, pct, test_pct)
+
+class Runner(object):
+
+ def __init__(self):
+ self.client = Client(self)
+ self._clear_info()
+
+ def _clear_info(self):
+ self.test_name = None
+ self.test_folder = None
+ self.current_test = None
+ self.current_run = None
+ self.current_test_progress = None
+ self.current_run_progress = None
+ self.current_item = None
+
+ def get_test_names(self):
+ tests = [ t[0] for t in insanity.utils.list_available_tests() ]
+ tests.extend(t[0] for t in insanity.utils.list_available_scenarios())
+ return tests
+
+ def start_test(self, test, folder):
+ self.run = TestRun(maxnbtests=1)
+ self.test_class = insanity.utils.get_test_class(test)
+ self.run.addTest(self.test_class, arguments={
+ 'uri': URIFileSystemGenerator(paths=[folder], recursive=True)
+ })
+ self.client.addTestRun(self.run)
+
+ storage = SQLiteStorage(path=settings.DATABASES['default']['NAME'])
+ self.client.setStorage(storage)
+
+ self.current_run = self.run
+ self.current_run_progress = 0
+ self.test_name = test
+ self.test_folder = folder
+ debug("Running test: " + test)
+ self.client.run()
+
+ def stop_test(self):
+ debug("Stopping test")
+ self.client.stop()
+
+ def test_progress_cb(self, run, test, pct, test_pct):
+ self.current_run = run
+ self.current_test = test
+ self.current_run_progress = pct
+ self.current_test_progress = test_pct
+
+ def test_run_done(self):
+ debug("Test run done")
+ self._clear_info()
+ self.client.clearTestRuns()
+
+ def get_progress(self):
+ return self.current_run_progress
+
+ def get_test_name(self):
+ return self.test_name
+
+ def get_test_folder(self):
+ return self.test_folder
+
+ def quit(self):
+ self.client.quit()
+
+runner = Runner()