diff options
| author | ianb <devnull@localhost> | 2005-08-15 16:49:21 +0000 |
|---|---|---|
| committer | ianb <devnull@localhost> | 2005-08-15 16:49:21 +0000 |
| commit | 855296d30ad93e655ef75812d9f1a96bc629d4da (patch) | |
| tree | 46ce6255d1be8678e8aa99c0b187b2a55e62027a /paste/tests | |
| parent | b146bb5a4942bf2f531975068357de35197d9a17 (diff) | |
| download | paste-855296d30ad93e655ef75812d9f1a96bc629d4da.tar.gz | |
Added CGI proxy application
Diffstat (limited to 'paste/tests')
| -rwxr-xr-x | paste/tests/cgiapp_data/error.cgi | 3 | ||||
| -rwxr-xr-x | paste/tests/cgiapp_data/form.cgi | 12 | ||||
| -rwxr-xr-x | paste/tests/cgiapp_data/ok.cgi | 6 | ||||
| -rwxr-xr-x | paste/tests/cgiapp_data/stderr.cgi | 8 | ||||
| -rw-r--r-- | paste/tests/test_cgiapp.py | 35 |
5 files changed, 64 insertions, 0 deletions
diff --git a/paste/tests/cgiapp_data/error.cgi b/paste/tests/cgiapp_data/error.cgi new file mode 100755 index 0000000..5afc9c9 --- /dev/null +++ b/paste/tests/cgiapp_data/error.cgi @@ -0,0 +1,3 @@ +#!/usr/bin/env python + +print 'hey you!' diff --git a/paste/tests/cgiapp_data/form.cgi b/paste/tests/cgiapp_data/form.cgi new file mode 100755 index 0000000..6d2e038 --- /dev/null +++ b/paste/tests/cgiapp_data/form.cgi @@ -0,0 +1,12 @@ +#!/usr/bin/env python + +import cgi + +print 'Content-type: text/plain' +print + +form = cgi.FieldStorage() + +print 'Filename:', form['up'].filename +print 'Name:', form['name'].value +print 'Content:', form['up'].file.read() diff --git a/paste/tests/cgiapp_data/ok.cgi b/paste/tests/cgiapp_data/ok.cgi new file mode 100755 index 0000000..8b8eb29 --- /dev/null +++ b/paste/tests/cgiapp_data/ok.cgi @@ -0,0 +1,6 @@ +#!/usr/bin/env python + +print 'Content-type: text/html; charset=UTF-8' +print 'Status: 200 Okay' +print +print 'This is the body' diff --git a/paste/tests/cgiapp_data/stderr.cgi b/paste/tests/cgiapp_data/stderr.cgi new file mode 100755 index 0000000..89dae0a --- /dev/null +++ b/paste/tests/cgiapp_data/stderr.cgi @@ -0,0 +1,8 @@ +#!/usr/bin/env python + +import sys +print 'Status: 500 Server Error' +print 'Content-type: text/html' +print +print 'There was an error' +print >> sys.stderr, 'some data on the error' diff --git a/paste/tests/test_cgiapp.py b/paste/tests/test_cgiapp.py new file mode 100644 index 0000000..133cd87 --- /dev/null +++ b/paste/tests/test_cgiapp.py @@ -0,0 +1,35 @@ +import os +import py.test +from paste.cgiapp import CGIApplication, CGIError +from fixture import * +del setup_module + +data_dir = os.path.join(os.path.dirname(__file__), 'cgiapp_data') + + +def test_ok(): + app = TestApp(CGIApplication('ok.cgi', [data_dir])) + res = app.get('') + assert res.header('content-type') == 'text/html; charset=UTF-8' + assert res.full_status == '200 Okay' + assert 'This is the body' in res + +def test_form(): + app = TestApp(CGIApplication('form.cgi', [data_dir])) + res = app.post('', params={'name': 'joe'}, + upload_files=[('up', 'file.txt', 'x'*10000)]) + assert 'file.txt' in res + assert 'joe' in res + assert 'x'*10000 in res + +def test_error(): + app = TestApp(CGIApplication('error.cgi', [data_dir])) + py.test.raises(CGIError, "app.get('', status=500)") + +def test_stderr(): + app = TestApp(CGIApplication('stderr.cgi', [data_dir])) + res = app.get('', expect_errors=True) + assert res.status == 500 + assert 'error' in res + assert 'some data' in res.errors + |
