Package platecom :: Package langview :: Package tests :: Module utils
[hide private]
[frames] | no frames]

Source Code for Module icsemantic.langfallback.tests.utils

  1  import os, sys 
  2  import glob 
  3   
  4  from Globals import package_home 
  5   
6 -def list_functionaltests(folder):
7 home = package_home(globals()) 8 return [folder + '/' + os.path.basename(filename) for filename in 9 glob.glob(os.path.sep.join([home, folder + '/*.txt']))]
10
11 -def cleanup_folder(folder):
12 """ 13 """ 14 folder.manage_delObjects(folder.objectIds())
15
16 -class Five:
17 version = '1.4.4'
18
19 -def http(request_string, handle_errors=True):
20 """ 21 MONKEYPATCH: Fix https://bugs.launchpad.net/zope3/+bug/98437 22 TODO: try to really fix this... ask Martin Aspeli, 23 talk in the zope channel, etc... 24 25 Execute an HTTP request string via the publisher 26 27 This is used for HTTP doc tests. 28 """ 29 import urllib 30 import rfc822 31 from cStringIO import StringIO 32 from ZPublisher.Response import Response 33 from ZPublisher.Test import publish_module 34 from AccessControl.SecurityManagement import getSecurityManager 35 from AccessControl.SecurityManagement import setSecurityManager 36 import transaction 37 from Testing.ZopeTestCase.zopedoctest.functional import HTTPHeaderOutput, \ 38 split_header, \ 39 sync, \ 40 DocResponseWrapper 41 42 # Save current Security Manager 43 old_sm = getSecurityManager() 44 45 # Commit work done by previous python code. 46 transaction.commit() 47 48 # Discard leading white space to make call layout simpler 49 request_string = request_string.lstrip() 50 51 # Split off and parse the command line 52 l = request_string.find('\n') 53 command_line = request_string[:l].rstrip() 54 request_string = request_string[l+1:] 55 method, path, protocol = command_line.split() 56 path = urllib.unquote(path) 57 58 instream = StringIO(request_string) 59 60 env = {"HTTP_HOST": 'nohost', 61 "HTTP_REFERER": 'http://nohost/plone', 62 "REQUEST_METHOD": method, 63 "SERVER_PROTOCOL": protocol, 64 } 65 66 p = path.split('?') 67 if len(p) == 1: 68 env['PATH_INFO'] = p[0] 69 elif len(p) == 2: 70 [env['PATH_INFO'], env['QUERY_STRING']] = p 71 else: 72 raise TypeError, '' 73 74 header_output = HTTPHeaderOutput( 75 protocol, ('x-content-type-warning', 'x-powered-by', 76 'bobo-exception-type', 'bobo-exception-file', 77 'bobo-exception-value', 'bobo-exception-line')) 78 79 headers = [split_header(header) 80 for header in rfc822.Message(instream).headers] 81 82 # Store request body without headers 83 instream = StringIO(instream.read()) 84 85 for name, value in headers: 86 name = ('_'.join(name.upper().split('-'))) 87 if name not in ('CONTENT_TYPE', 'CONTENT_LENGTH'): 88 name = 'HTTP_' + name 89 env[name] = value.rstrip() 90 91 if env.has_key('HTTP_AUTHORIZATION'): 92 env['HTTP_AUTHORIZATION'] = auth_header(env['HTTP_AUTHORIZATION']) 93 94 outstream = StringIO() 95 response = Response(stdout=outstream, stderr=sys.stderr) 96 97 publish_module('Zope2', 98 response=response, 99 stdin=instream, 100 environ=env, 101 debug=not handle_errors, 102 ) 103 header_output.setResponseStatus(response.getStatus(), response.errmsg) 104 header_output.setResponseHeaders(response.headers) 105 header_output.appendResponseHeaders(response._cookie_list()) 106 header_output.appendResponseHeaders(response.accumulated_headers.splitlines()) 107 108 # Restore previous security manager, which may have been changed 109 # by calling the publish method above 110 setSecurityManager(old_sm) 111 112 # Sync connection 113 sync() 114 115 return DocResponseWrapper(response, outstream, path, header_output)
116