Beispiel #1
0
    def test_daily_digest(self):
        from repoze.sendmail.interfaces import IMailDelivery
        from pyramid.interfaces import IRequest
        from karl.models.interfaces import IProfile
        from karl.testing import DummyMailer

        mailer = DummyMailer()
        self.config.registry.registerUtility(mailer, IMailDelivery)

        community = DummyCommunity()
        community["foo"] = context = testing.DummyModel()
        directlyProvides(context, IDummy)

        site = community.__parent__.__parent__
        site["profiles"] = profiles = testing.DummyModel()
        profiles["a"] = DummyProfile()
        profiles["a"].set_alerts_preference(community.__name__,
                                            IProfile.ALERT_DAILY_DIGEST)
        profiles["b"] = DummyProfile()
        profiles["b"].set_alerts_preference(community.__name__,
                                            IProfile.ALERT_DAILY_DIGEST)

        community.member_names = set(("a", ))
        community.moderator_names = set(("b", ))

        request = testing.DummyRequest()
        self.config.registry.registerAdapter(DummyEmailAlertAdapter,
                                             (IDummy, IProfile, IRequest),
                                             IAlert)

        tool = self._get_instance()
        tool.emit(context, request)
        community.moderator_names = set()
        tool.emit(context, request)

        self.assertEqual(0, len(mailer))
        self.assertEqual(2, len(list(profiles["a"]._pending_alerts)))
        self.assertEqual(1, len(list(profiles["b"]._pending_alerts)))

        self.config.testing_add_renderer('karl.utilities:email_digest.pt')

        tool.send_digests(site, 'daily')

        self.assertEqual(0, len(list(profiles["a"]._pending_alerts)))
        self.assertEqual(0, len(list(profiles["b"]._pending_alerts)))

        self.assertEqual(2, len(mailer))
        mtos = [x.mto for x in mailer]
        self.assertTrue([
            '*****@*****.**',
        ] in mtos)
        self.assertTrue([
            '*****@*****.**',
        ] in mtos)
Beispiel #2
0
    def test_digest(self):
        from repoze.sendmail.interfaces import IMailDelivery
        from pyramid.interfaces import IRequest
        from karl.models.interfaces import IProfile
        from karl.testing import DummyMailer

        mailer = DummyMailer()
        self.config.registry.registerUtility(mailer, IMailDelivery)

        community = DummyCommunity()
        community["foo"] = context = testing.DummyModel()
        directlyProvides(context, IDummy)

        site = community.__parent__.__parent__
        site["profiles"] = profiles = testing.DummyModel()
        profiles["a"] = DummyProfile()
        profiles["a"].set_alerts_preference(community.__name__,
                                            IProfile.ALERT_DIGEST)
        profiles["b"] = DummyProfile()
        profiles["b"].set_alerts_preference(community.__name__,
                                            IProfile.ALERT_DIGEST)

        community.member_names = set(("a",))
        community.moderator_names = set(("b",))

        request = testing.DummyRequest()
        self.config.registry.registerAdapter(DummyEmailAlertAdapter,
                                             (IDummy, IProfile, IRequest),
                                             IAlert)

        tool = self._get_instance()
        tool.emit(context, request)
        community.moderator_names = set()
        tool.emit(context, request)

        self.assertEqual(0, len(mailer))
        self.assertEqual(2, len(profiles["a"]._pending_alerts))
        self.assertEqual(1, len(profiles["b"]._pending_alerts))

        self.config.testing_add_renderer('karl.utilities:email_digest.pt')

        tool.send_digests(site)

        self.assertEqual(2, len(mailer))
        self.assertEqual(0, len(profiles["a"]._pending_alerts))
        self.assertEqual(0, len(profiles["b"]._pending_alerts))

        self.assertEqual(['*****@*****.**',], mailer[0].mto)
        self.assertEqual(['*****@*****.**',], mailer[1].mto)
Beispiel #3
0
    def test_emit(self):
        from repoze.sendmail.interfaces import IMailDelivery
        from pyramid.interfaces import IRequest
        from karl.models.interfaces import IProfile
        from karl.testing import DummyMailer

        mailer = DummyMailer()
        self.config.registry.registerUtility(mailer, IMailDelivery)

        community = DummyCommunity()
        community["foo"] = context = testing.DummyModel()
        directlyProvides(context, IDummy)

        site = community.__parent__.__parent__
        site["profiles"] = profiles = testing.DummyModel()
        profiles["a"] = DummyProfile()
        profiles["b"] = DummyProfile()
        profiles["c"] = DummyProfile()

        community.member_names = set((
            "a",
            "c",
        ))
        community.moderator_names = set(("b", ))

        request = testing.DummyRequest()
        self.config.registry.registerAdapter(DummyEmailAlertAdapter,
                                             (IDummy, IProfile, IRequest),
                                             IAlert)

        self._get_instance().emit(context, request)
        self.assertEqual(3, len(mailer))
Beispiel #4
0
    def test_respect_alert_prefs(self):
        from repoze.sendmail.interfaces import IMailDelivery
        from pyramid.interfaces import IRequest
        from karl.models.interfaces import IProfile
        from karl.testing import DummyMailer

        mailer = DummyMailer()
        self.config.registry.registerUtility(mailer, IMailDelivery)

        community = DummyCommunity()
        community["foo"] = context = testing.DummyModel()
        directlyProvides(context, IDummy)

        site = community.__parent__.__parent__
        site["profiles"] = profiles = testing.DummyModel()
        profiles["a"] = DummyProfile()
        profiles["b"] = DummyProfile()
        profiles["b"].set_alerts_preference(community.__name__,
                                            IProfile.ALERT_DIGEST)
        profiles["c"] = DummyProfile()
        profiles["c"].set_alerts_preference(community.__name__,
                                            IProfile.ALERT_NEVER)

        community.member_names = set(("a","c",))
        community.moderator_names = set(("b",))

        request = testing.DummyRequest()
        self.config.registry.registerAdapter(DummyEmailAlertAdapter,
                                             (IDummy, IProfile, IRequest),
                                             IAlert)

        self._get_instance().emit(context, request)
        self.assertEqual(1, len(mailer))
        self.assertEqual(1, len(profiles["b"]._pending_alerts))
Beispiel #5
0
    def test_emit(self):
        from repoze.sendmail.interfaces import IMailDelivery
        from repoze.bfg.interfaces import IRequest
        from karl.models.interfaces import IProfile
        from karl.testing import DummyMailer

        mailer = DummyMailer()
        testing.registerUtility(mailer, IMailDelivery)

        community = DummyCommunity()
        community["foo"] = context = testing.DummyModel()
        directlyProvides(context, IDummy)

        site = community.__parent__.__parent__
        site["profiles"] = profiles = testing.DummyModel()
        profiles["a"] = DummyProfile()
        profiles["b"] = DummyProfile()
        profiles["c"] = DummyProfile()

        community.member_names = set(("a","c",))
        community.moderator_names = set(("b",))

        request = testing.DummyRequest()
        testing.registerAdapter(DummyEmailAlertAdapter,
                                (IDummy, IProfile, IRequest), IAlert)

        self._get_instance().emit(context, request)
        self.assertEqual(3, len(mailer))
Beispiel #6
0
    def setUp(self):
        cleanUp()
        # Register mail utility
        from repoze.sendmail.interfaces import IMailDelivery
        from karl.testing import DummyMailer
        self.mailer = DummyMailer()
        karl.testing.registerUtility(self.mailer, IMailDelivery)

        # Register BlogCommentAlert adapter
        from karl.models.interfaces import IProfile
        from karl.models.interfaces import IComment
        from karl.content.views.adapters import BlogCommentAlert
        from karl.utilities.interfaces import IAlert
        from pyramid.interfaces import IRequest
        karl.testing.registerAdapter(BlogCommentAlert,
                                     (IComment, IProfile, IRequest), IAlert)

        # Register IShowSendAlert adapter
        self.show_sendalert = True
        from karl.content.views.interfaces import IShowSendalert

        class DummyShowSendalert(object):
            def __init__(myself, context, request):
                myself.show_sendalert = self.show_sendalert

        karl.testing.registerAdapter(DummyShowSendalert,
                                     (Interface, Interface), IShowSendalert)

        # Create dummy site skel
        from karl.testing import DummyCommunity
        from karl.testing import DummyProfile
        community = DummyCommunity()
        site = community.__parent__.__parent__
        site.sessions = DummySessions()
        profiles = testing.DummyModel()
        site["profiles"] = profiles
        profiles["a"] = DummyProfile()
        profiles["b"] = DummyProfile()
        profiles["c"] = DummyProfile()
        community.member_names = set([
            "b",
            "c",
        ])
        community.moderator_names = set([
            "a",
        ])
        blog = testing.DummyModel()
        community["blog"] = blog
        blogentry = blog["foo"] = DummyBlogEntry()
        self.context = blogentry["comments"]

        # Create dummy request
        request = testing.DummyRequest()
        request.environ['repoze.browserid'] = '1'
        self.request = request
