Exemplo n.º 1
0
    def test_getMessageTarget_report_alias_w_subdomain(self):
        from pyramid.traversal import resource_path
        from zope.interface import directlyProvides
        from karl.models.interfaces import IPeopleDirectory
        context = self._makeRoot()
        context.settings['system_list_subdomain'] = 'lists.example.com'
        cf = context['communities'] = self._makeContext()
        cf['testing'] = self._makeContext()
        pd = context['people'] = self._makeContext()
        directlyProvides(pd, IPeopleDirectory)
        section = pd['section'] = self._makeContext()
        extant = section['extant'] = self._makeContext()
        context.list_aliases['testing'] = resource_path(extant)
        mailin = self._makeOne(context)
        message = DummyMessage()
        message.to = ('*****@*****.**',)

        info = mailin.getMessageTargets(message)

        self.failIf(info.get('error'), info)
        targets = info['targets']
        self.assertEqual(len(targets), 1)
        info = targets[0]
        self.assertEqual(info['report'], 'section+extant')
        self.assertEqual(info['community'], None)
        self.assertEqual(info['tool'], None)
        self.failIf(info.get('in_reply_to'), info)
Exemplo n.º 2
0
    def test_getMessageTargets_no_To(self):
        mailin = self._makeOne()
        message = DummyMessage()
        info = mailin.getMessageTargets(message)

        self.assertEqual(info['error'],
                         'no community or distribution list specified')
Exemplo n.º 3
0
    def test_getMessageTarget_report_alias_doesnt_shadow_community(self):
        from repoze.bfg.interfaces import ISettings
        from repoze.bfg.testing import registerUtility
        from repoze.bfg.traversal import model_path
        from zope.interface import directlyProvides
        from karl.models.interfaces import IPeopleDirectory
        class DummySettings:
            system_list_subdomain = 'lists.example.com'
        registerUtility(DummySettings(), ISettings)
        context = self._makeRoot()
        cf = context['communities'] = self._makeContext()
        cf['testing'] = self._makeContext()
        pd = context['people'] = self._makeContext()
        directlyProvides(pd, IPeopleDirectory)
        section = pd['section'] = self._makeContext()
        extant = section['extant'] = self._makeContext()
        context.list_aliases['testing'] = model_path(extant)
        mailin = self._makeOne(context)
        mailin.default_tool = 'default'
        message = DummyMessage()
        message.to = ('*****@*****.**',)

        info = mailin.getMessageTargets(message)

        self.failIf(info.get('error'), info)
        targets = info['targets']
        self.assertEqual(len(targets), 1)
        info = targets[0]
        self.assertEqual(info['report'], None)
        self.assertEqual(info['community'], 'testing')
        self.assertEqual(info['tool'], 'default')
        self.assertEqual(info['in_reply_to'], None)
Exemplo n.º 4
0
    def test_getMessageTarget_reply_invalid_to_addr(self):
        context = self._makeRoot()
        context['communities'] = self._makeContext()
        mailin = self._makeOne(context)
        message = DummyMessage()
        message.to = ('undisclosed-recipients:;',)

        info = mailin.getMessageTargets(message)

        self.assertEqual(info['error'],
                         'no community or distribution list specified')
        self.assertEqual(len(info['targets']), 0)
Exemplo n.º 5
0
    def test_getMessageTarget_default_invalid_community(self):
        context = self._makeRoot()
        context['communities'] = self._makeContext()
        mailin = self._makeOne(context)
        mailin.default_tool = 'default'
        message = DummyMessage()
        message.to = ('*****@*****.**',)

        info = mailin.getMessageTargets(message)

        self.assertEqual(info['error'],
                         'no community or distribution list specified')
        self.assertEqual(len(info['targets']), 0)
Exemplo n.º 6
0
    def test_getMessageTarget_tool_ok_community_with_period(self):
        context = self._makeRoot()
        cf = context['communities'] = self._makeContext()
        cf['with-.dot'] = self._makeContext()
        mailin = self._makeOne(context)
        message = DummyMessage()
        message.to = ('*****@*****.**',)

        info = mailin.getMessageTargets(message)

        self.failIf(info.get('error'), info)
        targets = info['targets']
        self.assertEqual(len(targets), 1)
        info = targets[0]
        self.assertEqual(info['community'], 'with-.dot')
        self.assertEqual(info['tool'], 'tool')
        self.assertEqual(info['in_reply_to'], None)
Exemplo n.º 7
0
    def test_getMessageTargets_reply_invalid_community(self):
        context = self._makeRoot()
        context['communities'] = self._makeContext()
        mailin = self._makeOne(context)
        message = DummyMessage()
        message.to = ('*****@*****.**',)

        info = mailin.getMessageTargets(message)

        self.assertEqual(info['error'],
                         'no community or distribution list specified')
        self.assertEqual(len(info['targets']), 1)
        target = info['targets'][0]
        self.assertEqual(target['report'], None)
        self.assertEqual(target['community'], 'nonesuch')
        self.assertEqual(target['tool'], 'tool')
        self.assertEqual(target['in_reply_to'], '12345')
