I hit the same thing and ended up creating a base class and setting
content-type in it. Eg:
class base(object):
def __init__(self):
web.header('Content-type', 'text/html')
class hello(base):
def GET(self):
return 'Hello, world!'
I feel like this shouldn't be necessary, though, so I'm happy to be
corrected with the proper way :).
On 31 Mayo, 12:32, Pete Emerson <[email protected]> wrote:
> I am trying to get the simplest paste/nose test running by
> followinghttp://webpy.org/cookbook/testing_with_paste_and_noseand it's failing
> for me in both Mac OS X and Ubuntu environments.
>
> First, my error message:
>
> $ WEBPY_ENV=test nosetests
> F
> ======================================================================
> FAIL: tests.test_code.TestCode.test_index
> ----------------------------------------------------------------------
> Traceback (most recent call last):
> File "/usr/lib/pymodules/python2.7/nose/case.py", line 186, in runTest
> self.test(*self.arg)
> File "/home/pete/python/sample/tests/test_code.py", line 9, in test_index
> r = testApp.get('/')
> File "/usr/lib/pymodules/python2.7/paste/fixture.py", line 208, in get
> return self.do_request(req, status=status)
> File "/usr/lib/pymodules/python2.7/paste/fixture.py", line 389, in
> do_request
> **req.environ)
> File "/usr/lib/pymodules/python2.7/paste/wsgilib.py", line 343, in
> raw_interactive
> app_iter = application(basic_environ, start_response)
> File "/usr/lib/pymodules/python2.7/paste/lint.py", line 170, in lint_app
> iterator = application(environ, start_response_wrapper)
> File "/usr/lib/pymodules/python2.7/web/application.py", line 293, in wsgi
> start_resp(status, headers)
> File "/usr/lib/pymodules/python2.7/paste/lint.py", line 161, in
> start_response_wrapper
> check_content_type(status, headers)
> File "/usr/lib/pymodules/python2.7/paste/lint.py", line 414, in
> check_content_type
> assert 0, "No Content-Type header found in headers (%s)" % headers
> AssertionError: No Content-Type header found in headers ([])
>
> ----------------------------------------------------------------------
> Ran 1 test in 0.070s
>
> FAILED (failures=1)
>
> I've got the following installed (this is under Ubuntu 11.04):
>
> ii python 2.7.1-0ubuntu5
> interactive high-level object-oriented language (default version)
> ii python-nose 0.11.4-0ubuntu1 test
> discovery and running for Python's unittest
> ii python-paste 1.7.5.1-1ubuntu1
> tools for using a Web Server Gateway Interface stack
> ii python-webpy 1:0.34-2 Web
> framework for Python applications
>
> Here is my code file structure (empty __init__.py):
>
> ./code.py
> ./test
> ./test/test_code.py
> ./test/__init__.py
>
> #### code.py ####
>
> import web
> import os
>
> urls = ("/.*", "hello")
> app = web.application(urls, globals())
>
> class hello:
> def GET(self):
> return 'Hello, world!'
>
> def is_test():
> if 'WEBPY_ENV' in os.environ:
> return os.environ['WEBPY_ENV'] == 'test'
>
> if (not is_test()) and __name__ == "__main__":
> app.run()
>
> #### test_code.py ####
>
> from paste.fixture import TestApp
> from nose.tools import *
> from code import app
>
> class TestCode():
> def test_index(self):
> middleware = []
> testApp = TestApp(app.wsgifunc(*middleware))
> r = testApp.get('/')
> assert_equal(r.status, 200)
> r.mustcontain('Hello, world!')
>
> Thanks in advance for all help,
> Pete
--
You received this message because you are subscribed to the Google Groups
"web.py" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/webpy?hl=en.