Beispiel #7
0
    def test_weekly_digests(self):
        from repoze.sendmail.interfaces import IMailDelivery
        from pyramid.interfaces import IRequest
        from karl.models.interfaces import IProfile
        from karl.testing import DummyMailer

        mailer = DummyMailer()
        self.config.registry.registerUtility(mailer, IMailDelivery)

        community = DummyCommunity()
        community["foo"] = context = testing.DummyModel()
        directlyProvides(context, IDummy)

        site = community.__parent__.__parent__
        site["profiles"] = profiles = testing.DummyModel()
        profiles["a"] = DummyProfile()
        profiles["a"].set_alerts_preference(community.__name__, IProfile.ALERT_DAILY_DIGEST)
        profiles["b"] = DummyProfile()
        profiles["b"].set_alerts_preference(community.__name__, IProfile.ALERT_WEEKLY_DIGEST)
        profiles["c"] = DummyProfile()
        profiles["c"].set_alerts_preference(community.__name__, IProfile.ALERT_BIWEEKLY_DIGEST)

        community.member_names = set(("a", "b", "c"))
        community.moderator_names = set()

        request = testing.DummyRequest()
        self.config.registry.registerAdapter(DummyEmailAlertAdapter, (IDummy, IProfile, IRequest), IAlert)

        tool = self._get_instance()
        tool.emit(context, request)
        tool.emit(context, request)

        self.assertEqual(0, len(mailer))
        self.assertEqual(2, len(list(profiles["a"]._pending_alerts)))
        self.assertEqual(2, len(list(profiles["b"]._pending_alerts)))
        self.assertEqual(2, len(list(profiles["c"]._pending_alerts)))

        self.config.testing_add_renderer("karl.utilities:email_digest.pt")

        tool.send_digests(site, "weekly")

        self.assertEqual(0, len(list(profiles["a"]._pending_alerts)))
        self.assertEqual(0, len(list(profiles["b"]._pending_alerts)))
        self.assertEqual(2, len(list(profiles["c"]._pending_alerts)))

        self.assertEqual(2, len(mailer))
        self.assertEqual(0, len(list(list(profiles["a"]._pending_alerts))))
        self.assertEqual(0, len(list(list(profiles["b"]._pending_alerts))))
        mtos = [x.mto for x in mailer]
        self.assertTrue(["*****@*****.**"] in mtos)
        self.assertTrue(["*****@*****.**"] in mtos)
