1 # Copyright (C) 2015 by the Free Software Foundation, Inc.
3 # This file is part of GNU Mailman.
5 # GNU Mailman is free software: you can redistribute it and/or modify it under
6 # the terms of the GNU General Public License as published by the Free
7 # Software Foundation, either version 3 of the License, or (at your option)
10 # GNU Mailman is distributed in the hope that it will be useful, but WITHOUT
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 # You should have received a copy of the GNU General Public License along with
16 # GNU Mailman. If not, see <http://www.gnu.org/licenses/>.
18 """Test the MHonArc archiver."""
31 from mailman
.archiving
.mhonarc
import MHonArc
32 from mailman
.app
.lifecycle
import create_list
33 from mailman
.database
.transaction
import transaction
34 from mailman
.testing
.helpers
import (
35 configuration
, specialized_message_from_string
as mfs
)
36 from mailman
.testing
.layers
import ConfigLayer
37 from pkg_resources
import resource_filename
40 class TestMhonarc(unittest
.TestCase
):
41 """Test the MHonArc archiver."""
46 # Create a fake mailing list and message object.
49 From: anne@example.com
50 Subject: Testing the test list
52 Message-ID-Hash: MS6QLWERIJLGCRF44J7USBFDELMNT2BW
54 Tests are better than no tests
55 but the water deserves to be swum.
58 self
._mlist
= create_list('test@example.com')
59 tempdir
= tempfile
.mkdtemp()
60 self
.addCleanup(shutil
.rmtree
, tempdir
)
61 # Here's the command to execute our fake MHonArc process.
63 resource_filename('mailman.archiving.tests', 'fake_mhonarc.py'),
65 self
._output
_file
= os
.path
.join(tempdir
, 'output.txt')
66 command
= '{} {} {}'.format(
68 os
.path
.join(tempdir
, 'fake_mhonarc.py'),
70 # Write an external configuration file which points the command at our
71 # fake MHonArc process.
72 self
._cfg
= os
.path
.join(tempdir
, 'mhonarc.cfg')
73 with
open(self
._cfg
, 'w', encoding
='utf-8') as fp
:
76 base_url: http://$hostname/archives/$fqdn_listname
78 """.format(command
=command
), file=fp
)
80 def test_mhonarc(self
):
81 # The archiver properly sends stdin to the subprocess.
82 with
configuration('archiver.mhonarc',
83 configuration
=self
._cfg
,
85 MHonArc().archive_message(self
._mlist
, self
._msg
)
86 with
open(self
._output
_file
, 'r', encoding
='utf-8') as fp
:
87 results
= fp
.read().splitlines()
88 self
.assertEqual(results
[0], '<ant>')
89 self
.assertEqual(results
[1], 'MS6QLWERIJLGCRF44J7USBFDELMNT2BW')