def test_connection(self): config = Config(config_file_path) config.reload(config_file_path) config.set('General', 'debug', 'yes') rta_evt3_db_mysql = RTA_EVT3_DB('mysql', config_file_path) rta_evt3_db_redis = RTA_EVT3_DB('redis-basic', config_file_path) self.assertEqual(True, rta_evt3_db_mysql.dbConnector.testConnection()) self.assertEqual(True, rta_evt3_db_redis.dbConnector.testConnection())
def sendMockData(): config = Config(configFilePath) redisConn = redis.Redis(host=config.get('Redis', 'host'), port=6379, db=config.get('Redis', 'dbname'), password=config.get('Redis', 'password')) # pubsub = redisConn.pubsub() dtrInputChannel = config.get('Dtr', 'inputchannel') mockDetectionData = getMockData() print("Example of data: ", mockDetectionData[0]) # SORTING... for data in reversed(mockDetectionData): if not "dataType" in mockDetectionData: data["dataType"] = 'detection' if not "instrument_id" in mockDetectionData: data["instrument_id"] = instrument_id if not "observation_id" in mockDetectionData: data["observation_id"] = observation_id if not "analysis_session_type_id" in mockDetectionData: data["analysis_session_type_id"] = analysis_session_type_id sleep(randint(int(sleepMin), int(sleepMax))) print("Publish ", data, " on DTR channel ", dtrInputChannel) redisConn.publish(dtrInputChannel, data) redisConn.publish(dtrInputChannel, 'STOP')
def test_file_not_found_wrong_path(self): config = Config('', False) self.assertRaises(FileNotFoundError, config.parseConfigFile, '../../../Configs/akjdiajwnd')
def test_wrong_attribute(self): config = Config(config_file_path) self.assertEqual(False, config.get('General', 'Paperino'))
def test_wrong_section(self): config = Config(config_file_path) self.assertEqual(False, config.get('Pluto', 'Paperino'))
def test_priority_to_env_var(self): environ['RTALIBCONFIGFILE'] = config_file_path config = Config('../../../Configs/wrongconfigfile') self.assertEqual(True, bool(config.get()))
def test_singleton(self): config = Config(config_file_path) config.set('General', 'batchsize', 666) config = Config(config_file_path) self.assertEqual(666, config.get('General', 'batchsize')) config.reload(config_file_path)
def test_file_found_with_relative_path(self): config = Config(config_file_path) self.assertEqual(True, bool(config.get()))
def test_file_found_with_environment_variable(self): environ['RTALIBCONFIGFILE'] = config_file_path config = Config() self.assertEqual(True, bool(config.get()))
def getConfig(config_file_path, debug, reload=False): config = Config(config_file_path) if reload: config.reload(config_file_path) config.set('General', 'debug', debug) return config
def test_file_not_found_wrong_env_var_path(self): environ[ 'RTALIBCONFIGFILE'] = '../wrong/path/Configs/rtalibconfig_testing' config = Config('', False) self.assertRaises(FileNotFoundError, config.parseConfigFile, '')
def test_bool_false_cast(self): config = Config(config_file_path) config.set('General', 'debug', 'alksjdlkasjd') self.assertEqual( True, isinstance(config.get('General', 'debug', 'bool'), bool)) self.assertEqual(False, config.get('General', 'debug', 'bool'))
def test_no_path_no_env_var_provided(self): if 'RTALIBCONFIGFILE' in environ: del environ['RTALIBCONFIGFILE'] config = Config('', False) self.assertRaises(Exception, config.parseConfigFile, '')
def test_bool_true_cast(self): config = Config(config_file_path) config.set('General', 'debug', 'yes') self.assertEqual( True, isinstance(config.get('General', 'debug', 'bool'), bool)) self.assertEqual(True, config.get('General', 'debug', 'bool'))
def test_float_cast(self): config = Config(config_file_path) config.set('General', 'mjdref', 666.666) self.assertEqual( True, isinstance(config.get('General', 'mjdref', 'float'), float)) self.assertEqual(666.666, config.get('General', 'mjdref', 'float'))
def test_set_and_get_value(self): config = Config(config_file_path) config.set('General', 'batchsize', 666) self.assertEqual(666, config.get('General', 'batchsize'))
def test_get_section(self): config = Config(config_file_path) self.assertEqual(5, len(config.get('MySql')))
def test_wrong_section_no_attribute(self): config = Config(config_file_path) self.assertEqual(False, config.get('Pluto'))