def test_valid(self):
     channel1 = ChannelConfig(name='ch1',
                              mailbox_path='/var/mail/ch1',
                              query='label:ch1')
     group1 = GroupConfig(name='gr1', channels=['ch1'])
     config = Config(channels={'ch1': channel1}, groups={'gr1': group1})
     self.validator.validate(config)
 def test_invalid_channels_in_group(self):
     channel1 = ChannelConfig(name='ch1',
                              mailbox_path='/var/mail/ch1',
                              query='label:ch1')
     group1 = GroupConfig(name='gr1', channels=['other'])
     config = Config(channels={'ch1': channel1}, groups={'gr1': group1})
     with self.assertRaisesRegex(
             ConfigurationError,
             "Channel 'other' in group 'gr1' is not defined"):
         self.validator.validate(config)
    def test_channel_factory(self, mock_mailbox):
        ch1 = ChannelConfig(name='ch1', mailbox_path='/mail/ch1', box_type='maildir', query='label:STARRED')
        ch2 = ChannelConfig(name='ch2', mailbox_path='/mail/ch2', box_type='maildir', query='label:INBOX')
        ch3 = ChannelConfig(name='ch3', mailbox_path='/mail/ch3', box_type='mbox', query='other query')
        config = Config(channels=[ch1, ch2, ch3])

        channels_to_sync = ['ch1', 'ch3']

        channels = channel_factory(config, channels_to_sync)

        self.assertEqual(len(channels), 2)
        self._verify_channel(channels[0], 'ch1', 'label:STARRED')
        self._verify_channel(channels[1], 'ch3', 'other query')

        mock_mailbox.assert_has_calls([
            call('maildir', '/mail/ch1'),
            call('mbox', '/mail/ch3')
        ])
Exemple #4
0
class ConfigFilterTestCase(unittest.TestCase):

    def setUp(self):
        self.config = Config(channels={'ch1': CH1, 'ch2': CH2, 'ch3': CH3}, groups={'gr1': GR1})

    def test_no_filter(self):
        channels = self.config.get_channels()
        self._verify_eq_channels(channels, ['ch1', 'ch2', 'ch3'])

    def test_none_filter(self):
        channels = self.config.get_channels(names=None)
        self._verify_eq_channels(channels, ['ch1', 'ch2', 'ch3'])

    def test_empty_filter(self):
        channels = self.config.get_channels(names=[])
        self._verify_eq_channels(channels, ['ch1', 'ch2', 'ch3'])

    def test_valid_channel_filter(self):
        channels = self.config.get_channels(names=['ch1', 'ch3'])
        self._verify_eq_channels(channels, ['ch1', 'ch3'])

    def test_valid_group_filter(self):
        channels = self.config.get_channels(names=['gr1'])
        self._verify_eq_channels(channels, ['ch1', 'ch2'])

    def test_valid_channel_and_group_filter(self):
        channels = self.config.get_channels(names=['gr1', 'ch3'])
        self._verify_eq_channels(channels, ['ch1', 'ch2', 'ch3'])

    def test_invalid_filter(self):
        with self.assertRaisesRegex(ValueError, "Channel 'INVALID' is not present in config file"):
            self.config.get_channels(names=['INVALID'])

    def _verify_eq_channels(self, channels, expected_names):
        channel_names = [c.name for c in channels]
        self.assertEqual(channel_names, expected_names)
 def test_no_channels(self):
     config = Config()
     with self.assertRaisesRegex(ConfigurationError,
                                 'No channels found in config'):
         self.validator.validate(config)
Exemple #6
0
 def setUp(self):
     self.config = Config(channels={'ch1': CH1, 'ch2': CH2, 'ch3': CH3}, groups={'gr1': GR1})
Exemple #7
0
 def test_invalid_groups(self):
     with self.assertRaises(ValueError):
         config = Config(groups='invalid')
Exemple #8
0
 def test_groups_from_tuple(self):
     config = Config(groups=(GR1, GR2))
     self.assertEqual(config.groups, {'gr1': GR1, 'gr2': GR2})
Exemple #9
0
 def test_groups_from_list(self):
     config = Config(groups=[GR1, GR2])
     self.assertEqual(config.groups, {'gr1': GR1, 'gr2': GR2})
Exemple #10
0
 def test_groups_from_dict(self):
     config = Config(groups={'gr1': GR1, 'gr2': GR2})
     self.assertEqual(config.groups, {'gr1': GR1, 'gr2': GR2})
Exemple #11
0
 def test_invalid_channels(self):
     with self.assertRaises(ValueError):
         config = Config(channels='invalid')
Exemple #12
0
 def test_channels_from_list(self):
     config = Config(channels=[CH1, CH2])
     self.assertEqual(config.channels, {'ch1': CH1, 'ch2': CH2})
Exemple #13
0
 def test_channels_from_tuple(self):
     config = Config(channels=(CH1, CH2))
     self.assertEqual(config.channels, {'ch1': CH1, 'ch2': CH2})
Exemple #14
0
 def test_channels_from_dict(self):
     config = Config(channels={'ch1': CH1, 'ch2': CH2})
     self.assertEqual(config.channels, {'ch1': CH1, 'ch2': CH2})