summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/mailman/app/subscriptions.py6
-rw-r--r--src/mailman/app/tests/test_subscriptions.py15
-rw-r--r--src/mailman/app/tests/test_workflow.py10
-rw-r--r--src/mailman/app/workflow.py8
4 files changed, 31 insertions, 8 deletions
diff --git a/src/mailman/app/subscriptions.py b/src/mailman/app/subscriptions.py
index d72873616..ebb4198bb 100644
--- a/src/mailman/app/subscriptions.py
+++ b/src/mailman/app/subscriptions.py
@@ -71,7 +71,7 @@ class SubscriptionWorkflow(Workflow):
def __init__(self, mlist, subscriber,
pre_verified, pre_confirmed, pre_approved):
- super(SubscriptionWorkflow, self).__init__()
+ super().__init__()
self.mlist = mlist
# The subscriber must be either an IUser or IAddress.
if IAddress.providedBy(subscriber):
@@ -80,12 +80,12 @@ class SubscriptionWorkflow(Workflow):
elif IUser.providedBy(subscriber):
self.address = subscriber.preferred_address
self.user = subscriber
+ else:
+ raise AssertionError('subscriber is neither an IUser nor IAddress')
self.subscriber = subscriber
self.pre_verified = pre_verified
self.pre_confirmed = pre_confirmed
self.pre_approved = pre_approved
- # State saving
- self.SAVE_KEY = '{}:{}'.format(self.mlist.list_id, self.address.email)
def _maybe_set_preferred_address(self):
if self.user is None:
diff --git a/src/mailman/app/tests/test_subscriptions.py b/src/mailman/app/tests/test_subscriptions.py
index 5a767f463..d320284ce 100644
--- a/src/mailman/app/tests/test_subscriptions.py
+++ b/src/mailman/app/tests/test_subscriptions.py
@@ -82,6 +82,21 @@ class TestSubscriptionWorkflow(unittest.TestCase):
self._anne = 'anne@example.com'
self._user_manager = getUtility(IUserManager)
+ def test_user_or_address_required(self):
+ # The `subscriber` attribute must be a user or address.
+ self.assertRaises(AssertionError, SubscriptionWorkflow,
+ self._mlist,
+ 'not a user', False, False, False)
+
+ def test_user_without_preferred_address_gets_one(self):
+ # When subscribing a user without a preferred address, the first step
+ # in the workflow is to give the user a preferred address.
+ anne = self._user_manager.create_user(self._anne)
+ self.assertIsNone(anne.preferred_address)
+ workflow = SubscriptionWorkflow(self._mlist, anne, False, False, False)
+ next(workflow)
+
+
def test_preverified_address_joins_open_list(self):
# The mailing list has an open subscription policy, so the subscriber
# becomes a member with no human intervention.
diff --git a/src/mailman/app/tests/test_workflow.py b/src/mailman/app/tests/test_workflow.py
index 6bae46e8a..0f70042af 100644
--- a/src/mailman/app/tests/test_workflow.py
+++ b/src/mailman/app/tests/test_workflow.py
@@ -31,10 +31,10 @@ from mailman.testing.layers import ConfigLayer
class MyWorkflow(Workflow):
INITIAL_STATE = 'first'
SAVE_ATTRIBUTES = ('ant', 'bee', 'cat')
- SAVE_KEY = 'test-workflow'
def __init__(self):
super().__init__()
+ self.token = 'test-workflow'
self.ant = 1
self.bee = 2
self.cat = 3
@@ -116,3 +116,11 @@ class TestWorkflow(unittest.TestCase):
self.assertEqual(new_workflow.bee, 8)
self.assertEqual(new_workflow.cat, 7)
self.assertEqual(new_workflow.dog, 4)
+
+ def test_run_thru(self):
+ # Run all steps through the given one.
+ results = self._workflow.run_thru(second)
+ self.assertEqual(results, ['one', 'two'])
+
+ def test_run_until(self):
+ # Run until (but not including
diff --git a/src/mailman/app/workflow.py b/src/mailman/app/workflow.py
index bba5bb694..f9a951157 100644
--- a/src/mailman/app/workflow.py
+++ b/src/mailman/app/workflow.py
@@ -38,11 +38,11 @@ log = logging.getLogger('mailman.error')
class Workflow:
"""Generic workflow."""
- SAVE_KEY = ''
SAVE_ATTRIBUTES = ()
INITIAL_STATE = None
def __init__(self):
+ self.token = None
self._next = deque()
self.push(self.INITIAL_STATE)
@@ -68,7 +68,7 @@ class Workflow:
raise
def save(self):
- assert self.SAVE_KEY, 'Workflow SAVE_KEY must be set'
+ assert self.token, 'Workflow token must be set'
state_manager = getUtility(IWorkflowStateManager)
data = {attr: getattr(self, attr) for attr in self.SAVE_ATTRIBUTES}
# Note: only the next step is saved, not the whole stack. This is not
@@ -86,13 +86,13 @@ class Workflow:
"in the queue")
state_manager.save(
self.__class__.__name__,
- self.SAVE_KEY,
+ self.token,
step,
json.dumps(data))
def restore(self):
state_manager = getUtility(IWorkflowStateManager)
- state = state_manager.restore(self.__class__.__name__, self.SAVE_KEY)
+ state = state_manager.restore(self.__class__.__name__, self.token)
if state is not None:
self._next.clear()
if state.step: