Author: justi9
Date: 2008-02-08 13:12:41 -0500 (Fri, 08 Feb 2008)
New Revision: 1666
Added:
mgmt/cumin/python/cumin/test.py
Log:
Checkpoint commit of cumin tests.
Added: mgmt/cumin/python/cumin/test.py
===================================================================
--- mgmt/cumin/python/cumin/test.py (rev 0)
+++ mgmt/cumin/python/cumin/test.py 2008-02-08 18:12:41 UTC (rev 1666)
@@ -0,0 +1,166 @@
+import sys, os
+from mint import *
+from traceback import print_exc
+from datetime import datetime
+from wooly import Session
+
+from cumin import Cumin
+import time
+
+class TestEnvironment(object):
+ def __init__(self, app, broker_address):
+ self.app = app
+ self.broker_address = broker_address
+ self.broker = None
+
+class TestSession(object):
+ def __init__(self, env):
+ self.env = env
+
+ self.successes = list()
+ self.failures = list()
+
+ def add_success(self, test, message, exception):
+ result = TestResult(test, message, exception)
+ self.successes.append(result)
+
+ def add_failure(self, test, message, exception):
+ if exception:
+ print_exc()
+
+ result = TestResult(test, message, exception)
+ self.failures.append(result)
+
+ def report(self, out):
+ out.write("Succcesses (%i)\n" % len(self.successes))
+
+ for succcess in self.successes:
+ out.write(" %s\n" % success)
+
+ out.write("Failures (%i)\n" % len(self.failures))
+
+ for failure in self.failures:
+ out.write(" %s\n" % failure)
+
+class TestResult(object):
+ def __init__(self, test, message, exception):
+ self.test = test
+ self.message = message
+ self.exception = exception
+
+ def __repr__(self):
+ return "%s: %s" % (self.test, self.message)
+
+class Test(object):
+ def __init__(self, env, parent):
+ self.env = env
+ self.parent = parent
+ self.children = list()
+
+ if parent:
+ self.parent.children.append(self)
+
+ def run(self, session):
+ try:
+ self.do_run(session)
+ except Exception, e:
+ session.add_failure(self, e.message, e)
+
+ def do_run(self, session):
+ self.run_children(session)
+
+ def run_children(self, session):
+ for child in self.children:
+ child.run(session)
+
+ def __repr__(self):
+ return self.__class__.__name__
+
+class MainTest(Test):
+ def __init__(self, env):
+ super(MainTest, self).__init__(env, None)
+
+ BrokerTest(env, self)
+
+class BrokerTest(Test):
+ def __init__(self, env, parent):
+ super(BrokerTest, self).__init__(env, parent)
+
+ QueueTest(env, self)
+
+ def do_run(self, session):
+ app = self.env.app
+ page = app.main_page
+
+ s = Session(app)
+ s.set_page(page)
+
+ # navigate from ui top to broker set add
+
+ form = page.show_main(s).show_brokers_add(s)
+
+ name = "test-" + datetime.now().strftime("%Y-%m-%d-%H-%M")
+
+ form.names.get(s).append(name)
+ form.addrs.get(s).append(self.env.broker_address)
+ form.groups.get(s).append(None)
+ form.submit.set(s, True)
+
+ page.process(s, None)
+
+ redirect = page.get_redirect_url(s)
+
+ if redirect:
+ s = Session(app)
+ s.unmarshal(redirect)
+
+ page.process(s, None)
+
+ html = page.render(s, None)
+
+ file = open("BrokerTest.%s.html" % name, "w")
+ file.write(html)
+ file.close()
+
+ reg = BrokerRegistration.selectBy(name=name)[0]
+
+ wait(lambda: reg.broker)
+
+ self.env.broker = reg.broker
+
+ self.run_children(session)
+
+class QueueTest(Test):
+ def do_run(self, session):
+ print self.env.broker
+
+def wait(predicate, timeout=30):
+ start = time.time()
+
+ while True:
+ time.sleep(1)
+
+ if predicate():
+ return
+
+ if time.time() - start > timeout:
+ print "Operation timed out"
+ return
+
+def main():
+ home = os.environ["CUMIN_HOME"]
+ data = "postgresql://cumin@localhost/cumin"
+ app = Cumin(home, data)
+
+ app.init()
+
+ env = TestEnvironment(app, "qpid-test3.lab.boston.redhat.com")
+ session = TestSession(env)
+ main = MainTest(env)
+
+ main.run(session)
+
+ session.report(sys.stdout)
+
+if __name__ == "__main__":
+ main()