示例#1
0
 def test_tls(self, capsys, mocker, args):
     mocker.patch("aiosmtpd.main.PROGRAM", "smtpd")
     with pytest.raises(SystemExit) as exc:
         parseargs(args)
     assert exc.value.code == 2
     assert ("--tlscert and --tlskey must be specified together"
             in capsys.readouterr().err)
示例#2
0
 def test_ssl_files_err(self, capsys, mocker, meth, certfile, keyfile,
                        expect):
     mocker.patch("aiosmtpd.main.PROGRAM", "smtpd")
     with pytest.raises(SystemExit) as exc:
         parseargs((f"--{meth}cert", certfile, f"--{meth}key", keyfile))
     assert exc.value.code == 2
     assert expect in capsys.readouterr().err
示例#3
0
 def test_handler_no_from_cli_exception(self, capsys):
     with pytest.raises(SystemExit) as excinfo:
         parseargs(
             ("-c", "aiosmtpd.tests.test_main.NullHandler", "FOO", "BAR"))
     assert excinfo.value.code == 2
     assert ("Handler class aiosmtpd.tests.test_main takes no arguments"
             in capsys.readouterr().err)
示例#4
0
 def test_bad_port_number(self):
     stderr = StringIO()
     with patch('sys.stderr', stderr):
         with self.assertRaises(SystemExit) as cm:
             parseargs(('-l', ':foo'))
         self.assertEqual(cm.exception.code, 2)
     usage_lines = stderr.getvalue().splitlines()
     self.assertEqual(usage_lines[-1][-24:], 'Invalid port number: foo')
示例#5
0
 def test_bad_port_number(self):
     stderr = StringIO()
     with patch('sys.stderr', stderr):
         with self.assertRaises(SystemExit) as cm:
             parseargs(('-l', ':foo'))
         self.assertEqual(cm.exception.code, 2)
     usage_lines = stderr.getvalue().splitlines()
     self.assertEqual(usage_lines[-1][-24:], 'Invalid port number: foo')
示例#6
0
 def test_v(self):
     stdout = StringIO()
     with ExitStack() as resources:
         resources.enter_context(patch('sys.stdout', stdout))
         resources.enter_context(patch('aiosmtpd.main.PROGRAM', 'smtpd'))
         cm = resources.enter_context(self.assertRaises(SystemExit))
         parseargs(('-v',))
         self.assertEqual(cm.exception.code, 0)
     self.assertEqual(stdout.getvalue(), 'smtpd {}\n'.format(__version__))
示例#7
0
 def test_v(self):
     stdout = StringIO()
     with ExitStack() as resources:
         resources.enter_context(patch('sys.stdout', stdout))
         resources.enter_context(patch('aiosmtpd.main.PROGRAM', 'smtpd'))
         cm = resources.enter_context(self.assertRaises(SystemExit))
         parseargs(('-v', ))
         self.assertEqual(cm.exception.code, 0)
     self.assertEqual(stdout.getvalue(), 'smtpd {}\n'.format(__version__))
示例#8
0
 def test_handler_no_from_cli_exception(self):
     stderr = StringIO()
     with patch('sys.stderr', stderr):
         with self.assertRaises(SystemExit) as cm:
             parseargs(('-c', 'aiosmtpd.tests.test_main.TestHandler2',
                        'FOO', 'BAR'))
         self.assertEqual(cm.exception.code, 2)
     usage_lines = stderr.getvalue().splitlines()
     self.assertEqual(
         usage_lines[-1][-57:],
         'Handler class aiosmtpd.tests.test_main takes no arguments')
示例#9
0
 def test_handler_no_from_cli_exception(self):
     stderr = StringIO()
     with patch('sys.stderr', stderr):
         with self.assertRaises(SystemExit) as cm:
             parseargs(
                 ('-c', 'aiosmtpd.tests.test_main.TestHandler2',
                  'FOO', 'BAR'))
         self.assertEqual(cm.exception.code, 2)
     usage_lines = stderr.getvalue().splitlines()
     self.assertEqual(
         usage_lines[-1][-57:],
         'Handler class aiosmtpd.tests.test_main takes no arguments')
示例#10
0
 def test_defaults(self):
     parser, args = parseargs(tuple())
     assert args.classargs == tuple()
     assert args.classpath == "aiosmtpd.handlers.Debugging"
     assert args.debug == 0
     assert isinstance(args.handler, Debugging)
     assert args.host == "localhost"
     assert args.listen is None
     assert args.port == 8025
     assert args.setuid is True
     assert args.size is None
     assert args.smtputf8 is False
     assert args.smtpscert is None
     assert args.smtpskey is None
     assert args.tlscert is None
     assert args.tlskey is None
     assert args.requiretls is True
示例#11
0
 def test_handler_from_cli(self):
     # Ignore the host:port positional argument.
     parser, args = parseargs(
         ('-c', 'aiosmtpd.tests.test_main.TestHandler1', '--', 'FOO'))
     self.assertIsInstance(args.handler, TestHandler1)
     self.assertEqual(args.handler.called, 'FOO')
示例#12
0
 def test_norequiretls(self, capsys, mocker):
     mocker.patch("aiosmtpd.main.PROGRAM", "smtpd")
     parser, args = parseargs(("--no-requiretls",))
     assert args.requiretls is False
示例#13
0
 def test_version(self, capsys, mocker, opt):
     mocker.patch("aiosmtpd.main.PROGRAM", "smtpd")
     with pytest.raises(SystemExit) as excinfo:
         parseargs((opt,))
     assert excinfo.value.code == 0
     assert capsys.readouterr().out == f"smtpd {__version__}\n"
示例#14
0
 def test_bad_port_number(self, capsys):
     with pytest.raises(SystemExit) as excinfo:
         parseargs(("-l", ":foo"))
     assert excinfo.value.code == 2
     assert "Invalid port number: foo" in capsys.readouterr().err
示例#15
0
 def test_host_port(self, args, exp_host, exp_port):
     parser, args_ = parseargs(args=args)
     assert args_.host == exp_host
     assert args_.port == exp_port
示例#16
0
 def test_handler_no_from_cli(self):
     # Ignore the host:port positional argument.
     parser, args = parseargs(
         ('-c', 'aiosmtpd.tests.test_main.TestHandler2'))
     self.assertIsInstance(args.handler, TestHandler2)
示例#17
0
 def test_host_no_port(self):
     parser, args = parseargs(args=('-l', 'foo'))
     self.assertEqual(args.host, 'foo')
     self.assertEqual(args.port, 8025)
示例#18
0
 def test_host_no_port(self):
     parser, args = parseargs(args=('-l', 'foo'))
     self.assertEqual(args.host, 'foo')
     self.assertEqual(args.port, 8025)
示例#19
0
 def test_default_host_port(self):
     parser, args = parseargs(args=())
     self.assertEqual(args.host, 'localhost')
     self.assertEqual(args.port, 8025)
示例#20
0
 def test_default_host_port(self):
     parser, args = parseargs(args=())
     self.assertEqual(args.host, 'localhost')
     self.assertEqual(args.port, 8025)
示例#21
0
 def test_ipv6_host_port(self):
     parser, args = parseargs(args=('-l', '::0:25'))
     self.assertEqual(args.host, '::0')
     self.assertEqual(args.port, 25)
示例#22
0
 def test_host_no_host(self):
     parser, args = parseargs(args=('-l', ':25'))
     self.assertEqual(args.host, 'localhost')
     self.assertEqual(args.port, 25)
示例#23
0
 def test_handler_no_from_cli(self):
     # Ignore the host:port positional argument.
     parser, args = parseargs(
         ('-c', 'aiosmtpd.tests.test_main.TestHandler2'))
     self.assertIsInstance(args.handler, TestHandler2)
示例#24
0
 def test_ipv6_host_port(self):
     parser, args = parseargs(args=('-l', '::0:25'))
     self.assertEqual(args.host, '::0')
     self.assertEqual(args.port, 25)
示例#25
0
 def test_listen(self):
     parser, args = parseargs(args=('--listen', 'foo:25'))
     self.assertEqual(args.host, 'foo')
     self.assertEqual(args.port, 25)
示例#26
0
 def test_listen(self):
     parser, args = parseargs(args=('--listen', 'foo:25'))
     self.assertEqual(args.host, 'foo')
     self.assertEqual(args.port, 25)
示例#27
0
 def test_handler_no_from_cli(self):
     parser, args = parseargs(("-c", "aiosmtpd.tests.test_main.NullHandler"))
     assert isinstance(args.handler, NullHandler)
示例#28
0
 def test_host_no_host(self):
     parser, args = parseargs(args=('-l', ':25'))
     self.assertEqual(args.host, 'localhost')
     self.assertEqual(args.port, 25)
示例#29
0
 def test_handler_from_cli_exception(self):
     with pytest.raises(TypeError):
         parseargs(("-c", "aiosmtpd.tests.test_main.FromCliHandler", "FOO", "BAR"))
示例#30
0
 def test_handler_from_cli(self):
     parser, args = parseargs(
         ("-c", "aiosmtpd.tests.test_main.FromCliHandler", "--", "FOO")
     )
     assert isinstance(args.handler, FromCliHandler)
     assert args.handler.called == "FOO"
示例#31
0
 def test_handler_from_cli(self):
     # Ignore the host:port positional argument.
     parser, args = parseargs(
         ('-c', 'aiosmtpd.tests.test_main.TestHandler1', '--', 'FOO'))
     self.assertIsInstance(args.handler, TestHandler1)
     self.assertEqual(args.handler.called, 'FOO')