diff options
| author | bbangert <devnull@localhost> | 2006-03-10 21:24:58 +0000 |
|---|---|---|
| committer | bbangert <devnull@localhost> | 2006-03-10 21:24:58 +0000 |
| commit | 2659c4a3ea4d0dd0b1b2121f6b63ebb12a1c4f49 (patch) | |
| tree | a2ba5741e98ab1f4b85709835fc20c83d437eada /tests/test_registry.py | |
| parent | 7ff7a257d9eab338ec849b98f1579a4fdbf97b53 (diff) | |
| download | paste-2659c4a3ea4d0dd0b1b2121f6b63ebb12a1c4f49.tar.gz | |
Fixes iterable issue by using new IterWrap, likely need to break it into wsgilib still, added test case for iterable app
Diffstat (limited to 'tests/test_registry.py')
| -rw-r--r-- | tests/test_registry.py | 76 |
1 files changed, 66 insertions, 10 deletions
diff --git a/tests/test_registry.py b/tests/test_registry.py index 87966dd..bf4f507 100644 --- a/tests/test_registry.py +++ b/tests/test_registry.py @@ -22,18 +22,39 @@ class RegistryUsingApp(object): start_response(status, response_headers) return ['Hello world!\nThe variable is %s' % str(testobj)] +class RegistryUsingIteratorApp(object): + def __init__(self, var, value): + self.var = var + self.value = value + + def __call__(self, environ, start_response): + if environ.has_key('paste.registry'): + environ['paste.registry'].register(self.var, self.value) + status = '200 OK' + response_headers = [('Content-type','text/plain')] + start_response(status, response_headers) + return iter(['Hello world!\nThe variable is %s' % str(testobj)]) + class RegistryMiddleMan(object): - def __init__(self, app, var, value): + def __init__(self, app, var, value, depth): self.app = app self.var = var self.value = value + self.depth = depth def __call__(self, environ, start_response): if environ.has_key('paste.registry'): environ['paste.registry'].register(self.var, self.value) - app_response = ['Inserted by middleware!\nInsertValue is %s' % str(testobj)] - app_response.extend(self.app(environ, start_response)) - app_response.extend(['\nAppended by middleware!\nAppendValue is %s' % str(testobj)]) + app_response = ['\nInserted by middleware!\nInsertValue at depth \ + %s is %s' % (self.depth, str(testobj))] + app_iter = None + app_iter = self.app(environ, start_response) + if type(app_iter) in (list, tuple): + app_response.extend(app_iter) + else: + app_response.extend(list(app_iter)) + app_response.extend(['\nAppended by middleware!\nAppendValue at \ + depth %s is %s' % (self.depth, str(testobj))]) return app_response @@ -57,16 +78,51 @@ def test_double_registry(): secondobj = {'bye':'friends'} wsgiapp = RegistryUsingApp(testobj, obj) wsgiapp = RegistryManager(wsgiapp) - wsgiapp = RegistryMiddleMan(wsgiapp, testobj, secondobj) + wsgiapp = RegistryMiddleMan(wsgiapp, testobj, secondobj, 0) wsgiapp = RegistryManager(wsgiapp) app = TestApp(wsgiapp) res = app.get('/') assert 'Hello world' in res assert 'The variable is' in res assert "{'hi': 'people'}" in res - assert "Inserted by middleware" in res - assert "Appended by middleware" in res - assert "InsertValue is {'bye': 'friends'}" in res - assert "AppendValue is {'bye': 'friends'}" in res + assert "InsertValue at depth 0 is {'bye': 'friends'}" in res + assert "AppendValue at depth 0 is {'bye': 'friends'}" in res -
\ No newline at end of file +def test_really_deep_registry(): + keylist = ['fred', 'wilma', 'barney', 'homer', 'marge', 'bart', 'lisa', + 'maggie'] + valuelist = range(0, len(keylist)) + obj = {'hi':'people'} + wsgiapp = RegistryUsingApp(testobj, obj) + wsgiapp = RegistryManager(wsgiapp) + for depth in valuelist: + newobj = {keylist[depth]: depth} + wsgiapp = RegistryMiddleMan(wsgiapp, testobj, newobj, depth) + wsgiapp = RegistryManager(wsgiapp) + app = TestApp(wsgiapp) + res = app.get('/') + assert 'Hello world' in res + assert 'The variable is' in res + assert "{'hi': 'people'}" in res + for depth in valuelist: + assert "InsertValue at depth %s is {'%s': %s}" % \ + (depth, keylist[depth], depth) in res + for depth in valuelist: + assert "AppendValue at depth %s is {'%s': %s}" % \ + (depth, keylist[depth], depth) in res + +def test_iterating_response(): + obj = {'hi':'people'} + secondobj = {'bye':'friends'} + wsgiapp = RegistryUsingIteratorApp(testobj, obj) + wsgiapp = RegistryManager(wsgiapp) + wsgiapp = RegistryMiddleMan(wsgiapp, testobj, secondobj, 0) + wsgiapp = RegistryManager(wsgiapp) + app = TestApp(wsgiapp) + res = app.get('/') + print res.body + assert 'Hello world' in res + assert 'The variable is' in res + assert "{'hi': 'people'}" in res + assert "InsertValue at depth 0 is {'bye': 'friends'}" in res + assert "AppendValue at depth 0 is {'bye': 'friends'}" in res |
