本文整理汇总了Python中mailman.app.subscriptions.SubscriptionWorkflow类的典型用法代码示例。如果您正苦于以下问题:Python SubscriptionWorkflow类的具体用法?Python SubscriptionWorkflow怎么用?Python SubscriptionWorkflow使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SubscriptionWorkflow类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_moderator_approves
def test_moderator_approves(self):
# The workflow runs until moderator approval is required, at which
# point the workflow is saved. Once the moderator approves, the
# workflow resumes and the user is subscribed.
self._mlist.subscription_policy = SubscriptionPolicy.moderate
anne = self._user_manager.create_address(self._anne)
workflow = SubscriptionWorkflow(self._mlist, anne,
pre_verified=True,
pre_confirmed=True)
# Consume the entire state machine.
list(workflow)
# The user is not currently subscribed to the mailing list.
member = self._mlist.regular_members.get_member(self._anne)
self.assertIsNone(member)
self.assertIsNone(workflow.member)
# The token is owned by the moderator.
self.assertIsNotNone(workflow.token)
self.assertEqual(workflow.token_owner, TokenOwner.moderator)
# Create a new workflow with the previous workflow's save token, and
# restore its state. This models an approved subscription and should
# result in the user getting subscribed.
approved_workflow = SubscriptionWorkflow(self._mlist)
approved_workflow.token = workflow.token
approved_workflow.restore()
list(approved_workflow)
# Now the user is subscribed to the mailing list.
member = self._mlist.regular_members.get_member(self._anne)
self.assertEqual(member.address, anne)
self.assertEqual(approved_workflow.member, member)
# No further token is needed.
self.assertIsNone(approved_workflow.token)
self.assertEqual(approved_workflow.token_owner, TokenOwner.no_one)
示例2: test_do_subscription_cleanups
def test_do_subscription_cleanups(self):
# Once the user is subscribed, the token, and its associated pending
# database record will be removed from the database.
self._mlist.subscription_policy = SubscriptionPolicy.open
anne = self._user_manager.create_address(self._anne)
workflow = SubscriptionWorkflow(self._mlist, anne,
pre_verified=True,
pre_confirmed=True,
pre_approved=True)
# Cache the token.
token = workflow.token
# Consume the entire state machine.
list(workflow)
# Anne is now a member of the mailing list.
member = self._mlist.regular_members.get_member(self._anne)
self.assertEqual(member.address, anne)
self.assertEqual(workflow.member, member)
# The workflow is done, so it has no token.
self.assertIsNone(workflow.token)
self.assertEqual(workflow.token_owner, TokenOwner.no_one)
# The pendable associated with the token has been evicted.
self.assertIsNone(getUtility(IPendings).confirm(token, expunge=False))
# There is no saved workflow associated with the token. This shows up
# as an exception when we try to restore the workflow.
new_workflow = SubscriptionWorkflow(self._mlist)
new_workflow.token = token
self.assertRaises(LookupError, new_workflow.restore)
示例3: test_do_confirmation_subscribes_user
def test_do_confirmation_subscribes_user(self):
# Subscriptions to the mailing list must be confirmed. Once that's
# done, the user's address (which is not initially verified) gets
# subscribed to the mailing list.
self._mlist.subscription_policy = SubscriptionPolicy.confirm
anne = self._user_manager.create_address(self._anne)
self.assertIsNone(anne.verified_on)
workflow = SubscriptionWorkflow(self._mlist, anne)
list(workflow)
# Anne is not yet a member.
member = self._mlist.regular_members.get_member(self._anne)
self.assertIsNone(member)
self.assertIsNone(workflow.member)
# The token is owned by the subscriber.
self.assertIsNotNone(workflow.token)
self.assertEqual(workflow.token_owner, TokenOwner.subscriber)
# Confirm.
confirm_workflow = SubscriptionWorkflow(self._mlist)
confirm_workflow.token = workflow.token
confirm_workflow.restore()
list(confirm_workflow)
self.assertIsNotNone(anne.verified_on)
# Anne is now a member.
member = self._mlist.regular_members.get_member(self._anne)
self.assertEqual(member.address, anne)
self.assertEqual(confirm_workflow.member, member)
# No further token is needed.
self.assertIsNone(confirm_workflow.token)
self.assertEqual(confirm_workflow.token_owner, TokenOwner.no_one)
示例4: confirm
def confirm(self, token):
"""See `IRegistrar`."""
workflow = SubscriptionWorkflow(self._mlist)
workflow.token = token
workflow.restore()
list(workflow)
return workflow.token, workflow.token_owner, workflow.member
示例5: test_moderation_checks_approval_required
def test_moderation_checks_approval_required(self):
# The moderator must approve the subscription.
self._mlist.subscription_policy = SubscriptionPolicy.moderate
anne = self._user_manager.create_address(self._anne)
workflow = SubscriptionWorkflow(self._mlist, anne, pre_verified=True)
workflow.run_thru('moderation_checks')
with patch.object(workflow, '_step_get_moderator_approval') as step:
next(workflow)
step.assert_called_once_with()
示例6: test_confirmation_checks_confirmation_needed
def test_confirmation_checks_confirmation_needed(self):
# The subscription policy requires confirmation and the subscription
# is not pre-confirmed.
self._mlist.subscription_policy = SubscriptionPolicy.confirm
anne = self._user_manager.create_address(self._anne)
workflow = SubscriptionWorkflow(self._mlist, anne, pre_verified=True)
workflow.run_thru('confirmation_checks')
with patch.object(workflow, '_step_send_confirmation') as step:
next(workflow)
step.assert_called_once_with()
示例7: test_confirmation_checks_no_user_confirmation_needed
def test_confirmation_checks_no_user_confirmation_needed(self):
# A subscription to a list which does not need user confirmation skips
# to the moderation checks.
self._mlist.subscription_policy = SubscriptionPolicy.moderate
anne = self._user_manager.create_address(self._anne)
workflow = SubscriptionWorkflow(self._mlist, anne, pre_verified=True)
workflow.run_thru('confirmation_checks')
with patch.object(workflow, '_step_moderation_checks') as step:
next(workflow)
step.assert_called_once_with()
示例8: test_confirmation_checks_open_list
def test_confirmation_checks_open_list(self):
# A subscription to an open list does not need to be confirmed or
# moderated.
self._mlist.subscription_policy = SubscriptionPolicy.open
anne = self._user_manager.create_address(self._anne)
workflow = SubscriptionWorkflow(self._mlist, anne, pre_verified=True)
workflow.run_thru('confirmation_checks')
with patch.object(workflow, '_step_do_subscription') as step:
next(workflow)
step.assert_called_once_with()
示例9: test_verification_checks_with_verified_address
def test_verification_checks_with_verified_address(self):
# When the address is already verified, we skip straight to the
# confirmation checks.
anne = self._user_manager.create_address(self._anne)
anne.verified_on = now()
workflow = SubscriptionWorkflow(self._mlist, anne)
workflow.run_thru('verification_checks')
with patch.object(workflow, '_step_confirmation_checks') as step:
next(workflow)
step.assert_called_once_with()
示例10: test_verification_checks_with_pre_verified_address
def test_verification_checks_with_pre_verified_address(self):
# When the address is not yet verified, but the pre-verified flag is
# passed to the workflow, we skip to the confirmation checks.
anne = self._user_manager.create_address(self._anne)
workflow = SubscriptionWorkflow(self._mlist, anne, pre_verified=True)
workflow.run_thru('verification_checks')
with patch.object(workflow, '_step_confirmation_checks') as step:
next(workflow)
step.assert_called_once_with()
# And now the address is verified.
self.assertIsNotNone(anne.verified_on)
示例11: test_sanity_checks_address
def test_sanity_checks_address(self):
# Ensure that the sanity check phase, when given an IAddress, ends up
# with a linked user.
anne = self._user_manager.create_address(self._anne)
workflow = SubscriptionWorkflow(self._mlist, anne)
self.assertIsNotNone(workflow.address)
self.assertIsNone(workflow.user)
workflow.run_thru('sanity_checks')
self.assertIsNotNone(workflow.address)
self.assertIsNotNone(workflow.user)
self.assertEqual(list(workflow.user.addresses)[0].email, self._anne)
示例12: test_sanity_checks_user_without_preferred_address
def test_sanity_checks_user_without_preferred_address(self):
# Ensure that the sanity check phase, when given a user without a
# preferred address, but with at least one linked address, gets an
# address.
anne = self._user_manager.make_user(self._anne)
workflow = SubscriptionWorkflow(self._mlist, anne)
self.assertIsNone(workflow.address)
self.assertEqual(workflow.user, anne)
workflow.run_thru('sanity_checks')
self.assertIsNotNone(workflow.address)
self.assertEqual(workflow.user, anne)
示例13: test_verification_checks_confirmation_needed
def test_verification_checks_confirmation_needed(self):
# The address is neither verified, nor is the pre-verified flag set.
# A confirmation message must be sent to the user which will also
# verify their address.
anne = self._user_manager.create_address(self._anne)
workflow = SubscriptionWorkflow(self._mlist, anne)
workflow.run_thru('verification_checks')
with patch.object(workflow, '_step_send_confirmation') as step:
next(workflow)
step.assert_called_once_with()
# The address still hasn't been verified.
self.assertIsNone(anne.verified_on)
示例14: test_confirmation_checks_confirm_and_moderate_pre_confirmed
def test_confirmation_checks_confirm_and_moderate_pre_confirmed(self):
# The subscription policy requires user confirmation and moderation,
# but their subscription is pre-confirmed.
self._mlist.subscription_policy = \
SubscriptionPolicy.confirm_then_moderate
anne = self._user_manager.create_address(self._anne)
workflow = SubscriptionWorkflow(self._mlist, anne,
pre_verified=True,
pre_confirmed=True)
workflow.run_thru('confirmation_checks')
with patch.object(workflow, '_step_moderation_checks') as step:
next(workflow)
step.assert_called_once_with()
示例15: test_sanity_checks_user_with_preferred_address
def test_sanity_checks_user_with_preferred_address(self):
# Ensure that the sanity check phase, when given an IUser with a
# preferred address, ends up with an address.
anne = self._user_manager.make_user(self._anne)
address = set_preferred(anne)
workflow = SubscriptionWorkflow(self._mlist, anne)
# The constructor sets workflow.address because the user has a
# preferred address.
self.assertEqual(workflow.address, address)
self.assertEqual(workflow.user, anne)
workflow.run_thru('sanity_checks')
self.assertEqual(workflow.address, address)
self.assertEqual(workflow.user, anne)