From 4a85581cd937542d6f0cbcd7fbef2180575fd756 Mon Sep 17 00:00:00 2001 From: Ryan Petrello Date: Thu, 29 Aug 2013 15:57:48 -0400 Subject: Document and test the uwsgi plugin. Change-Id: I97449c5238ac8c8a9dbc334e628c4f7a414ff896 --- docs/source/deployment.rst | 13 ++----------- pecan/tests/scaffold_builder.py | 30 ++++++++++++++++++++++++------ tox.ini | 16 +++++++++------- 3 files changed, 35 insertions(+), 24 deletions(-) diff --git a/docs/source/deployment.rst b/docs/source/deployment.rst index 9cc1fec..96b1b3a 100644 --- a/docs/source/deployment.rst +++ b/docs/source/deployment.rst @@ -174,21 +174,12 @@ Running Pecan applications with uWSGI is a snap:: $ pip install uwsgi $ pecan create simpleapp && cd simpleapp $ python setup.py develop - -Next, let's create a new file in the project root:: - - # wsgi.py - from pecan.deploy import deploy - application = deploy('config.py') - -and then run it with:: - - $ uwsgi --http-socket 127.0.0.1:8000 -H /path/to/virtualenv -w wsgi + $ uwsgi --http-socket :8080 --venv /path/to/virtualenv --pecan config.py or using a Unix socket (that nginx, for example, could be configured to `proxy to `_):: - $ uwsgi -s /tmp/uwsgi.sock -H ../path/to/virtualenv -w wsgi + $ uwsgi -s /tmp/uwsgi.sock --venv /path/to/virtualenv --pecan config.py Gunicorn ++++++++ diff --git a/pecan/tests/scaffold_builder.py b/pecan/tests/scaffold_builder.py index e00b6da..563e762 100644 --- a/pecan/tests/scaffold_builder.py +++ b/pecan/tests/scaffold_builder.py @@ -96,9 +96,9 @@ if __name__ == '__main__': except: pass - class TestGunicornServeCommand(TestTemplateBuilds): + class TestThirdPartyServe(TestTemplateBuilds): - def poll_gunicorn(self, proc, port): + def poll_http(self, name, proc, port): try: self.poll(proc) retries = 30 @@ -106,8 +106,8 @@ if __name__ == '__main__': retries -= 1 if retries < 0: # pragma: nocover raise RuntimeError( - "The gunicorn server has not replied within" - " 3 seconds." + "The %s server has not replied within" + " 3 seconds." % name ) try: # ...and that it's serving (valid) content... @@ -123,6 +123,8 @@ if __name__ == '__main__': finally: proc.terminate() + class TestGunicornServeCommand(TestThirdPartyServe): + def test_serve_from_config(self): # Start the server proc = subprocess.Popen([ @@ -130,7 +132,7 @@ if __name__ == '__main__': 'testing123/config.py' ]) - self.poll_gunicorn(proc, 8080) + self.poll_http('gunicorn', proc, 8080) def test_serve_with_custom_bind(self): # Start the server @@ -140,7 +142,23 @@ if __name__ == '__main__': 'testing123/config.py' ]) - self.poll_gunicorn(proc, 9191) + self.poll_http('gunicorn', proc, 9191) + + class TestUWSGIServiceCommand(TestThirdPartyServe): + + def test_serve_from_config(self): + # Start the server + proc = subprocess.Popen([ + os.path.join(self.bin, 'uwsgi'), + '--http-socket', + ':8080', + '--venv', + sys.prefix, + '--pecan', + 'testing123/config.py' + ]) + + self.poll_http('uwsgi', proc, 8080) # First, ensure that the `testing123` package has been installed args = [ diff --git a/tox.ini b/tox.ini index 951b808..59106f4 100644 --- a/tox.ini +++ b/tox.ini @@ -4,10 +4,14 @@ envlist = py26,py27,py32,py33,scaffolds-26,scaffolds-27,scaffolds-32,scaffolds-3 [testenv] commands={envpython} setup.py test -v -[testenv:scaffolds-26] -basepython = python2.6 +[testenv:scaffolds-base] deps = pep8 gunicorn + uwsgi + +[testenv:scaffolds-26] +basepython = python2.6 +deps = {[testenv:scaffolds-base]deps} unittest2 changedir={envdir}/tmp commands=pecan create testing123 @@ -18,7 +22,7 @@ commands=pecan create testing123 [testenv:scaffolds-27] basepython = python2.7 -deps = {[testenv:scaffolds-26]deps} +deps = {[testenv:scaffolds-base]deps} changedir={[testenv:scaffolds-26]changedir} commands=pecan create testing123 {envpython} testing123/setup.py install @@ -28,8 +32,7 @@ commands=pecan create testing123 [testenv:scaffolds-32] basepython = python3.2 -deps = pep8 - gunicorn +deps = {[testenv:scaffolds-base]deps} changedir={[testenv:scaffolds-26]changedir} commands=pecan create testing123 curl "http://python-distribute.org/distribute_setup.py" -O @@ -41,8 +44,7 @@ commands=pecan create testing123 [testenv:scaffolds-33] basepython = python3.3 -deps = pep8 - gunicorn +deps = {[testenv:scaffolds-base]deps} changedir={[testenv:scaffolds-26]changedir} commands=pecan create testing123 curl "http://python-distribute.org/distribute_setup.py" -O -- cgit v1.2.1