aboutsummaryrefslogtreecommitdiff
path: root/src/mailman_pgp/styles
diff options
context:
space:
mode:
authorJ08nY2017-06-28 16:48:02 +0200
committerJ08nY2017-06-28 16:48:02 +0200
commit47eea2be6a86f81ba075df632305c1dfeecce50c (patch)
tree737dbbfe7f4b1902ee0c8ebfc5f61e23ecfe70ee /src/mailman_pgp/styles
parentbc548f544bd8ae4c46d72a684e822b3eaa6cfafd (diff)
downloadmailman-pgp-47eea2be6a86f81ba075df632305c1dfeecce50c.tar.gz
mailman-pgp-47eea2be6a86f81ba075df632305c1dfeecce50c.tar.zst
mailman-pgp-47eea2be6a86f81ba075df632305c1dfeecce50c.zip
Diffstat (limited to 'src/mailman_pgp/styles')
-rw-r--r--src/mailman_pgp/styles/base.py5
-rw-r--r--src/mailman_pgp/styles/tests/test_announce.py45
-rw-r--r--src/mailman_pgp/styles/tests/test_base.py45
-rw-r--r--src/mailman_pgp/styles/tests/test_discussion.py45
4 files changed, 138 insertions, 2 deletions
diff --git a/src/mailman_pgp/styles/base.py b/src/mailman_pgp/styles/base.py
index dd8e76b..caa7775 100644
--- a/src/mailman_pgp/styles/base.py
+++ b/src/mailman_pgp/styles/base.py
@@ -29,12 +29,13 @@ class PGPStyle:
"""Creates the encrypted mailing list instance for the list it's
applied to.
"""
+ mailing_list.posting_chain = 'pgp-posting-chain'
+
pgp_list = PGPMailingList.query().filter_by(
- list_id=mailing_list.list_id).first()
+ list_id=mailing_list.list_id).first()
if pgp_list:
return
pgp_list = PGPMailingList(mailing_list)
with transaction() as session:
session.add(pgp_list)
- mailing_list.posting_chain = 'pgp-posting-chain'
diff --git a/src/mailman_pgp/styles/tests/test_announce.py b/src/mailman_pgp/styles/tests/test_announce.py
new file mode 100644
index 0000000..13f665b
--- /dev/null
+++ b/src/mailman_pgp/styles/tests/test_announce.py
@@ -0,0 +1,45 @@
+# Copyright (C) 2017 Jan Jancar
+#
+# This file is a part of the Mailman PGP plugin.
+#
+# This program is free software; you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free
+# Software Foundation, either version 3 of the License, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+# more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program. If not, see <http://www.gnu.org/licenses/>.
+
+from unittest import TestCase
+
+from mailman.app.lifecycle import create_list
+
+from mailman_pgp.database import mm_transaction
+from mailman_pgp.model.list import PGPMailingList
+from mailman_pgp.testing.layers import PGPConfigLayer
+
+
+class TestAnnounceStyle(TestCase):
+ layer = PGPConfigLayer
+
+ def test_create(self):
+ with mm_transaction():
+ mlist = create_list('test@example.com', style_name='pgp-announce')
+
+ pgp_list = PGPMailingList.query().filter_by(
+ list_id=mlist.list_id).first()
+
+ # Test that we have our PGPMailingList
+ self.assertIsNotNone(pgp_list)
+ self.assertEqual(pgp_list.mlist, mlist)
+
+ # from LegacyAnnounceStyle
+ self.assertEqual(mlist.allow_list_posts, False)
+ self.assertEqual(mlist.send_welcome_message, True)
+ self.assertEqual(mlist.send_goodbye_message, True)
+ self.assertEqual(mlist.anonymous_list, False)
diff --git a/src/mailman_pgp/styles/tests/test_base.py b/src/mailman_pgp/styles/tests/test_base.py
new file mode 100644
index 0000000..159a242
--- /dev/null
+++ b/src/mailman_pgp/styles/tests/test_base.py
@@ -0,0 +1,45 @@
+# Copyright (C) 2017 Jan Jancar
+#
+# This file is a part of the Mailman PGP plugin.
+#
+# This program is free software; you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free
+# Software Foundation, either version 3 of the License, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+# more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program. If not, see <http://www.gnu.org/licenses/>.
+from unittest import TestCase
+
+from mailman.app.lifecycle import create_list
+
+from mailman_pgp.model.list import PGPMailingList
+from mailman_pgp.styles.base import PGPStyle
+from mailman_pgp.testing.layers import PGPConfigLayer
+
+
+class TestBaseStyle(TestCase):
+ layer = PGPConfigLayer
+
+ def test_apply(self):
+ # Create with default style.
+ mlist = create_list('test@example.com')
+ # Manually apply base PGPStyle.
+ base_style = PGPStyle()
+ base_style.apply(mlist)
+
+ pgp_list = PGPMailingList.query().filter_by(
+ list_id=mlist.list_id).first()
+
+ # Test that we have our PGPMailingList
+ self.assertIsNotNone(pgp_list)
+ self.assertEqual(pgp_list.mlist, mlist)
+ self.assertEqual(mlist.posting_chain, 'pgp-posting-chain')
+
+ # Test another apply doesn't fail
+ base_style.apply(mlist)
diff --git a/src/mailman_pgp/styles/tests/test_discussion.py b/src/mailman_pgp/styles/tests/test_discussion.py
new file mode 100644
index 0000000..9056971
--- /dev/null
+++ b/src/mailman_pgp/styles/tests/test_discussion.py
@@ -0,0 +1,45 @@
+# Copyright (C) 2017 Jan Jancar
+#
+# This file is a part of the Mailman PGP plugin.
+#
+# This program is free software; you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free
+# Software Foundation, either version 3 of the License, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+# more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program. If not, see <http://www.gnu.org/licenses/>.
+
+from unittest import TestCase
+
+from mailman.app.lifecycle import create_list
+
+from mailman_pgp.database import mm_transaction
+from mailman_pgp.model.list import PGPMailingList
+from mailman_pgp.testing.layers import PGPConfigLayer
+
+
+class TestDiscussionStyle(TestCase):
+ layer = PGPConfigLayer
+
+ def test_create(self):
+ with mm_transaction():
+ mlist = create_list('test@example.com', style_name='pgp-default')
+
+ pgp_list = PGPMailingList.query().filter_by(
+ list_id=mlist.list_id).first()
+
+ # Test that we have our PGPMailingList
+ self.assertIsNotNone(pgp_list)
+ self.assertEqual(pgp_list.mlist, mlist)
+
+ # from LegacyDiscussionStyle
+ self.assertEqual(mlist.allow_list_posts, True)
+ self.assertEqual(mlist.send_welcome_message, True)
+ self.assertEqual(mlist.send_goodbye_message, True)
+ self.assertEqual(mlist.anonymous_list, False)