aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/mailman_pgp/config/__init__.py4
-rw-r--r--src/mailman_pgp/database/__init__.py5
-rw-r--r--src/mailman_pgp/pgp/keygen.py3
-rw-r--r--src/mailman_pgp/rest/tests/test_lists.py4
-rw-r--r--src/mailman_pgp/rules/tests/test_signature.py7
-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
-rw-r--r--src/mailman_pgp/testing/layers.py3
10 files changed, 157 insertions, 9 deletions
diff --git a/src/mailman_pgp/config/__init__.py b/src/mailman_pgp/config/__init__.py
index 803b0f9..fcf5e55 100644
--- a/src/mailman_pgp/config/__init__.py
+++ b/src/mailman_pgp/config/__init__.py
@@ -37,8 +37,10 @@ class Config(ConfigParser):
"""
self.name = name
self.read(expand_path(
- dict(mailman_config.plugin_configs)[self.name].configuration))
+ dict(mailman_config.plugin_configs)[self.name].configuration))
config = Config()
public(config=config)
+mm_config = mailman_config
+public(mm_config=mm_config)
diff --git a/src/mailman_pgp/database/__init__.py b/src/mailman_pgp/database/__init__.py
index bbb7840..2e24cdc 100644
--- a/src/mailman_pgp/database/__init__.py
+++ b/src/mailman_pgp/database/__init__.py
@@ -20,6 +20,7 @@
from contextlib import contextmanager
from mailman.config import config as mailman_config
+from mailman.database.transaction import transaction as mailman_transaction
from mailman.utilities.string import expand
from public import public
from sqlalchemy import create_engine
@@ -80,3 +81,7 @@ def query(cls):
:rtype: sqlalchemy.orm.query.Query
"""
return config.db.session.query(cls)
+
+
+mm_transaction = mailman_transaction
+public(mm_transaction=mm_transaction)
diff --git a/src/mailman_pgp/pgp/keygen.py b/src/mailman_pgp/pgp/keygen.py
index 32c24ed..33784dd 100644
--- a/src/mailman_pgp/pgp/keygen.py
+++ b/src/mailman_pgp/pgp/keygen.py
@@ -35,7 +35,8 @@ class ListKeyGenerator(mp.Process):
super().__init__(
target=self.generate,
args=(keypair_config, display_name, posting_address,
- request_address, key_path))
+ request_address, key_path),
+ daemon=True)
def generate(self, keypair_config, display_name, posting_address,
request_address, key_path):
diff --git a/src/mailman_pgp/rest/tests/test_lists.py b/src/mailman_pgp/rest/tests/test_lists.py
index a7b1c2a..f5f8754 100644
--- a/src/mailman_pgp/rest/tests/test_lists.py
+++ b/src/mailman_pgp/rest/tests/test_lists.py
@@ -19,10 +19,10 @@ from unittest import TestCase
from urllib.error import HTTPError
from mailman.app.lifecycle import create_list
-from mailman.database.transaction import transaction as mailman_transaction
from mailman.testing.helpers import call_api
from pgpy import PGPKey
+from mailman_pgp.database import mm_transaction
from mailman_pgp.testing.layers import PGPRESTLayer
@@ -30,7 +30,7 @@ class TestLists(TestCase):
layer = PGPRESTLayer
def setUp(self):
- with mailman_transaction():
+ with mm_transaction():
self.mlist = create_list('test@example.com',
style_name='pgp-default')
diff --git a/src/mailman_pgp/rules/tests/test_signature.py b/src/mailman_pgp/rules/tests/test_signature.py
index 86141a9..084f599 100644
--- a/src/mailman_pgp/rules/tests/test_signature.py
+++ b/src/mailman_pgp/rules/tests/test_signature.py
@@ -18,9 +18,9 @@ from unittest import TestCase
from mailman.app.lifecycle import create_list
from mailman.config import config
-from mailman.database.transaction import transaction as mailman_transaction
from mailman.testing.helpers import specialized_message_from_string as mfs
+from mailman_pgp.database import mm_transaction
from mailman_pgp.rules.signature import Signature
from mailman_pgp.testing.layers import PGPConfigLayer
@@ -29,7 +29,7 @@ class TestSignature(TestCase):
layer = PGPConfigLayer
def setUp(self):
- with mailman_transaction():
+ with mm_transaction():
self.mlist = create_list('nobody@example.com',
style_name='pgp-default')
@@ -37,7 +37,8 @@ class TestSignature(TestCase):
self.assertIn(Signature.name, config.rules.keys())
def test_no_pgp_list(self):
- ordinary_list = create_list('ordinary@example.com')
+ with mm_transaction():
+ ordinary_list = create_list('ordinary@example.com')
msg = mfs("""\
From: anne@example.com
To: ordinary@example.com
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)
diff --git a/src/mailman_pgp/testing/layers.py b/src/mailman_pgp/testing/layers.py
index d0d30d0..8ae2779 100644
--- a/src/mailman_pgp/testing/layers.py
+++ b/src/mailman_pgp/testing/layers.py
@@ -34,6 +34,9 @@ def reset_pgp_world():
Base.metadata.create_all(config.db.engine)
+# It's weird that ws have to do this, but for some reason nose2 test layers
+# don't work when ws create a mixin class with the two classmethods
+# and subclass both it and the respective Mailman Core test layer.
class PGPConfigLayer(ConfigLayer):
@classmethod
def tearDown(cls):