Commits

desmaj committed 043403f

added SeleniumRC functional tests

Comments (0)

Files changed (5)

daemon/orbited/test/functional/__init__.py

+import sys
+
+TESTING_HOSTS = ['www.orbited', 'sub.www.orbited', 'xp.orbited']
+LOCALHOST = '127.0.0.1'
+
+class HostsFile(object):
+    HOSTS = '/etc/hosts'
+    
+    def __init__(self):
+        self._entries = {}
+    
+    def _with_file(self, body, *args, **kwargs):
+        f = file(*args, **kwargs)
+        result = body(f)
+        f.close()
+        return result
+    
+    def load(self):
+        return self._with_file(self._readlines, self.HOSTS, 'r')
+    
+    def _readlines(self, f):
+        for line in f.readlines():
+            self._readline(line)
+    
+    def _readline(self, line):
+        comment = None
+        if '#' in line:
+            line, comment = line.split('#')
+        parts = line.split()
+        if comment is not None:
+            parts[-1] += ' #' + comment
+        self._entries[parts[0]] = parts[1:]
+    
+    def store(self):
+        contents = str(self)
+        def writelines(f):
+                print >>f, contents
+        return with_file(writelines, HOSTS, 'r')
+    
+    def add(self, entry, alias):
+        self._entries.setdefault(entry, []).insert(0, alias)
+    
+    def remove(self, entry, alias):
+        if entry in self._entries:
+            self._entries[entry].remove(alias)
+            if not self._entries[entry]:
+                del self._entries[entry]
+    
+    def __str__(self):
+        return '\n'.join(['\t'.join([key, ' '.join(value)])
+                          for key, value in self._entries.items()])
+
+class OrbitedDaemon(object):
+    
+    def __init__(self):
+        pass
+    
+    def start(self):
+        pass
+    
+    def stop(self):
+        pass
+
+class SeleniumRCServer(object):
+    
+    def __init__(self):
+        pass
+    
+    def start(self):
+        pass
+    
+    def stop(self):
+        pass
+
+def main(argv):
+    hosts = HostsFile()
+    hosts.load()
+    print str(hosts)
+    for host in TESTING_HOSTS:
+        hosts.add(LOCALHOST, host)
+    print str(hosts)
+    for host in TESTING_HOSTS:
+        hosts.remove(LOCALHOST, host)
+    print str(hosts)
+    
+
+if (__name__=='__main__'):
+    main(sys.argv)
+
+orbited = OrbitedDaemon()
+selenium_rc = SeleniumRCServer()
+
+def setup():
+    hosts = HostsFile()
+    hosts.load()
+    for host in TESTING_HOSTS:
+        hosts.add(LOCALHOST, host)
+    hosts.store()
+    orbited.start()
+    selenium_rc.start()
+    
+def teardown():
+    selenium_rc.stop()
+    orbited.stop()
+    hosts = HostsFile()
+    hosts.load()
+    for host in TESTING_HOSTS:
+        hosts.remove(LOCALHOST, host)
+    hosts.store()

daemon/orbited/test/functional/test_cross_port_tcp_socket.py

+from selenium import selenium
+import unittest, time, re
+
+class TestCrossPortTCPSocket(unittest.TestCase):
+    def setUp(self):
+        self.verificationErrors = []
+        self.selenium = selenium("xp.orbited", 4444, "*chrome", "http://xp.orbited:8000/")
+        self.selenium.start()
+    
+    def test_same_domain_t_c_p_socket(self):
+        sel = self.selenium
+        sel.open("/static/tests/")
+        sel.click("link=Same Domain")
+        sel.wait_for_page_to_load("30000")
+        try: self.failUnless(sel.is_text_present(""))
+        except AssertionError, e: self.verificationErrors.append(str(e))
+        time.sleep(NaN)
+        try: self.failUnless(sel.is_text_present(""))
+        except AssertionError, e: self.verificationErrors.append(str(e))
+        try: self.failUnless(sel.is_text_present(""))
+        except AssertionError, e: self.verificationErrors.append(str(e))
+        try: self.failUnless(sel.is_text_present(""))
+        except AssertionError, e: self.verificationErrors.append(str(e))
+    
+    def tearDown(self):
+        self.selenium.stop()
+        self.assertEqual([], self.verificationErrors)
+
+if __name__ == "__main__":
+    unittest.main()

