summaryrefslogtreecommitdiff
path: root/src/mailman/handlers
diff options
context:
space:
mode:
authorBarry Warsaw2016-02-27 14:40:06 -0500
committerBarry Warsaw2016-02-27 14:40:06 -0500
commitcd61fcc88245af25bda231710cbbe1eb75a5e0e4 (patch)
treed45dd282508400183c352ac239d984358af12ac8 /src/mailman/handlers
parenta763e9634ce5dacc4a5079271d14e8fb4b71235c (diff)
downloadmailman-cd61fcc88245af25bda231710cbbe1eb75a5e0e4.tar.gz
mailman-cd61fcc88245af25bda231710cbbe1eb75a5e0e4.tar.zst
mailman-cd61fcc88245af25bda231710cbbe1eb75a5e0e4.zip
Diffstat (limited to 'src/mailman/handlers')
-rw-r--r--src/mailman/handlers/decorate.py3
-rw-r--r--src/mailman/handlers/tests/test_decorate.py51
2 files changed, 42 insertions, 12 deletions
diff --git a/src/mailman/handlers/decorate.py b/src/mailman/handlers/decorate.py
index cd9f189aa..8493a0b08 100644
--- a/src/mailman/handlers/decorate.py
+++ b/src/mailman/handlers/decorate.py
@@ -217,8 +217,9 @@ def decorate(mlist, uri, extradict=None):
# Get the decorator template.
loader = getUtility(ITemplateLoader)
template_uri = expand(uri, dict(
- listname=mlist.fqdn_listname,
language=mlist.preferred_language.code,
+ list_id=mlist.list_id,
+ listname=mlist.fqdn_listname,
))
template = loader.get(template_uri)
return decorate_template(mlist, template, extradict)
diff --git a/src/mailman/handlers/tests/test_decorate.py b/src/mailman/handlers/tests/test_decorate.py
index 9707223c5..84adceb9a 100644
--- a/src/mailman/handlers/tests/test_decorate.py
+++ b/src/mailman/handlers/tests/test_decorate.py
@@ -23,8 +23,6 @@ __all__ = [
import os
-import shutil
-import tempfile
import unittest
from mailman.app.lifecycle import create_list
@@ -33,6 +31,7 @@ from mailman.handlers import decorate
from mailman.interfaces.archiver import IArchiver
from mailman.testing.helpers import specialized_message_from_string as mfs
from mailman.testing.layers import ConfigLayer
+from tempfile import TemporaryDirectory
from zope.interface import implementer
@@ -56,19 +55,18 @@ class TestDecorate(unittest.TestCase):
layer = ConfigLayer
def setUp(self):
- self._mlist = create_list('test@example.com')
+ self._mlist = create_list('ant@example.com')
self._msg = mfs("""\
-To: test@example.com
+To: ant@example.com
From: aperson@example.com
-Message-ID: <somerandomid.example.com>
+Message-ID: <alpha>
Content-Type: text/plain;
This is a test message.
""")
- template_dir = tempfile.mkdtemp()
- self.addCleanup(shutil.rmtree, template_dir)
- site_dir = os.path.join(template_dir, 'site', 'en')
- os.makedirs(site_dir)
+ temporary_dir = TemporaryDirectory()
+ self.addCleanup(temporary_dir.cleanup)
+ template_dir = temporary_dir.name
config.push('archiver', """\
[paths.testing]
template_dir: {}
@@ -77,13 +75,44 @@ This is a test message.
enable: yes
""".format(template_dir))
self.addCleanup(config.pop, 'archiver')
- self.footer_path = os.path.join(site_dir, 'myfooter.txt')
def test_decorate_footer_with_archive_url(self):
- with open(self.footer_path, 'w', encoding='utf-8') as fp:
+ site_dir = os.path.join(config.TEMPLATE_DIR, 'site', 'en')
+ os.makedirs(site_dir)
+ footer_path = os.path.join(site_dir, 'myfooter.txt')
+ with open(footer_path, 'w', encoding='utf-8') as fp:
print('${testarchiver_url}', file=fp)
self._mlist.footer_uri = 'mailman:///myfooter.txt'
self._mlist.preferred_language = 'en'
decorate.process(self._mlist, self._msg, {})
self.assertIn('http://example.com/link_to_message',
self._msg.as_string())
+
+ def test_list_id_allowed_in_template_uri(self):
+ # Issue #196 - allow the list_id in the template uri expansion.
+ list_dir = os.path.join(
+ config.TEMPLATE_DIR, 'lists', 'ant.example.com', 'en')
+ os.makedirs(list_dir)
+ footer_path = os.path.join(list_dir, 'myfooter.txt')
+ with open(footer_path, 'w', encoding='utf-8') as fp:
+ print('${testarchiver_url}', file=fp)
+ self._mlist.footer_uri = 'mailman:///${list_id}/myfooter.txt'
+ self._mlist.preferred_language = 'en'
+ decorate.process(self._mlist, self._msg, {})
+ self.assertIn('http://example.com/link_to_message',
+ self._msg.as_string())
+
+ def test_list_id_and_language_code_allowed_in_template_uri(self):
+ # Issue #196 - allow the list_id in the template uri expansion.
+ list_dir = os.path.join(
+ config.TEMPLATE_DIR, 'lists', 'ant.example.com', 'it')
+ os.makedirs(list_dir)
+ footer_path = os.path.join(list_dir, 'myfooter.txt')
+ with open(footer_path, 'w', encoding='utf-8') as fp:
+ print('${testarchiver_url}', file=fp)
+ self._mlist.footer_uri = (
+ 'mailman:///${list_id}/${language}/myfooter.txt')
+ self._mlist.preferred_language = 'it'
+ decorate.process(self._mlist, self._msg, {})
+ self.assertIn('http://example.com/link_to_message',
+ self._msg.as_string())