tests/test-hgweb-no-request-uri
author Patrick Mezard <pmezard@gmail.com>
Mon, 26 Apr 2010 22:30:40 +0200
branchstable
changeset 11010 18e81d42ee5c
parent 8167 6c82beaaa11a
child 12161 dfb11f9922c1
permissions -rwxr-xr-x
util: fix default termwidth() under Windows sys.stdout.write('-'*80 + '\n') or sys.stdout.write('-'*80 + '\r') do not work on Windows as they do on unix. On a 80 columns Windows console, the extra CR or LF are interpreted as if belonging to the next line, so the first command displays 2 lines (only one on unix) and the second one leave the line visible and move back to the following line. To avoid this, we sacrifice one column under Windows.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5579
e15f7db0f0ee Use SCRIPT_NAME and PATH_INFO instead of REQUEST_URI. This is required by WSGI (fixes issue846).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
     1
#!/bin/sh
5580
f429e0e067a8 Fix style nit and add some comments to tests.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5579
diff changeset
     2
# This tests if hgweb and hgwebdir still work if the REQUEST_URI variable is
f429e0e067a8 Fix style nit and add some comments to tests.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5579
diff changeset
     3
# no longer passed with the request. Instead, SCRIPT_NAME and PATH_INFO
f429e0e067a8 Fix style nit and add some comments to tests.
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 5579
diff changeset
     4
# should be used from d74fc8dec2b4 onward to route the request.
5579
e15f7db0f0ee Use SCRIPT_NAME and PATH_INFO instead of REQUEST_URI. This is required by WSGI (fixes issue846).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
     5
e15f7db0f0ee Use SCRIPT_NAME and PATH_INFO instead of REQUEST_URI. This is required by WSGI (fixes issue846).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
     6
mkdir repo
e15f7db0f0ee Use SCRIPT_NAME and PATH_INFO instead of REQUEST_URI. This is required by WSGI (fixes issue846).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
     7
cd repo
e15f7db0f0ee Use SCRIPT_NAME and PATH_INFO instead of REQUEST_URI. This is required by WSGI (fixes issue846).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
     8
hg init
e15f7db0f0ee Use SCRIPT_NAME and PATH_INFO instead of REQUEST_URI. This is required by WSGI (fixes issue846).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
     9
echo foo > bar
e15f7db0f0ee Use SCRIPT_NAME and PATH_INFO instead of REQUEST_URI. This is required by WSGI (fixes issue846).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
    10
hg add bar
8167
6c82beaaa11a tests: removed redundant "-d '0 0'" from test scripts
Martin Geisler <mg@lazybytes.net>
parents: 6945
diff changeset
    11
hg commit -m "test" -u "Testing"
5579
e15f7db0f0ee Use SCRIPT_NAME and PATH_INFO instead of REQUEST_URI. This is required by WSGI (fixes issue846).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
    12
hg tip
e15f7db0f0ee Use SCRIPT_NAME and PATH_INFO instead of REQUEST_URI. This is required by WSGI (fixes issue846).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
    13
e15f7db0f0ee Use SCRIPT_NAME and PATH_INFO instead of REQUEST_URI. This is required by WSGI (fixes issue846).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
    14
cat > request.py <<EOF
e15f7db0f0ee Use SCRIPT_NAME and PATH_INFO instead of REQUEST_URI. This is required by WSGI (fixes issue846).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
    15
from mercurial.hgweb import hgweb, hgwebdir
e15f7db0f0ee Use SCRIPT_NAME and PATH_INFO instead of REQUEST_URI. This is required by WSGI (fixes issue846).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
    16
from StringIO import StringIO
e15f7db0f0ee Use SCRIPT_NAME and PATH_INFO instead of REQUEST_URI. This is required by WSGI (fixes issue846).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
    17
import os, sys
e15f7db0f0ee Use SCRIPT_NAME and PATH_INFO instead of REQUEST_URI. This is required by WSGI (fixes issue846).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
    18
e15f7db0f0ee Use SCRIPT_NAME and PATH_INFO instead of REQUEST_URI. This is required by WSGI (fixes issue846).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
    19
errors = StringIO()
e15f7db0f0ee Use SCRIPT_NAME and PATH_INFO instead of REQUEST_URI. This is required by WSGI (fixes issue846).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
    20
input = StringIO()
e15f7db0f0ee Use SCRIPT_NAME and PATH_INFO instead of REQUEST_URI. This is required by WSGI (fixes issue846).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
    21
e15f7db0f0ee Use SCRIPT_NAME and PATH_INFO instead of REQUEST_URI. This is required by WSGI (fixes issue846).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
    22
