Commit 41d8b2d6 authored by Vincent Pelletier's avatar Vincent Pelletier

test: Reduce value duplication in testWSGI.

parent 40bd5a05
......@@ -1423,11 +1423,14 @@ class CaucaseTest(unittest.TestCase):
getCertificateSigningRequest = _placeholder
getCertificate = _placeholder
server_name = u'caucase.example.com'
server_http_port = 8000
server_https_port = server_http_port + 1
application = wsgi.Application(
DummyCAU(),
None,
'http://caucase.example.com:8000',
'https://caucase.example.com:8001',
'http://%s:%i' % (server_name, server_http_port),
'https://%s:%i' % (server_name, server_https_port),
wsgi.CORSTokenManager(),
)
def request(environ):
......@@ -1436,9 +1439,8 @@ class CaucaseTest(unittest.TestCase):
"""
environ.setdefault('wsgi.errors', sys.stderr)
environ.setdefault('wsgi.url_scheme', 'http')
name, port = self._server_netloc.split(':')
environ.setdefault('SERVER_NAME', name)
environ.setdefault('SERVER_PORT', port)
environ.setdefault('SERVER_NAME', server_name)
environ.setdefault('SERVER_PORT', str(server_http_port))
start_response_list = []
body = list(application(
environ,
......@@ -1458,14 +1460,17 @@ class CaucaseTest(unittest.TestCase):
return int(status), reason, header_dict, b''.join(body)
UNAUTHORISED_STATUS = 401
HATEOAS_HTTP_PREFIX = u"http://caucase.example.com:8000/base/path"
HATEOAS_HTTPS_PREFIX = u"https://caucase.example.com:8001/base/path"
HATEOAS_HTTP_PREFIX = u"http://%s:%i/base/path" % (
server_name,
server_http_port,
)
HATEOAS_HTTPS_PREFIX = u"https://%s:%i/base/path" % (
server_name,
server_https_port,
)
root_hateoas_request = request({
'SCRIPT_NAME': '/base/path',
'REQUEST_METHOD': 'GET',
'wsgi.url_scheme': 'http',
'SERVER_NAME': 'caucase.example.com',
'SERVER_PORT': '8000',
})
self.maxDiff = None
self.assertEqual(root_hateoas_request[0], 200)
......@@ -1489,9 +1494,6 @@ class CaucaseTest(unittest.TestCase):
'SCRIPT_NAME': '/base/path',
'PATH_INFO': '/cau/',
'REQUEST_METHOD': 'GET',
'wsgi.url_scheme': 'http',
'SERVER_NAME': 'caucase.example.com',
'SERVER_PORT': '8000',
})
self.assertEqual(cau_hateoas_request[0], 200)
self.assertEqual(cau_hateoas_request[2]['Content-Type'], 'application/hal+json')
......@@ -1781,7 +1783,7 @@ class CaucaseTest(unittest.TestCase):
self.assertEqual(
header_dict['WWW-Authenticate'],
'cors url=' + quote(
'https://localhost:8000/cors?' +
'https://%s:%i/cors?' % (server_name, server_https_port) +
urlencode([('origin', cross_origin)]) +
'{&return}',
),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment