You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by ke...@apache.org on 2024/03/12 15:04:22 UTC

(allura) branch master updated (15ff11bf1 -> c1062c9ae)

This is an automated email from the ASF dual-hosted git repository.

kentontaylor pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/allura.git


    from 15ff11bf1 [#8537] small update to notifications function to set active
     new d44e0aaf2 remove unittest from these classes, it won't work well with pytest parametrize
     new c1062c9ae encode emails when the body has long lines.  [#8533] erroneously removed handling of it.  This is a better solution than before too

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 Allura/allura/lib/mail_util.py    |  5 ++++
 Allura/allura/tests/test_tasks.py | 51 +++++++++++++++++++++------------------
 2 files changed, 33 insertions(+), 23 deletions(-)


(allura) 02/02: encode emails when the body has long lines. [#8533] erroneously removed handling of it. This is a better solution than before too

Posted by ke...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

kentontaylor pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/allura.git

commit c1062c9aef1303327890cb9b92117ea505754efe
Author: Dave Brondsema <db...@slashdotmedia.com>
AuthorDate: Tue Mar 12 10:32:37 2024 -0400

    encode emails when the body has long lines.  [#8533] erroneously removed handling of it.  This is a better solution than before too
---
 Allura/allura/lib/mail_util.py    |  5 +++++
 Allura/allura/tests/test_tasks.py | 31 +++++++++++++++++++------------
 2 files changed, 24 insertions(+), 12 deletions(-)

diff --git a/Allura/allura/lib/mail_util.py b/Allura/allura/lib/mail_util.py
index 24f1eb8c6..285c12d73 100644
--- a/Allura/allura/lib/mail_util.py
+++ b/Allura/allura/lib/mail_util.py
@@ -194,6 +194,11 @@ def encode_email_part(content, content_type):
         # simplest email - plain ascii
         encoded_content = content.encode('ascii')
         encoding = 'ascii'
+        for line in encoded_content.splitlines():
+            if len(line) > MAX_MAIL_LINE_OCTETS:
+                # force base64 content-encoding to make lines shorter
+                encoding = 'utf-8'
+                break
     except Exception:
         # utf8 will get base64 encoded so we only do it if ascii fails
         encoded_content = content.encode('utf-8')
diff --git a/Allura/allura/tests/test_tasks.py b/Allura/allura/tests/test_tasks.py
index 56ab38f55..54e936ec6 100644
--- a/Allura/allura/tests/test_tasks.py
+++ b/Allura/allura/tests/test_tasks.py
@@ -14,7 +14,8 @@
 #       KIND, either express or implied.  See the License for the
 #       specific language governing permissions and limitations
 #       under the License.
-
+import email.parser
+import email.iterators
 import operator
 import shutil
 from textwrap import dedent
@@ -28,6 +29,7 @@ import pkg_resources
 import tg
 import mock
 from tg import tmpl_context as c, app_globals as g
+import pytest
 
 from ming.odm import FieldProperty, Mapper
 from ming.odm import ThreadLocalODMSession
@@ -464,29 +466,34 @@ class TestMailTasks:
             return_path, rcpts, body = _client.sendmail.call_args[0]
             assert 'From: "Test Admin" <te...@users.localhost>' in body
 
-    def test_send_email_long_lines_use_quoted_printable(self):
+    @pytest.mark.parametrize('bodychars', [
+        '0123456789',  # plain ascii is handled different since it doesn't necessarily need to be encoded
+        'Громады стро ',
+    ])
+    def test_send_email_long_lines(self, bodychars):
         with mock.patch.object(mail_tasks.smtp_client, '_client') as _client:
             mail_tasks.sendsimplemail(
                 fromaddr='"По" <fo...@bar.com>',
                 toaddr='blah@blah.com',
-                text=('0123456789' * 100) + '\n\n' + ('Громады стро ' * 100),
+                text=bodychars * 100,
                 reply_to=g.noreply,
                 subject='123451234512345' * 100,
                 references=['foo@example.com'] * 100,  # needs to handle really long headers as well
                 message_id=h.gen_message_id())
             return_path, rcpts, body = _client.sendmail.call_args[0]
-            body = body.split(email_policy.linesep)
+            body_lines = body.split(email_policy.linesep)
 
-            for line in body:
+            for line in body_lines:
                 assert len(line) <= MAX_MAIL_LINE_OCTETS
 
-            bodystr = ''.join(body)
-            # plain text
-            assert b64encode(b'012345678901234567890123').decode('utf8') in bodystr
-            assert b64encode('Громады стро '.encode('utf8')).decode('utf8') in bodystr
-            # html
-            assert b64encode(b'<div class="markdown_content"><p>012345678901234567890123').decode('utf8') in bodystr
-            assert b64encode('<p>Громады стро '.encode('utf8')).decode('utf8') in bodystr
+            msg = email.parser.Parser().parsestr(body)
+            plain_subpart = next(email.iterators.typed_subpart_iterator(msg, 'text', 'plain'))
+            plain = plain_subpart.get_payload(decode=True).decode('utf-8')
+            html_subpart = next(email.iterators.typed_subpart_iterator(msg, 'text', 'html')).get_payload(decode=True)
+            html = html_subpart.decode('utf-8')
+
+            assert (bodychars + bodychars) in plain
+            assert f'<div class="markdown_content"><p>{bodychars}{bodychars}' in html
 
     @td.with_wiki
     def test_receive_email_ok(self):


(allura) 01/02: remove unittest from these classes, it won't work well with pytest parametrize

Posted by ke...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

kentontaylor pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/allura.git

commit d44e0aaf2e0b4f5bebed4c89d27f57d5cab4e210
Author: Dave Brondsema <db...@slashdotmedia.com>
AuthorDate: Tue Mar 12 10:31:19 2024 -0400

    remove unittest from these classes, it won't work well with pytest parametrize
---
 Allura/allura/tests/test_tasks.py | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)

diff --git a/Allura/allura/tests/test_tasks.py b/Allura/allura/tests/test_tasks.py
index 8ecbeeb05..56ab38f55 100644
--- a/Allura/allura/tests/test_tasks.py
+++ b/Allura/allura/tests/test_tasks.py
@@ -51,7 +51,7 @@ from allura.tests.exclude_from_rewrite_hook import raise_compound_exception
 from allura.lib.decorators import event_handler, task
 
 
-class TestRepoTasks(unittest.TestCase):
+class TestRepoTasks:
 
     def setup_method(self, method):
         setup_basic_test()
@@ -100,7 +100,7 @@ def _task_that_creates_event(event_name,):
     assert not M.MonQTask.query.get(task_name='allura.tasks.event_tasks.event', args=[event_name])
 
 
-class TestEventTasks(unittest.TestCase):
+class TestEventTasks:
 
     def setup_method(self, method):
         setup_basic_test()
@@ -158,7 +158,7 @@ class TestEventTasks(unittest.TestCase):
             assert ('assert %d' % x) in t.result
 
 
-class TestIndexTasks(unittest.TestCase):
+class TestIndexTasks:
 
     def setup_method(self, method):
         setup_basic_test()
@@ -243,7 +243,7 @@ class TestIndexTasks(unittest.TestCase):
         solr.delete.assert_called_once_with(q=solr_query)
 
 
-class TestMailTasks(unittest.TestCase):
+class TestMailTasks:
 
     def setup_method(self, method):
         setup_basic_test()
@@ -570,7 +570,7 @@ class TestUserNotificationTasks(TestController):
         assert 'auth/subscriptions#notifications' in text
 
 
-class TestNotificationTasks(unittest.TestCase):
+class TestNotificationTasks:
 
     def setup_method(self, method):
         setup_basic_test()
@@ -605,7 +605,7 @@ class _TestArtifact(M.Artifact):
             text=self.text)
 
 
-class TestExportTasks(unittest.TestCase):
+class TestExportTasks:
 
     def setup_method(self, method):
         setup_basic_test()
@@ -621,13 +621,11 @@ class TestExportTasks(unittest.TestCase):
         exportable = mock.Mock(exportable=True)
         not_exportable = mock.Mock(exportable=False)
         BE = export_tasks.BulkExport()
-        self.assertEqual(
-            BE.filter_exportable([None, exportable, not_exportable]), [exportable])
+        assert BE.filter_exportable([None, exportable, not_exportable]) == [exportable]
 
     def test_bulk_export_filter_successful(self):
         BE = export_tasks.BulkExport()
-        self.assertEqual(
-            BE.filter_successful(['foo', None, '0']), ['foo', '0'])
+        assert BE.filter_successful(['foo', None, '0']) == ['foo', '0']
 
     @mock.patch('allura.tasks.export_tasks.shutil')
     @mock.patch('allura.tasks.export_tasks.zipdir')
@@ -659,7 +657,7 @@ class TestExportTasks(unittest.TestCase):
         assert c.project.bulk_export_status() == 'busy'
 
 
-class TestAdminTasks(unittest.TestCase):
+class TestAdminTasks:
 
     def test_install_app_docstring(self):
         assert 'ep_name, mount_point=None' in admin_tasks.install_app.__doc__