'We provide one-click unsubscribe links in digest e-mails that you can
click even when logged out to stop receiving them.
Unsubscribing from these emails also dequeues any digest email jobs that
have been queued.'

def test_digest_unsubscribe(self):

    user_profile = self.example_user('hamlet')
    self.assertTrue(user_profile.enable_digest_emails)
    context = {'name': '', 'realm_uri': '', 'unread_pms': [], 'hot_conversations': [], 'new_users': [], 'new_streams': {'plain': []}, 'unsubscribe_link': ''}
    send_future_email('zerver/emails/digest', to_user_id=user_profile.id, context=context)
    self.assertEqual(1, ScheduledEmail.objects.filter(user=user_profile).count())
    unsubscribe_link = one_click_unsubscribe_link(user_profile, 'digest')
    result = self.client_get(urllib.parse.urlparse(unsubscribe_link).path)
    self.assertEqual(result.status_code, 200)
    user_profile = UserProfile.objects.get(email=self.example_email('hamlet'))
    self.assertFalse(user_profile.enable_digest_emails)
    self.assertEqual(0, ScheduledEmail.objects.filter(user=user_profile).count())
