Skip to content

Commit 7aa3737

Browse files
committed
Reenable RemoteUserMiddleware, it turns out the Secretariat tests are
using REMOTE_USER to auth instead of logging in - instead include a little middleware class that adds the REMOTE_USER header during testing. Also fix problem with the empty test_label hack not working with double-dotted Secretariat apps. - Legacy-Id: 6935
1 parent e1025e6 commit 7aa3737

1 file changed

Lines changed: 15 additions & 7 deletions

File tree

ietf/utils/test_runner.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,17 @@ def safe_destroy_0_1(*args, **kwargs):
8282
def template_coverage_loader(template_name, dirs):
8383
loaded_templates.add(str(template_name))
8484
raise TemplateDoesNotExist
85-
8685
template_coverage_loader.is_usable = True
8786

8887
class RecordUrlsMiddleware(object):
8988
def process_request(self, request):
9089
visited_urls.add(request.path)
9190

91+
class FillInRemoteUserMiddleware(object):
92+
def process_request(self, request):
93+
if request.user.is_authenticated() and "REMOTE_USER" not in request.META:
94+
request.META["REMOTE_USER"] = request.user.username
95+
9296
def get_patterns(module):
9397
all = []
9498
try:
@@ -190,19 +194,23 @@ def run_tests(self, test_labels, extra_tests=None, **kwargs):
190194
old_destroy = connection.creation.__class__.destroy_test_db
191195
connection.creation.__class__.destroy_test_db = safe_destroy_0_1
192196

193-
# exclude RemoteUserMiddleware - it logs out request.user if
194-
# REMOTE_USER is not passed in as a header, which the tests
195-
# don't do
196-
settings.MIDDLEWARE_CLASSES = tuple(m for m in settings.MIDDLEWARE_CLASSES if "RemoteUserMiddleware" not in m)
197+
classes = []
198+
for m in settings.MIDDLEWARE_CLASSES:
199+
if m == "django.contrib.auth.middleware.RemoteUserMiddleware":
200+
# the tests are not passing in REMOTE_USER, so insert
201+
# hack to do so automatically
202+
classes.append("ietf.utils.test_runner.FillInRemoteUserMiddleware")
203+
classes.append(m)
204+
settings.MIDDLEWARE_CLASSES = classes
197205

198206
check_coverage = not test_labels
199207

200208
if check_coverage:
201209
settings.TEMPLATE_LOADERS = ('ietf.utils.test_runner.template_coverage_loader',) + settings.TEMPLATE_LOADERS
202210
settings.MIDDLEWARE_CLASSES = ('ietf.utils.test_runner.RecordUrlsMiddleware',) + settings.MIDDLEWARE_CLASSES
203211

204-
if not test_labels:
205-
test_labels = [x.split(".")[-1] for x in settings.INSTALLED_APPS if x.startswith("ietf")]
212+
if not test_labels: # we only want to run our own tests
213+
test_labels = [app for app in settings.INSTALLED_APPS if app.startswith("ietf")]
206214

207215
if settings.SITE_ID != 1:
208216
print " Changing SITE_ID to '1' during testing."

0 commit comments

Comments
 (0)