def startrsp(headers, data):
e15f7db0f0ee Use SCRIPT_NAME and PATH_INFO instead of REQUEST_URI. This is required by WSGI (fixes issue846).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
    23
	print '---- HEADERS'
e15f7db0f0ee Use SCRIPT_NAME and PATH_INFO instead of REQUEST_URI. This is required by WSGI (fixes issue846).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
    24
	print headers
e15f7db0f0ee Use SCRIPT_NAME and PATH_INFO instead of REQUEST_URI. This is required by WSGI (fixes issue846).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
    25
	print '---- DATA'
e15f7db0f0ee Use SCRIPT_NAME and PATH_INFO instead of REQUEST_URI. This is required by WSGI (fixes issue846).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
    26
	print data
e15f7db0f0ee Use SCRIPT_NAME and PATH_INFO instead of REQUEST_URI. This is required by WSGI (fixes issue846).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
    27
	return output.write
e15f7db0f0ee Use SCRIPT_NAME and PATH_INFO instead of REQUEST_URI. This is required by WSGI (fixes issue846).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
    28
e15f7db0f0ee Use SCRIPT_NAME and PATH_INFO instead of REQUEST_URI. This is required by WSGI (fixes issue846).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
    29
env = {
e15f7db0f0ee Use SCRIPT_NAME and PATH_INFO instead of REQUEST_URI. This is required by WSGI (fixes issue846).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
    30
	'wsgi.version': (1, 0),
e15f7db0f0ee Use SCRIPT_NAME and PATH_INFO instead of REQUEST_URI. This is required by WSGI (fixes issue846).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
    31
	'wsgi.url_scheme': 'http',
e15f7db0f0ee Use SCRIPT_NAME and PATH_INFO instead of REQUEST_URI. This is required by WSGI (fixes issue846).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
    32
	'wsgi.errors': errors,
e15f7db0f0ee Use SCRIPT_NAME and PATH_INFO instead of REQUEST_URI. This is required by WSGI (fixes issue846).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
    33
	'wsgi.input': input,
e15f7db0f0ee Use SCRIPT_NAME and PATH_INFO instead of REQUEST_URI. This is required by WSGI (fixes issue846).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
    34
	'wsgi.multithread': False,
e15f7db0f0ee Use SCRIPT_NAME and PATH_INFO instead of REQUEST_URI. This is required by WSGI (fixes issue846).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
    35
	'wsgi.multiprocess': False,
e15f7db0f0ee Use SCRIPT_NAME and PATH_INFO instead of REQUEST_URI. This is required by WSGI (fixes issue846).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
    36
	'wsgi.run_once': False,
e15f7db0f0ee Use SCRIPT_NAME and PATH_INFO instead of REQUEST_URI. This is required by WSGI (fixes issue846).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
    37
	'REQUEST_METHOD': 'GET',
e15f7db0f0ee Use SCRIPT_NAME and PATH_INFO instead of REQUEST_URI. This is required by WSGI (fixes issue846).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
    38
	'SCRIPT_NAME': '',
e15f7db0f0ee Use SCRIPT_NAME and PATH_INFO instead of REQUEST_URI. This is required by WSGI (fixes issue846).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
    39
	'SERVER_NAME': '127.0.0.1',
e15f7db0f0ee Use SCRIPT_NAME and PATH_INFO instead of REQUEST_URI. This is required by WSGI (fixes issue846).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
    40
	'SERVER_PORT': os.environ['HGPORT'],
e15f7db0f0ee Use SCRIPT_NAME and PATH_INFO instead of REQUEST_URI. This is required by WSGI (fixes issue846).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
    41
	'SERVER_PROTOCOL': 'HTTP/1.0'
e15f7db0f0ee Use SCRIPT_NAME and PATH_INFO instead of REQUEST_URI. This is required by WSGI (fixes issue846).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
    42
}
e15f7db0f0ee Use SCRIPT_NAME and PATH_INFO instead of REQUEST_URI. This is required by WSGI (fixes issue846).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
    43
6945
2cfdabe235fb hgweb: return content iterator instead of using write() callable
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6796
diff changeset
    44
def process(app):
2cfdabe235fb hgweb: return content iterator instead of using write() callable
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6796
diff changeset
    45
	content = app(env, startrsp)
2cfdabe235fb hgweb: return content iterator instead of using write() callable
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6796
diff changeset
    46
	sys.stdout.write(output.getvalue())
2cfdabe235fb hgweb: return content iterator instead of using write() callable
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6796
diff changeset
    47
	sys.stdout.write(''.join(content))
2cfdabe235fb hgweb: return content iterator instead of using write() callable
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6796
diff changeset
    48
	print '---- ERRORS'
