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