Exemplo n.º 1
0
 def test_transaction_abort_after_failing_subcommand(self):
     with transaction():
         mlist = create_list('*****@*****.**')
         mlist.volume = 5
         mlist.next_digest_number = 3
         mlist.digest_last_sent_at = now() - timedelta(days=60)
     testargs = [
         'mailman', 'digests', '-b', '-l', '*****@*****.**', '--send'
     ]
     output = StringIO()
     with ExitStack() as resources:
         enter = resources.enter_context
         enter(patch('sys.argv', testargs))
         enter(patch('sys.stdout', output))
         # Force an exception in the subcommand.
         enter(
             patch('mailman.commands.cli_digests.maybe_send_digest_now',
                   side_effect=RuntimeError))
         # Everything is already initialized.
         enter(patch('mailman.bin.mailman.initialize'))
         with self.assertRaises(RuntimeError):
             main()
     # Clear the current transaction to force a database reload.
     config.db.abort()
     # The volume and number haven't changed.
     self.assertEqual(mlist.volume, 5)
     self.assertEqual(mlist.next_digest_number, 3)
Exemplo n.º 2
0
 def test_transaction_abort_after_failing_subcommand(self):
     with transaction():
         mlist = create_list('*****@*****.**')
         mlist.volume = 5
         mlist.next_digest_number = 3
         mlist.digest_last_sent_at = now() - timedelta(days=60)
     testargs = ['mailman', 'digests', '-b', '-l', '*****@*****.**',
                 '--send']
     output = StringIO()
     with ExitStack() as resources:
         enter = resources.enter_context
         enter(patch('sys.argv', testargs))
         enter(patch('sys.stdout', output))
         # Force an exception in the subcommand.
         enter(patch('mailman.commands.cli_digests.maybe_send_digest_now',
                     side_effect=RuntimeError))
         # Everything is already initialized.
         enter(patch('mailman.bin.mailman.initialize'))
         with self.assertRaises(RuntimeError):
             main()
     # Clear the current transaction to force a database reload.
     config.db.abort()
     # The volume and number haven't changed.
     self.assertEqual(mlist.volume, 5)
     self.assertEqual(mlist.next_digest_number, 3)
Exemplo n.º 3
0
 def test_mailman_command_without_subcommand_prints_help(self):
     # Issue #137: Running `mailman` without a subcommand raises an
     # AttributeError.
     testargs = ['mailman']
     output = StringIO()
     with patch('sys.argv', testargs), patch('sys.stdout', output):
         with self.assertRaises(SystemExit):
             main()
     self.assertIn('usage', output.getvalue())
Exemplo n.º 4
0
 def test_mailman_command_without_subcommand_prints_help(self):
     # Issue #137: Running `mailman` without a subcommand raises an
     # AttributeError.
     testargs = ['mailman']
     output = StringIO()
     with patch('sys.argv', testargs), patch('sys.stdout', output):
         with self.assertRaises(SystemExit):
             main()
     self.assertIn('usage', output.getvalue())
Exemplo n.º 5
0
 def test_transaction_commit_after_successful_subcommand(self):
     # Issue #223: Subcommands which change the database need to commit or
     # abort the transaction.
     with transaction():
         mlist = create_list('*****@*****.**')
         mlist.volume = 5
         mlist.next_digest_number = 3
         mlist.digest_last_sent_at = now() - timedelta(days=60)
     testargs = ['mailman', 'digests', '-b', '-l', '*****@*****.**']
     output = StringIO()
     with ExitStack() as resources:
         enter = resources.enter_context
         enter(patch('sys.argv', testargs))
         enter(patch('sys.stdout', output))
         # Everything is already initialized.
         enter(patch('mailman.bin.mailman.initialize'))
         main()
     # Clear the current transaction to force a database reload.
     config.db.abort()
     self.assertEqual(mlist.volume, 6)
     self.assertEqual(mlist.next_digest_number, 1)
Exemplo n.º 6
0
 def test_transaction_commit_after_successful_subcommand(self):
     # Issue #223: Subcommands which change the database need to commit or
     # abort the transaction.
     with transaction():
         mlist = create_list('*****@*****.**')
         mlist.volume = 5
         mlist.next_digest_number = 3
         mlist.digest_last_sent_at = now() - timedelta(days=60)
     testargs = ['mailman', 'digests', '-b', '-l', '*****@*****.**']
     output = StringIO()
     with ExitStack() as resources:
         enter = resources.enter_context
         enter(patch('sys.argv', testargs))
         enter(patch('sys.stdout', output))
         # Everything is already initialized.
         enter(patch('mailman.bin.mailman.initialize'))
         main()
     # Clear the current transaction to force a database reload.
     config.db.abort()
     self.assertEqual(mlist.volume, 6)
     self.assertEqual(mlist.next_digest_number, 1)