def test_specific_default(self): """ Checks the default values of the specific options in the parser. """ _cmd_line = [] _args = configuration_parser(_cmd_line) self.assertEqual(self._default.mqtt_remote_host, _args.mqtt_remote_host) self.assertEqual(self._default.mqtt_remote_port, _args.mqtt_remote_port) # self.assertEqual(self._default.mqtt_remote_tls, # _args.mqtt_remote_tls) self.assertEqual(self._default.mqtt_remote_cafile, _args.mqtt_remote_cafile) self.assertEqual(self._default.mqtt_remote_certfile, _args.mqtt_remote_certfile) self.assertEqual(self._default.mqtt_remote_keyfile, _args.mqtt_remote_keyfile) self.assertEqual(self._default.mqtt_remote_user, _args.mqtt_remote_user) self.assertEqual(self._default.mqtt_remote_pass, _args.mqtt_remote_pass) self.assertEqual(self._default.mqtt_remote_secret, _args.mqtt_remote_secret)
def test_general_override_options(self): """ Tests if the options in the GENERAL section are overridden by the same options in the specific section. """ _config_specific_override_file = '/tmp/override_config.ini' _f = open(_config_specific_override_file, "w") _f.write("[GENERAL]\n") _f.write("mqtt_local_host = {}\n".format(self._test.mqtt_local_host)) _f.write("mqtt_local_port = {}\n".format(self._test.mqtt_local_port)) _f.write("logging_level = {}\n".format(self._test.logging_level)) _f.write("[{:s}]\n".format(APPLICATION_NAME)) _f.write("mqtt_local_host = {}\n".format( self._override.mqtt_local_host)) _f.write("mqtt_local_port = {}\n".format( self._override.mqtt_local_port)) _f.write("logging_level = {}\n".format(self._override.logging_level)) _f.close() _cmd_line = ['-c', _config_specific_override_file] _args = configuration_parser(_cmd_line) self.assertEqual(self._override.mqtt_local_host, _args.mqtt_local_host) self.assertEqual(self._override.mqtt_local_port, _args.mqtt_local_port) self.assertEqual(self._override.logging_level, _args.logging_level) os.remove(_config_specific_override_file)
def test_command_line_long_partial_override(self): """" Tests if the command line options override the settings in the configuration file (long options). """ for _opt, _par in COMMANDLINE_PARAMETERS.items(): _cmd_line = ['--config-file', str(self._config_file)] _cmd_line.extend( [_par['cmdline'], str(getattr(self._test_options, _opt))]) _args = configuration_parser(_cmd_line) self.assertEqual(getattr(_args, _opt), getattr(self._test_options, _opt)) if _opt != 'mqtt_remote_tls': self.assertNotEqual(getattr(_args, _opt), getattr(self._test_configuration, _opt)) for _cfg, _val in COMMANDLINE_PARAMETERS.items(): if _cfg == _opt: continue self.assertEqual(getattr(_args, _cfg), getattr(self._test_configuration, _cfg))
def test_general_default(self): """ Checks the defaults of the GENERAL section in the parser. """ _cmd_line = [] _args = configuration_parser(_cmd_line) self.assertEqual(self._default.mqtt_local_host, _args.mqtt_local_host) self.assertEqual(self._default.mqtt_local_port, _args.mqtt_local_port) self.assertEqual(self._default.logging_level, _args.logging_level)
def test_general_arguments(self): """ Checks the presence of the GENERAL section in the parser. """ _cmd_line = [] _args = configuration_parser(_cmd_line) self.assertIn('mqtt_local_host', _args) self.assertIn('mqtt_local_port', _args) self.assertIn('logging_level', _args)
def test_specific_arguments(self): """ Checks the presence of the specific options in the parser. """ _cmd_line = [] _args = configuration_parser(_cmd_line) self.assertIn('mqtt_remote_host', _args) self.assertIn('mqtt_remote_port', _args) self.assertIn('mqtt_remote_tls', _args) self.assertIn('mqtt_remote_cafile', _args) self.assertIn('mqtt_remote_certfile', _args) self.assertIn('mqtt_remote_keyfile', _args) self.assertIn('mqtt_remote_user', _args) self.assertIn('mqtt_remote_pass', _args) self.assertIn('mqtt_remote_secret', _args) self.assertIn('edge_id', _args)
def test_general_options(self): """ Tests the parsing of the options in the GENERAL section. """ _cmd_line = ['-c', self._config_file] _args = configuration_parser(_cmd_line) self.assertEqual(self._test.mqtt_local_host, _args.mqtt_local_host) self.assertEqual(self._test.mqtt_local_port, _args.mqtt_local_port) self.assertEqual(self._test.logging_level, _args.logging_level) self.assertNotEqual(_args.mqtt_local_host, self._default.mqtt_local_host) self.assertNotEqual(_args.mqtt_local_port, self._default.mqtt_local_port) self.assertNotEqual(_args.logging_level, self._default.logging_level)
def test_specific_options(self): """ Tests the parsing of the options in the specific section. """ _cmd_line = ['-c', self._config_file] _args = configuration_parser(_cmd_line) self.assertEqual(self._test.mqtt_remote_host, _args.mqtt_remote_host) self.assertEqual(self._test.mqtt_remote_port, _args.mqtt_remote_port) # self.assertEqual(self._test.mqtt_remote_tls, # _args.mqtt_remote_tls) self.assertEqual(self._test.mqtt_remote_cafile, _args.mqtt_remote_cafile) self.assertEqual(self._test.mqtt_remote_certfile, _args.mqtt_remote_certfile) self.assertEqual(self._test.mqtt_remote_keyfile, _args.mqtt_remote_keyfile) self.assertEqual(self._test.mqtt_remote_user, _args.mqtt_remote_user) self.assertEqual(self._test.mqtt_remote_pass, _args.mqtt_remote_pass) self.assertEqual(self._test.mqtt_remote_secret, _args.mqtt_remote_secret)
def test_command_line_long_override(self): """" Tests if the command line options override the settings in the configuration file (long options). """ _cmd_line = [] _cmd_line.extend(['--config-file', str(self._config_file)]) _cmd_line.extend( ['--local-broker', str(self._test_options.mqtt_local_host)]) _cmd_line.extend( ['--local-port', str(self._test_options.mqtt_local_port)]) _cmd_line.extend( ['--logging-level', str(self._test_options.logging_level)]) _cmd_line.extend( ['--remote-broker', str(self._test_options.mqtt_remote_host)]) _cmd_line.extend( ['--remote-port', str(self._test_options.mqtt_remote_port)]) _cmd_line.extend( ['--remote-tls', str(self._test_options.mqtt_remote_tls)]) _cmd_line.extend( ['--remote-cafile', str(self._test_options.mqtt_remote_cafile)]) _cmd_line.extend([ '--remote-certfile', str(self._test_options.mqtt_remote_certfile) ]) _cmd_line.extend( ['--remote-keyfile', str(self._test_options.mqtt_remote_keyfile)]) _cmd_line.extend( ['--remote-user', str(self._test_options.mqtt_remote_user)]) _cmd_line.extend( ['--remote-pass', str(self._test_options.mqtt_remote_pass)]) _cmd_line.extend( ['--remote-secret', str(self._test_options.mqtt_remote_secret)]) _args = configuration_parser(_cmd_line) self.assertEqual(self._test_options.mqtt_local_host, _args.mqtt_local_host) self.assertEqual(self._test_options.mqtt_local_port, _args.mqtt_local_port) self.assertEqual(self._test_options.logging_level, _args.logging_level) self.assertEqual(self._test_options.mqtt_remote_host, _args.mqtt_remote_host) self.assertEqual(self._test_options.mqtt_remote_port, _args.mqtt_remote_port) self.assertEqual(self._test_options.mqtt_remote_tls, _args.mqtt_remote_tls) self.assertEqual(self._test_options.mqtt_remote_cafile, _args.mqtt_remote_cafile) self.assertEqual(self._test_options.mqtt_remote_certfile, _args.mqtt_remote_certfile) self.assertEqual(self._test_options.mqtt_remote_keyfile, _args.mqtt_remote_keyfile) self.assertEqual(self._test_options.mqtt_remote_user, _args.mqtt_remote_user) self.assertEqual(self._test_options.mqtt_remote_pass, _args.mqtt_remote_pass) self.assertEqual(self._test_options.mqtt_remote_secret, _args.mqtt_remote_secret)