2cfdabe235fb hgweb: return content iterator instead of using write() callable
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6796
diff changeset
    49
	print errors.getvalue()
2cfdabe235fb hgweb: return content iterator instead of using write() callable
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6796
diff changeset
    50
	
2cfdabe235fb hgweb: return content iterator instead of using write() callable
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6796
diff changeset
    51
5579
e15f7db0f0ee Use SCRIPT_NAME and PATH_INFO instead of REQUEST_URI. This is required by WSGI (fixes issue846).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
    52
output = StringIO()
e15f7db0f0ee Use SCRIPT_NAME and PATH_INFO instead of REQUEST_URI. This is required by WSGI (fixes issue846).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
    53
env['PATH_INFO'] = '/'
e15f7db0f0ee Use SCRIPT_NAME and PATH_INFO instead of REQUEST_URI. This is required by WSGI (fixes issue846).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
    54
env['QUERY_STRING'] = 'style=atom'
6945
2cfdabe235fb hgweb: return content iterator instead of using write() callable
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6796
diff changeset
    55
process(hgweb('.', name = 'repo'))
5579
e15f7db0f0ee Use SCRIPT_NAME and PATH_INFO instead of REQUEST_URI. This is required by WSGI (fixes issue846).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
    56
e15f7db0f0ee Use SCRIPT_NAME and PATH_INFO instead of REQUEST_URI. This is required by WSGI (fixes issue846).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
    57
output = StringIO()
e15f7db0f0ee Use SCRIPT_NAME and PATH_INFO instead of REQUEST_URI. This is required by WSGI (fixes issue846).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
    58
env['PATH_INFO'] = '/file/tip/'
e15f7db0f0ee Use SCRIPT_NAME and PATH_INFO instead of REQUEST_URI. This is required by WSGI (fixes issue846).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
    59
env['QUERY_STRING'] = 'style=raw'
6945
2cfdabe235fb hgweb: return content iterator instead of using write() callable
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6796
diff changeset
    60
process(hgweb('.', name = 'repo'))
5579
e15f7db0f0ee Use SCRIPT_NAME and PATH_INFO instead of REQUEST_URI. This is required by WSGI (fixes issue846).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
    61
e15f7db0f0ee Use SCRIPT_NAME and PATH_INFO instead of REQUEST_URI. This is required by WSGI (fixes issue846).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
    62
output = StringIO()
e15f7db0f0ee Use SCRIPT_NAME and PATH_INFO instead of REQUEST_URI. This is required by WSGI (fixes issue846).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
    63
env['PATH_INFO'] = '/'
e15f7db0f0ee Use SCRIPT_NAME and PATH_INFO instead of REQUEST_URI. This is required by WSGI (fixes issue846).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
    64
env['QUERY_STRING'] = 'style=raw'
6945
2cfdabe235fb hgweb: return content iterator instead of using write() callable
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6796
diff changeset
    65
process(hgwebdir({'repo': '.'}))
5579
e15f7db0f0ee Use SCRIPT_NAME and PATH_INFO instead of REQUEST_URI. This is required by WSGI (fixes issue846).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
    66
e15f7db0f0ee Use SCRIPT_NAME and PATH_INFO instead of REQUEST_URI. This is required by WSGI (fixes issue846).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
    67
output = StringIO()
e15f7db0f0ee Use SCRIPT_NAME and PATH_INFO instead of REQUEST_URI. This is required by WSGI (fixes issue846).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
    68
env['PATH_INFO'] = '/repo/file/tip/'
e15f7db0f0ee Use SCRIPT_NAME and PATH_INFO instead of REQUEST_URI. This is required by WSGI (fixes issue846).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
    69
env['QUERY_STRING'] = 'style=raw'
6945
2cfdabe235fb hgweb: return content iterator instead of using write() callable
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents: 6796
diff changeset
    70
process(hgwebdir({'repo': '.'}))
5579
e15f7db0f0ee Use SCRIPT_NAME and PATH_INFO instead of REQUEST_URI. This is required by WSGI (fixes issue846).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
    71
EOF
e15f7db0f0ee Use SCRIPT_NAME and PATH_INFO instead of REQUEST_URI. This is required by WSGI (fixes issue846).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
    72
e15f7db0f0ee Use SCRIPT_NAME and PATH_INFO instead of REQUEST_URI. This is required by WSGI (fixes issue846).
Dirkjan Ochtman <dirkjan@ochtman.nl>
parents:
diff changeset
    73
python request.py | sed "s/http:\/\/127\.0\.0\.1:[0-9]*\//http:\/\/127.0.0.1\//"