Changeset 4584

Show
Ignore:
Timestamp:
05/15/08 12:05:08 (6 months ago)
Author:
kskuhlman
Message:

Fixed problems in test suite where some modules were relying on requests to be created as a side-effect of other test modules. (They failed when tested standalone).

test_sqlobject.test_redirection:

cherrypy.HTTPRedirect isn't available outside of a request. Monkey-patched in a dummy request that doesn't have this dependancy as a fix. The other possibility would have been to switch the test over to be more of a functional test, creating a request & bringing the whole stack into test, but since the rest of test_sqlobject is a functional test, I decided to keep the style intact.

test_view.test_UnicodeValueAppearingInATemplateIsFine, and
test_view.test_default_output_encoding:

view.base.render sets the response header, which is impossible outside of a request. Added a setup method in test_view.TestView? to create dummy request & response objects. The dummy response object is a new (trivial) addition to testutil.

Discovered these while working on #1762.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.1/turbogears/tests/test_sqlobject.py

    r4356 r4584  
    11"""Tests for SQLObject database operations""" 
    22 
    3 from turbogears import database 
     3from turbogears import database, testutil 
    44from sqlobject import dbconnection 
    55import cherrypy 
     
    3737    finally: 
    3838        database.hub_registry.clear() 
     39 
     40 
     41class DummyRedirect(Exception): 
     42    pass 
    3943 
    4044 
     
    101105    dsi = DatabaseStandIn() 
    102106    database.hub_registry.add(dsi) 
     107    #The real cherrypy redirect is only available within a request, 
     108    # so monkey-patch in this dummy. 
     109    _http_redirect = cherrypy.HTTPRedirect 
     110    cherrypy.HTTPRedirect = DummyRedirect 
    103111    try: 
    104112        try: 
     
    111119    finally: 
    112120        database.hub_registry.clear() 
     121        cherrypy.HTTPRedirect = _http_redirect 
    113122 
    114123 
  • branches/1.1/turbogears/tests/test_view.py

    r4329 r4584  
    11# -*- coding: utf-8 -*- 
    22 
    3 from turbogears import view, config 
     3from turbogears import view, config, testutil 
     4import cherrypy 
    45import unittest 
    56 
    67class TestView(unittest.TestCase): 
     8 
     9    def setUp(self): 
     10        testutil.start_cp() 
     11        cherrypy.serving.request = testutil.DummyRequest() 
     12        cherrypy.serving.response = testutil.DummyResponse() 
    713 
    814    def test_cycle(self): 
  • branches/1.1/turbogears/testutil.py

    r4176 r4584  
    137137 
    138138 
     139class DummyResponse: 
     140    """A very simple dummy response.""" 
     141    headers = {} 
     142 
     143 
    139144def call(method, *args, **kw): 
    140145    start_cp()