Exemplo n.º 8
0
    def test_getMessageTarget_tool_invalid_community(self):
        context = self._makeRoot()
        context['communities'] = self._makeContext()
        mailin = self._makeOne(context)
        message = DummyMessage()
        message.to = ('*****@*****.**',)

        info = mailin.getMessageTargets(message)

        self.failUnless(info['error'])
        targets = info['targets']
        self.assertEqual(len(targets), 1)
        info = targets[0]
        self.assertEqual(info['error'], 'invalid community: nonesuch')
        self.assertEqual(info['report'], None)
        self.assertEqual(info['community'], 'nonesuch')
        self.assertEqual(info['tool'], 'tool')
        self.assertEqual(info['in_reply_to'], None)
Exemplo n.º 9
0
    def test_getMessageTarget_reply_ok_target_in_X_Original_To(self):
        context = self._makeRoot()
        cf = context['communities'] = self._makeContext()
        cf['testing'] = self._makeContext()
        mailin = self._makeOne(context)
        message = DummyMessage()
        message.x_original_to = ('*****@*****.**',)

        info = mailin.getMessageTargets(message)

        self.failIf(info.get('error'))
        targets = info['targets']
        self.assertEqual(len(targets), 1)
        info = targets[0]
        self.assertEqual(info['report'], None)
        self.assertEqual(info['community'], 'testing')
        self.assertEqual(info['tool'], 'tool')
        self.assertEqual(info['in_reply_to'], '12345')
Exemplo n.º 10
0
    def test_getMessageTarget_reply_ok(self):
        context = self._makeRoot()
        cf = context['communities'] = self._makeContext()
        cf['testing'] = self._makeContext()
        mailin = self._makeOne(context)
        message = DummyMessage()
        message.to = ('*****@*****.**', )

        info = mailin.getMessageTargets(message)

        self.failIf(info.get('error'))
        targets = info['targets']
        self.assertEqual(len(targets), 1)
        info = targets[0]
        self.assertEqual(info['report'], None)
        self.assertEqual(info['community'], 'testing')
        self.assertEqual(info['tool'], 'tool')
        self.assertEqual(info['in_reply_to'], '12345')
Exemplo n.º 11
0
    def test_getMessageTarget_default_valid_community(self):
        context = self._makeRoot()
        cf = context['communities'] = self._makeContext()
        cf['testing'] = self._makeContext()
        mailin = self._makeOne(context)
        mailin.default_tool = 'default'
        message = DummyMessage()
        message.to = ('*****@*****.**',)

        info = mailin.getMessageTargets(message)

        self.failIf(info.get('error'))
        targets = info['targets']
        self.assertEqual(len(targets), 1)
        info = targets[0]
        self.assertEqual(info['report'], None)
        self.assertEqual(info['community'], 'testing')
        self.assertEqual(info['tool'], 'default')
        self.assertEqual(info['in_reply_to'], None)
Exemplo n.º 12
0
    def test_getMessageTarget_report_valid_report(self):
        from zope.interface import directlyProvides
        from karl.models.interfaces import IPeopleDirectory
        context = self._makeRoot()
        pd = context['people'] = self._makeContext()
        directlyProvides(pd, IPeopleDirectory)
        section = pd['section'] = self._makeContext()
        section['extant'] = self._makeContext()
        mailin = self._makeOne(context)
        message = DummyMessage()
        message.to = ('*****@*****.**', )

        info = mailin.getMessageTargets(message)

        self.failIf(info.get('error'), info)
        targets = info['targets']
        self.assertEqual(len(targets), 1)
        info = targets[0]
        self.assertEqual(info['report'], 'section+extant')
        self.assertEqual(info['community'], None)
        self.assertEqual(info['tool'], None)
        self.failIf(info.get('in_reply_to'), info)
Exemplo n.º 13
0
    def test_getMessageTarget_report_valid_report(self):
        from zope.interface import directlyProvides
        from karl.models.interfaces import IPeopleDirectory
        context = self._makeRoot()
        pd = context['people'] = self._makeContext()
        directlyProvides(pd, IPeopleDirectory)
        section = pd['section'] = self._makeContext()
        section['extant'] = self._makeContext()
        mailin = self._makeOne(context)
        message = DummyMessage()
        message.to = ('*****@*****.**',)

        info = mailin.getMessageTargets(message)

        self.failIf(info.get('error'), info)
        targets = info['targets']
        self.assertEqual(len(targets), 1)
        info = targets[0]
        self.assertEqual(info['report'], 'section+extant')
        self.assertEqual(info['community'], None)
        self.assertEqual(info['tool'], None)
        self.failIf(info.get('in_reply_to'), info)