1
0
Fork 0
mirror of https://github.com/evilhero/mylar synced 2024-12-22 15:52:47 +00:00
mylar/lib/tests/test_cli.py
Brian Hartvigsen 69eeb9b49d Put libs/ in sys.path
Update bs4 to latest version to fix issues
Get clean modules using `pip install --upgrade --target=lib`
Move cherrypy, mako, pystun, bs4 into lib directory
2016-08-23 00:01:41 -06:00

61 lines
1.9 KiB
Python

import argparse
import unittest
import stun
from stun import cli
class TestCLI(unittest.TestCase):
"""Test the CLI API."""
@classmethod
def setUpClass(cls):
cls.source_ip = '123.45.67.89'
cls.source_port = 24816
cls.stun_port = 13579
cls.stun_host = 'stun.stub.org'
def test_cli_parser_default(self):
parser = cli.make_argument_parser()
options = parser.parse_args([])
self.assertEqual(options.source_ip, stun.DEFAULTS['source_ip'])
self.assertEqual(options.source_port, stun.DEFAULTS['source_port'])
self.assertEqual(options.stun_port, stun.DEFAULTS['stun_port'])
self.assertIsNone(options.stun_host)
def test_cli_parser_user_long_form(self):
parser = cli.make_argument_parser()
options = parser.parse_args([
'--source-port', str(self.source_port),
'--source-ip', self.source_ip,
'--stun-port', str(self.stun_port),
'--stun-host', self.stun_host,
'--debug'
])
self.assertTrue(options.debug)
self.assertEqual(options.source_ip, self.source_ip)
self.assertEqual(options.source_port, self.source_port)
self.assertEqual(options.stun_host, self.stun_host)
self.assertEqual(options.stun_port, self.stun_port)
def test_cli_parser_user_short_form(self):
parser = cli.make_argument_parser()
options = parser.parse_args([
'-p', str(self.source_port),
'-i', self.source_ip,
'-P', str(self.stun_port),
'-H', self.stun_host,
'-d'
])
self.assertTrue(options.debug)
self.assertEqual(options.source_ip, self.source_ip)
self.assertEqual(options.source_port, self.source_port)
self.assertEqual(options.stun_host, self.stun_host)
self.assertEqual(options.stun_port, self.stun_port)
if __name__ == '__main__':
unittest.main()