~kernevil/ubuntu/saucy/pylons/fix-useless-import

« back to all changes in this revision

Viewing changes to tests/test_units/test_deprecated.py

  • Committer: Bazaar Package Importer
  • Author(s): Piotr Ożarowski
  • Date: 2011-08-02 21:17:36 UTC
  • mfrom: (1.2.3 upstream) (10.1.3 experimental)
  • Revision ID: james.westby@ubuntu.com-20110802211736-ejqil9b3yqgxt6lr
Tags: 1.0-2
* Add ipython_0.11_compatibility patch (thanks to Julian Taylor)
* Add build-arch and build-indep targets to debian/rules 
* Switch from dh_pysupport to dh_python2
* Source format changed to 3.0 (quilt)
* Standards-Version bumped to 3.9.2 (no changes needed)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
import warnings
2
 
from unittest import TestCase
3
 
 
4
 
from paste.fixture import TestApp
5
 
from paste.httpexceptions import HTTPMovedPermanently
6
 
from paste.registry import RegistryManager
7
 
 
8
 
import pylons
9
 
from pylons.controllers import WSGIController
10
 
from pylons.controllers.util import etag_cache
11
 
from pylons.decorators import jsonify as orig_jsonify
12
 
from pylons.util import ContextObj
13
 
 
14
 
from __init__ import ControllerWrap, SetupCacheGlobal, TestWSGIController
15
 
 
16
 
class SimpleTestWSGIController(TestWSGIController):
17
 
    wsgi_app = None
18
 
    def __init__(self, *args, **kargs):
19
 
        TestWSGIController.__init__(self, *args, **kargs)
20
 
        self.baseenviron = {}
21
 
        app = ControllerWrap(self.wsgi_app)
22
 
        app = self.sap = SetupCacheGlobal(app, self.baseenviron)
23
 
        app = RegistryManager(app)
24
 
        self.app = TestApp(app)
25
 
        
26
 
    def setUp(self):
27
 
        TestWSGIController.setUp(self)
28
 
        self.baseenviron.update(self.environ)
29
 
 
30
 
 
31
 
class HelpersController(WSGIController):
32
 
    def imports(self):
33
 
        import pylons.controllers.util
34
 
        self.helpers = pylons.controllers.util
35
 
 
36
 
    def abort(self):
37
 
        self.helpers.abort(404)
38
 
 
39
 
    def etag_cache(self):
40
 
        self.helpers.etag_cache('hello')
41
 
        return 'etag cache'
42
 
 
43
 
    def redirect_to(self):
44
 
        self.helpers.redirect_to('/etag_cache')
45
 
 
46
 
class TestDeprecatedHelpers(SimpleTestWSGIController):
47
 
    wsgi_app = HelpersController()
48
 
 
49
 
    def setUp(self):
50
 
        warnings.simplefilter('ignore', DeprecationWarning)
51
 
        self.wsgi_app.imports()
52
 
        warnings.simplefilter('error', DeprecationWarning)
53
 
    
54
 
    def tearDown(self):
55
 
        warnings.simplefilter('always', DeprecationWarning)
56
 
 
57
 
 
58
 
 
59
 
class MiscLegacyController(WSGIController):
60
 
 
61
 
    def legacy_httpexception(self):
62
 
        raise HTTPMovedPermanently('/elsewhere')
63
 
 
64
 
    def legacy_etag_cache(self):
65
 
        # used to crash
66
 
        response = etag_cache('test')
67
 
        response.body = 'from etag_cache'
68
 
        return response
69
 
 
70
 
 
71
 
class TestMiscLegacy(SimpleTestWSGIController):
72
 
    wsgi_app = MiscLegacyController
73
 
 
74
 
    def setUp(self):
75
 
        SimpleTestWSGIController.setUp(self)
76
 
        warnings.simplefilter('error', DeprecationWarning)
77
 
 
78
 
    def tearDown(self):
79
 
        SimpleTestWSGIController.tearDown(self)
80
 
        warnings.simplefilter('always', DeprecationWarning)
81
 
 
82
 
    # def test_legacy_return_etag_cache(self):
83
 
    #     warnings.simplefilter('always', DeprecationWarning)
84
 
    # 
85
 
    #     self.baseenviron['pylons.routes_dict']['action'] = 'legacy_etag_cache'
86
 
    #     response = self.app.get('/')
87
 
    #     assert 'from etag_cache' in response