From d1ccc0aa4e30caf62eb37708fb51bf90c698bba2 Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Fri, 5 Oct 2018 14:13:58 +0200 Subject: [PATCH 1/2] tests: import TestResponse.__getitem__ from django-webtest --- tests/utilities.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/tests/utilities.py b/tests/utilities.py index 884dea46..04f04bd7 100644 --- a/tests/utilities.py +++ b/tests/utilities.py @@ -13,7 +13,7 @@ import urlparse from wcs import sql, sessions -from webtest import TestApp +from webtest import TestApp, TestResponse from quixote import cleanup, get_publisher from django.conf import settings @@ -204,6 +204,23 @@ def force_connections_close(): pass +class WcsTestResponse(TestResponse): + def __getitem__(self, item): + for key, value in self.headerlist: + if key.lower() == item.lower(): + return value + raise KeyError(item) + + +class WcsTestApp(TestApp): + response_class = WcsTestResponse + + def do_request(self, *args, **kwargs): + response = super(WcsTestApp, self).do_request(*args, **kwargs) + response.__class__ = self.response_class + return response + + def get_app(pub, https=False): extra_environ = {'HTTP_HOST': 'example.net', 'REMOTE_ADDR': '127.0.0.1'} if https: @@ -211,7 +228,8 @@ def get_app(pub, https=False): extra_environ['HTTPS'] = 'on' else: extra_environ['HTTPS'] = 'off' - return TestApp(wcs.wsgi.application, extra_environ=extra_environ) + return WcsTestApp(wcs.wsgi.application, extra_environ=extra_environ) + def login(app, username='admin', password='admin'): login_page = app.get('/login/') -- 2.18.0