+class ODLArgParserTesting(ODLTesting):
+
+ """The class testing ODLParser."""
+ # pylint: disable=missing-docstring
+
+ def setUp(self):
+ self.parser = odl.ODLParser()
+ super(ODLArgParserTesting, self).setUp()
+
+ def test_default(self):
+ self.assertEqual(self.parser.parse_args(), self.defaultargs)
+
+ def test_basic(self):
+ self.defaultargs['neutronip'] = self._neutron_ip
+ self.defaultargs['odlip'] = self._sdn_controller_ip
+ self.assertEqual(
+ self.parser.parse_args(
+ ["--neutronip={}".format(self._neutron_ip),
+ "--odlip={}".format(self._sdn_controller_ip)]),
+ self.defaultargs)
+
+ @mock.patch('sys.stderr', new_callable=StringIO.StringIO)
+ def test_fail(self, mock_method):
+ self.defaultargs['foo'] = 'bar'
+ with self.assertRaises(SystemExit):
+ self.parser.parse_args(["--foo=bar"])
+ self.assertTrue(mock_method.getvalue().startswith("usage:"))
+
+ def _test_arg(self, arg, value):
+ self.defaultargs[arg] = value
+ self.assertEqual(
+ self.parser.parse_args(["--{}={}".format(arg, value)]),
+ self.defaultargs)
+
+ def test_odlusername(self):
+ self._test_arg('odlusername', 'foo')
+
+ def test_odlpassword(self):
+ self._test_arg('odlpassword', 'foo')
+
+ def test_osauthurl(self):
+ self._test_arg('osauthurl', 'http://127.0.0.4:5000/v2')
+
+ def test_neutronip(self):
+ self._test_arg('neutronip', '127.0.0.4')
+
+ def test_osusername(self):
+ self._test_arg('osusername', 'foo')
+
+ def test_ostenantname(self):
+ self._test_arg('ostenantname', 'foo')
+
+ def test_ospassword(self):
+ self._test_arg('ospassword', 'foo')
+
+ def test_odlip(self):
+ self._test_arg('odlip', '127.0.0.4')
+
+ def test_odlwebport(self):
+ self._test_arg('odlwebport', '80')
+
+ def test_odlrestconfport(self):
+ self._test_arg('odlrestconfport', '80')
+
+ def test_pushtodb(self):
+ self.defaultargs['pushtodb'] = True
+ self.assertEqual(self.parser.parse_args(["--{}".format('pushtodb')]),
+ self.defaultargs)
+
+ def test_multiple_args(self):
+ self.defaultargs['neutronip'] = self._neutron_ip
+ self.defaultargs['odlip'] = self._sdn_controller_ip
+ self.assertEqual(
+ self.parser.parse_args(
+ ["--neutronip={}".format(self._neutron_ip),
+ "--odlip={}".format(self._sdn_controller_ip)]),
+ self.defaultargs)
+
+