From b41165fd01521fdbb2a02f0c7ac3b02de9a138c5 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Fri, 11 Sep 2020 21:32:57 -0700 Subject: [PATCH] dev_urls: Give the user_avatars URLPattern a name. Signed-off-by: Anders Kaseorg --- zerver/lib/test_runner.py | 19 +++---------------- zproject/dev_urls.py | 10 ++++++---- 2 files changed, 9 insertions(+), 20 deletions(-) diff --git a/zerver/lib/test_runner.py b/zerver/lib/test_runner.py index cb621f884f..9640429358 100644 --- a/zerver/lib/test_runner.py +++ b/zerver/lib/test_runner.py @@ -13,7 +13,6 @@ from django.test import TestCase from django.test import runner as django_runner from django.test.runner import DiscoverRunner from django.test.signals import template_rendered -from django.urls.resolvers import URLPattern from scripts.lib.zulip_tools import ( TEMPLATE_DATABASE_DIR, @@ -196,22 +195,10 @@ def init_worker(counter: Synchronized) -> None: create_test_databases(_worker_id) initialize_worker_path(_worker_id) - def is_upload_avatar_url(url: URLPattern) -> bool: - if url.pattern.regex.pattern == r'^user_avatars/(?P.*)$': - return True - return False - # We manually update the upload directory path in the url regex. - from zproject import dev_urls - found = False - for url in dev_urls.urls: - if is_upload_avatar_url(url): - found = True - new_root = os.path.join(settings.LOCAL_UPLOADS_DIR, "avatars") - url.default_args['document_root'] = new_root - - if not found: - print("*** Upload directory not found.") + from zproject.dev_urls import avatars_url + new_root = os.path.join(settings.LOCAL_UPLOADS_DIR, "avatars") + avatars_url.default_args['document_root'] = new_root class ParallelTestSuite(django_runner.ParallelTestSuite): run_subsuite = run_subsuite diff --git a/zproject/dev_urls.py b/zproject/dev_urls.py index 1c5253722b..5f0ab9fbf0 100644 --- a/zproject/dev_urls.py +++ b/zproject/dev_urls.py @@ -84,7 +84,9 @@ i18n_urls = [ # On a production instance, these files would be served by nginx. if settings.LOCAL_UPLOADS_DIR is not None: - urls += [ - re_path(r'^user_avatars/(?P.*)$', serve, - {'document_root': os.path.join(settings.LOCAL_UPLOADS_DIR, "avatars")}), - ] + avatars_url = re_path( + r'^user_avatars/(?P.*)$', + serve, + {'document_root': os.path.join(settings.LOCAL_UPLOADS_DIR, "avatars")}, + ) + urls += [avatars_url]