Beispiel #8
0
    def setUp(self):
        cleanUp()
        # Register mail utility
        from repoze.sendmail.interfaces import IMailDelivery
        from karl.testing import DummyMailer
        self.mailer = DummyMailer()
        karl.testing.registerUtility(self.mailer, IMailDelivery)

        # Register BlogCommentAlert adapter
        from karl.models.interfaces import IProfile
        from karl.models.interfaces import IComment
        from karl.content.views.adapters import BlogCommentAlert
        from karl.utilities.interfaces import IAlert
        from pyramid.interfaces import IRequest
        karl.testing.registerAdapter(BlogCommentAlert,
                                     (IComment, IProfile, IRequest),
                                     IAlert)

        # Register IShowSendAlert adapter
        self.show_sendalert = True
        from karl.content.views.interfaces import IShowSendalert
        class DummyShowSendalert(object):
            def __init__(myself, context, request):
                myself.show_sendalert = self.show_sendalert

        karl.testing.registerAdapter(DummyShowSendalert, (Interface, Interface),
                                     IShowSendalert)

        # Create dummy site skel
        from karl.testing import DummyCommunity
        from karl.testing import DummyProfile
        community = DummyCommunity()
        site = community.__parent__.__parent__
        site.sessions = DummySessions()
        profiles = testing.DummyModel()
        site["profiles"] = profiles
        profiles["a"] = DummyProfile()
        profiles["b"] = DummyProfile()
        profiles["c"] = DummyProfile()
        community.member_names = set(["b", "c",])
        community.moderator_names = set(["a",])
        blog = testing.DummyModel()
        community["blog"] = blog
        blogentry = blog["foo"] = DummyBlogEntry()
        self.context = blogentry["comments"]

        # Create dummy request
        request = testing.DummyRequest()
        request.environ['repoze.browserid'] = '1'
        self.request = request
Beispiel #9
0
    def test_respect_alert_prefs(self):
        from repoze.sendmail.interfaces import IMailDelivery
        from pyramid.interfaces import IRequest
        from karl.models.interfaces import IProfile
        from karl.testing import DummyMailer

        mailer = DummyMailer()
        self.config.registry.registerUtility(mailer, IMailDelivery)

        community = DummyCommunity()
        community["foo"] = context = testing.DummyModel()
        directlyProvides(context, IDummy)

        site = community.__parent__.__parent__
        site["profiles"] = profiles = testing.DummyModel()
        profiles["a"] = DummyProfile()
        profiles["b"] = DummyProfile()
        profiles["b"].set_alerts_preference(community.__name__,
                                            IProfile.ALERT_DAILY_DIGEST)
        profiles["c"] = DummyProfile()
        profiles["c"].set_alerts_preference(community.__name__,
                                            IProfile.ALERT_NEVER)
        profiles["d"] = DummyProfile()
        profiles["d"].set_alerts_preference(community.__name__,
                                            IProfile.ALERT_WEEKLY_DIGEST)
        profiles["e"] = DummyProfile()
        profiles["e"].set_alerts_preference(community.__name__,
                                            IProfile.ALERT_BIWEEKLY_DIGEST)

        community.member_names = set((
            "a",
            "c",
        ))
        community.moderator_names = set(("b", ))

        request = testing.DummyRequest()
        self.config.registry.registerAdapter(DummyEmailAlertAdapter,
                                             (IDummy, IProfile, IRequest),
                                             IAlert)

        self._get_instance().emit(context, request)
        self.assertEqual(1, len(mailer))
        self.assertEqual(1, len(list(profiles["b"]._pending_alerts)))
Beispiel #10
0
    def setUp(self):
        cleanUp()

        # Register mail utility
        from repoze.sendmail.interfaces import IMailDelivery
        from karl.testing import DummyMailer
        self.mailer = DummyMailer()
        testing.registerUtility(self.mailer, IMailDelivery)

        # Register BlogCommentAlert adapter
        from karl.models.interfaces import IProfile
        from karl.models.interfaces import IComment
        from karl.content.views.adapters import BlogCommentAlert
        from karl.utilities.interfaces import IAlert
        from repoze.bfg.interfaces import IRequest
        testing.registerAdapter(BlogCommentAlert,
                                (IComment, IProfile, IRequest),
                                IAlert)

        # Create dummy site skel
        from karl.testing import DummyCommunity
        from karl.testing import DummyProfile
        community = DummyCommunity()
        site = community.__parent__.__parent__

        profiles = testing.DummyModel()
        site["profiles"] = profiles
        profiles["a"] = DummyProfile()
        profiles["b"] = DummyProfile()
        profiles["c"] = DummyProfile()

        community.member_names = set(["b", "c",])
        community.moderator_names = set(["a",])

        blog = testing.DummyModel()
        community["blog"] = blog

        blogentry = blog["foo"] = DummyBlogEntry()

        self.context = blogentry["comments"]