daemon/orbited/test/functional/test_cross_subdomain_tcp_socket.py

+from selenium import selenium
+import unittest, time, re
+
+class TestCrossSubDomainTCPSocket(unittest.TestCase):
+    def setUp(self):
+        self.verificationErrors = []
+        self.selenium = selenium("www.orbited", 4444, "*chrome", "http://www.orbited:8000/")
+        self.selenium.start()
+    
+    def test_same_domain_t_c_p_socket(self):
+        sel = self.selenium
+        sel.open("/static/tests/")
+        sel.click("link=Same Domain")
+        sel.wait_for_page_to_load("30000")
+        try: self.failUnless(sel.is_text_present(""))
+        except AssertionError, e: self.verificationErrors.append(str(e))
+        time.sleep(NaN)
+        try: self.failUnless(sel.is_text_present(""))
+        except AssertionError, e: self.verificationErrors.append(str(e))
+        try: self.failUnless(sel.is_text_present(""))
+        except AssertionError, e: self.verificationErrors.append(str(e))
+        try: self.failUnless(sel.is_text_present(""))
+        except AssertionError, e: self.verificationErrors.append(str(e))
+    
+    def tearDown(self):
+        self.selenium.stop()
+        self.assertEqual([], self.verificationErrors)
+
+if __name__ == "__main__":
+    unittest.main()

daemon/orbited/test/functional/test_same_domain_tcp_socket.py

+from selenium import selenium
+import unittest, time, re
+
+class TestSameDomainTCPSocket(unittest.TestCase):
+    def setUp(self):
+        self.verificationErrors = []
+        self.selenium = selenium("localhost", 4444, "*chrome", "http://localhost:8000/")
+        self.selenium.start()
+    
+    def test_same_domain_t_c_p_socket(self):
+        sel = self.selenium
+        sel.open("/static/tests/")
+        sel.click("link=Same Domain")
+        sel.wait_for_page_to_load("30000")
+        try: self.failUnless(sel.is_text_present(""))
+        except AssertionError, e: self.verificationErrors.append(str(e))
+        time.sleep(NaN)
+        try: self.failUnless(sel.is_text_present(""))
+        except AssertionError, e: self.verificationErrors.append(str(e))
+        try: self.failUnless(sel.is_text_present(""))
+        except AssertionError, e: self.verificationErrors.append(str(e))
+        try: self.failUnless(sel.is_text_present(""))
+        except AssertionError, e: self.verificationErrors.append(str(e))
+    
+    def tearDown(self):
+        self.selenium.stop()
+        self.assertEqual([], self.verificationErrors)
+
+if __name__ == "__main__":
+    unittest.main()

daemon/release.cfg

+[general]
+name = orbited
+version = 0.7.11
+author = Michael Carter
+author_email = CarterMichael@gmail.com
+maintainer = Matthew Desmarais
+maintainer_email = matthew.desmarais@gmail.com
+url = http://www.orbited.org
+license = MIT License
+description = 
+    A browser(javascript)->tcp bridge; Comet is used to emulate TCP connections
+    in the browser; Allows you to connect a web browser directly to an IRC or
+    XMPP server, for instance.
+long_description = '',
+zip_safe = False
+classifiers = 
+    Development Status :: 4 - Beta
+    Environment :: Console
+    Intended Audience :: Developers
+    License :: OSI Approved :: MIT License
+    Operating System :: OS Independent
+    Programming Language :: Python
+    Topic :: Software Development :: Libraries :: Python Modules
+package_data = 
+    *.js 
+    *.html
+    *.css 
+    *.ico 
+    *.gif 
+    *.jpg 
+    *.png 
+    *.txt*
+    *.py
+    *.template
+
+[distributions]
+eggs = 2.4 2.5 2.6 2.7 3.0 3.1
+source = True
+
+[entry_points:console_scripts]
+orbited = orbited.start:main
+
+[install_requires]
+morbid = ge 0.8.7.3
+twisted = eq 10.1
+
+[packages]
+setup = setuptools