Exemplo n.º 1
0
 def unsubscribe(self, content_id, email, token):
     # Check and confirm cancellation
     # NOTE: no doc string, so, not *publishable* TTW
     #
     content = get_subscribable_content(content_id)
     manager = ISubscriptionManager(content, None)
     if manager is None:
         raise errors.CancellationError()
     email = urllib.unquote(email)
     if not self._validate_token(
         content_id, email, 'confirm_cancellation', token):
         raise errors.CancellationError()
     manager.unsubscribe(email)
    def test_subscribe_unsubscribe(self):
        manager = ISubscriptionManager(self.root.document)
        manager.subscribability = SUBSCRIBABLE
        self.assertEqual(manager.locally_subscribed_emails, set([]))
        self.assertEqual(manager.is_subscribed("*****@*****.**"), False)

        # we can subscribe some emails
        manager.subscribe("*****@*****.**")
        manager.subscribe("*****@*****.**")
        manager.subscribe("*****@*****.**")
        self.assertEqual(manager.locally_subscribed_emails, set(["*****@*****.**", "*****@*****.**"]))
        self.assertEqual(manager.is_subscribed("*****@*****.**"), True)

        # and unscribe others
        manager.unsubscribe("*****@*****.**")
        manager.unsubscribe("*****@*****.**")
        self.assertEqual(manager.locally_subscribed_emails, set(["*****@*****.**"]))
        self.assertEqual(manager.is_subscribed("*****@*****.**"), False)