1. Eric Larson
  2. Dad

Commits

Eric Larson  committed 241f578

Added a sample long running process for testing

  • Participants
  • Parent commits cfba55a
  • Branches default

Comments (0)

Files changed (3)

File configs/test.conf

View file
+[hello_world]
+command = hello_world
+instances = 2
+
+PYTHONPATH=$VIRTUAL_ENV/lib/python2.7/

File conftest.py

View file
 import subprocess
 import urllib
 import time
+import shutil
 
 from cherrypy.process.servers import check_port
 
 import py.test
 
+HERE = os.path.abspath(os.path.dirname(__file__))
+DAD_TEST_SANDBOXES = os.path.join(HERE, 'test_sandboxes')
+
+class TestApps(object):
+
+    def create_sandboxes(self):
+        sbox = os.path.join(DAD_TEST_SANDBOXES, 'hello_world', 'bin')
+        if not os.path.isdir(sbox):
+            os.makedirs(sbox)
+        return sbox
+
+    def deploy(self):
+        sbox = self.create_sandboxes()
+        dest = os.path.join(sbox, 'hello_world')
+        src = os.path.join(HERE, 'example/hello_world')
+        if not os.path.isfile(dest):
+            shutil.copy(src, dest)
+
+    def remove(self):
+        shutil.rmtree(DAD_TEST_SANDBOXES)
+
 
 class DevServer(object):
     port = 5000
     def start(self):
         cmd = os.path.join(sys.prefix, 'bin', 'dad.web')
         self.log.info('starting %s', cmd)
+
+        os.environ['DAD_SANDBOXES'] = DAD_TEST_SANDBOXES
+        os.environ['DAD_CONFIG'] = 'configs/test.conf'
         self.proc = subprocess.Popen([cmd], stdout=self.get_log())
 
         try:
 
 def pytest_namespace():
     dev_server = DevServer()
+    test_apps = TestApps()
     return vars()
 
 def pytest_configure(config):
     logging.basicConfig(level=logging.INFO)
+    py.test.test_apps.deploy()
     py.test.dev_server.start()
 
 def pytest_unconfigure(config):
-    py.test.dev_server.stop()    
+    py.test.dev_server.stop()
+    py.test.test_apps.remove()
     

File example/hello_world

View file
+#!/usr/bin/env python
+import os
+import cherrypy
+
+
+class HelloWorld(object):
+    def index(self):
+        return 'Hello World!'
+
+    index.exposed = True
+
+
+def run():
+    cherrypy.config.update({
+        'server.socket_host': os.environ.get('HOST', '127.0.0.1'),
+        'server.socket_port': int(os.environ.get('PORT', 8080)),
+    })
+
+
+    cherrypy.tree.mount(HelloWorld(), '/')
+    cherrypy.engine.start()
+    cherrypy.engine.block()
+
+
+if __name__ == '__main__':
+    run()
+