~sambuddhabasu1/mailman/fix_mailman_run_error

« back to all changes in this revision

Viewing changes to src/mailman/runners/tests/test_archiver.py

  • Committer: Barry Warsaw
  • Date: 2012-04-01 18:53:38 UTC
  • mfrom: (7139.1.4 bug-967409)
  • Revision ID: barry@list.org-20120401185338-5qujo0c3kc9a8wtr
 * The `news` runner and queue has been renamed to the more accurate `nntp`.
   The runner has also been ported to Mailman 3 (LP: #967409).  Beta testers
   can can safely remove `$var_dir/queue/news`.

 * Configuration schema variable changes:
   [nntp]username -> [nntp]user
   [nntp]port (added)

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
from mailman.interfaces.archiver import IArchiver
37
37
from mailman.runners.archive import ArchiveRunner
38
38
from mailman.testing.helpers import (
 
39
    configuration,
39
40
    make_testable_runner,
40
41
    specialized_message_from_string as mfs)
41
42
from mailman.testing.layers import ConfigLayer
43
44
 
44
45
 
45
46
 
46
 
# This helper will set up a specific archiver as appropriate for a specific
47
 
# test.  It assumes the setUp() will just disable all archivers.
48
 
def archiver(name, enable=False, clobber=None, skew=None):
49
 
    def decorator(func):
50
 
        def wrapper(*args, **kws):
51
 
            config_name = 'archiver {0}'.format(name)
52
 
            section = """
53
 
            [archiver.{0}]
54
 
            enable: {1}
55
 
            clobber_date: {2}
56
 
            clobber_skew: {3}
57
 
            """.format(name,
58
 
                       'yes' if enable else 'no',
59
 
                       clobber, skew)
60
 
            config.push(config_name, section)
61
 
            try:
62
 
                return func(*args, **kws)
63
 
            finally:
64
 
                config.pop(config_name)
65
 
        return wrapper
66
 
    return decorator
67
 
 
68
 
 
69
 
 
70
47
class DummyArchiver:
71
48
    implements(IArchiver)
72
49
    name = 'dummy'
126
103
    def tearDown(self):
127
104
        config.pop('dummy')
128
105
 
129
 
    @archiver('dummy', enable=True)
 
106
    @configuration('archiver.dummy', enable='yes')
130
107
    def test_archive_runner(self):
131
108
        # Ensure that the archive runner ends up archiving the message.
132
109
        self._archiveq.enqueue(
141
118
            archived = message_from_file(fp)
142
119
        self.assertEqual(archived['message-id'], '<first>')
143
120
 
144
 
    @archiver('dummy', enable=True)
 
121
    @configuration('archiver.dummy', enable='yes')
145
122
    def test_archive_runner_with_dated_message(self):
146
123
        # Date headers don't throw off the archiver runner.
147
124
        self._msg['Date'] = now(strip_tzinfo=False).strftime(RFC822_DATE_FMT)
158
135
        self.assertEqual(archived['message-id'], '<first>')
159
136
        self.assertEqual(archived['date'], 'Mon, 01 Aug 2005 07:49:23 +0000')
160
137
 
161
 
    @archiver('dummy', enable=True, clobber='never')
 
138
    @configuration('archiver.dummy', enable='yes', clobber_date='never')
162
139
    def test_clobber_date_never(self):
163
140
        # Even if the Date header is insanely off from the received time of
164
141
        # the message, if clobber_date is 'never', the header is not clobbered.
176
153
        self.assertEqual(archived['message-id'], '<first>')
177
154
        self.assertEqual(archived['date'], 'Mon, 01 Aug 2005 07:49:23 +0000')
178
155
 
179
 
    @archiver('dummy', enable=True)
 
156
    @configuration('archiver.dummy', enable='yes')
180
157
    def test_clobber_dateless(self):
181
158
        # A message with no Date header will always get clobbered.
182
159
        self.assertEqual(self._msg['date'], None)
195
172
        self.assertEqual(archived['message-id'], '<first>')
196
173
        self.assertEqual(archived['date'], 'Mon, 01 Aug 2005 07:49:23 +0000')
197
174
 
198
 
    @archiver('dummy', enable=True, clobber='always')
 
175
    @configuration('archiver.dummy', enable='yes', clobber_date='always')
199
176
    def test_clobber_date_always(self):
200
177
        # The date always gets clobbered with the current received time.
201
178
        self._msg['Date'] = now(strip_tzinfo=False).strftime(RFC822_DATE_FMT)
216
193
        self.assertEqual(archived['x-original-date'],
217
194
                         'Mon, 01 Aug 2005 07:49:23 +0000')
218
195
 
219
 
    @archiver('dummy', enable=True, clobber='maybe', skew='1d')
 
196
    @configuration('archiver.dummy', 
 
197
                   enable='yes', clobber_date='maybe', clobber_skew='1d')
220
198
    def test_clobber_date_maybe_when_insane(self):
221
199
        # The date is clobbered if it's farther off from now than its skew
222
200
        # period.
238
216
        self.assertEqual(archived['x-original-date'],
239
217
                         'Mon, 01 Aug 2005 07:49:23 +0000')
240
218
 
241
 
    @archiver('dummy', enable=True, clobber='maybe', skew='10d')
 
219
    @configuration('archiver.dummy',
 
220
                   enable='yes', clobber_date='maybe', clobber_skew='10d')
242
221
    def test_clobber_date_maybe_when_sane(self):
243
222
        # The date is not clobbered if it's nearer to now than its skew
244
223
        # period.