Exemplo n.º 1
0
 def test_prototype_archiver_good_path(self):
     # Verify the good path; the message gets archived.
     Prototype.archive_message(self._mlist, self._msg)
     new_path = os.path.join(config.ARCHIVE_DIR, "prototype", self._mlist.fqdn_listname, "new")
     archived_messages = list(os.listdir(new_path))
     self.assertEqual(len(archived_messages), 1)
     # Check that the email has been added.
     with open(os.path.join(new_path, archived_messages[0])) as fp:
         archived_message = message_from_file(fp)
     self.assertEqual(self._msg.as_string(), archived_message.as_string())
Exemplo n.º 2
0
 def test_prototype_archiver_good_path(self):
     # Verify the good path; the message gets archived.
     Prototype.archive_message(self._mlist, self._msg)
     new_path = os.path.join(
         config.ARCHIVE_DIR, 'prototype', self._mlist.fqdn_listname, 'new')
     archived_messages = list(os.listdir(new_path))
     self.assertEqual(len(archived_messages), 1)
     # Check that the email has been added.
     with open(os.path.join(new_path, archived_messages[0])) as fp:
         archived_message = message_from_file(fp)
     self.assertEqual(self._msg.as_string(), archived_message.as_string())
Exemplo n.º 3
0
 def test_archive_maildir_created(self):
     # Archiving a message to the prototype archiver should create the
     # expected directory structure.
     Prototype.archive_message(self._mlist, self._msg)
     all_filenames = self._find(config.ARCHIVE_DIR)
     # Check that the directory structure has been created and we have one
     # more file (the archived message) than expected directories.
     archived_messages = all_filenames - self._expected_dir_structure
     self.assertEqual(len(archived_messages), 1)
     self.assertTrue(archived_messages.pop().startswith(
         os.path.join(config.ARCHIVE_DIR, 'prototype',
                      self._mlist.fqdn_listname, 'new')))
Exemplo n.º 4
0
 def test_archive_maildir_created(self):
     # Archiving a message to the prototype archiver should create the
     # expected directory structure.
     Prototype.archive_message(self._mlist, self._msg)
     all_filenames = self._find(config.ARCHIVE_DIR)
     # Check that the directory structure has been created and we have one
     # more file (the archived message) than expected directories.
     archived_messages = all_filenames - self._expected_dir_structure
     self.assertEqual(len(archived_messages), 1)
     self.assertTrue(
         archived_messages.pop().startswith(
             os.path.join(config.ARCHIVE_DIR, 'prototype',
                          self._mlist.fqdn_listname, 'new')))
Exemplo n.º 5
0
 def test_archive_maildir_existence_does_not_raise(self):
     # Archiving a second message does not cause an EEXIST to be raised
     # when a second message is archived.
     new_dir = None
     Prototype.archive_message(self._mlist, self._msg)
     for directory in ("cur", "new", "tmp"):
         path = os.path.join(config.ARCHIVE_DIR, "prototype", self._mlist.fqdn_listname, directory)
         if directory == "new":
             new_dir = path
         self.assertTrue(os.path.isdir(path))
     # There should be one message in the 'new' directory.
     self.assertEqual(len(os.listdir(new_dir)), 1)
     # Archive a second message.  If an exception occurs, let it fail the
     # test.  Afterward, two messages should be in the 'new' directory.
     del self._msg["message-id"]
     del self._msg["x-message-id-hash"]
     self._msg["Message-ID"] = "<bee>"
     add_message_hash(self._msg)
     Prototype.archive_message(self._mlist, self._msg)
     self.assertEqual(len(os.listdir(new_dir)), 2)
Exemplo n.º 6
0
 def test_archive_maildir_existence_does_not_raise(self):
     # Archiving a second message does not cause an EEXIST to be raised
     # when a second message is archived.
     new_dir = None
     Prototype.archive_message(self._mlist, self._msg)
     for directory in ('cur', 'new', 'tmp'):
         path = os.path.join(config.ARCHIVE_DIR, 'prototype',
                             self._mlist.fqdn_listname, directory)
         if directory == 'new':
             new_dir = path
         self.assertTrue(os.path.isdir(path))
     # There should be one message in the 'new' directory.
     self.assertEqual(len(os.listdir(new_dir)), 1)
     # Archive a second message.  If an exception occurs, let it fail the
     # test.  Afterward, two messages should be in the 'new' directory.
     del self._msg['message-id']
     del self._msg['message-id-hash']
     self._msg['Message-ID'] = '<bee>'
     add_message_hash(self._msg)
     Prototype.archive_message(self._mlist, self._msg)
     self.assertEqual(len(os.listdir(new_dir)), 2)