def setUpClass(cls): zabbixapi.urllib2 = test_urllib2.urllib2() ms_dict = {"serverId": None, "url": None, "type":0, "nickName": "nick", "userName": "******", "password": "******", "extendedInfo":"", "pollingIntervalSec": 10, "retryIntervalSec":10} monitoring_server_info = haplib.MonitoringServerInfo(ms_dict) cls.api = zabbixapi.ZabbixAPI(monitoring_server_info)
def test_normal_run(self): sys.argv = [sys.argv[0], "--transporter", "EzTransporter"] hap = self.StandardHapTestee() hap() hap.enable_handling_sigchld(False) expect_ms = haplib.MonitoringServerInfo( json.loads(EzTransporter.TEST_MONITORING_SERVER_RESULT)) actual_ms = hap.get_received_ms_info() self.assertEqual(str(actual_ms), str(expect_ms))
def test_create(self): key_map = {} for key in self.INFO_DICT.keys(): snake = re.sub("([A-Z])", lambda x: "_" + x.group(1).lower(), key) key_map[key] = snake ms_info = haplib.MonitoringServerInfo(self.INFO_DICT) for key, val in self.INFO_DICT.items(): actual = eval("ms_info.%s" % key_map[key]) self.assertEquals(actual, val)
def test_normal_run(self): hap = self.StandardHapTestee() sys.argv = [ sys.argv[0], "--transporter", "EzTransporter", "--transporter-module", "test.TestStandardHap" ] hap() hap.enable_handling_sigchld(False) exact_ms = haplib.MonitoringServerInfo( json.loads(EzTransporter.TEST_MONITORING_SERVER_RESULT)) result_ms = hap.get_received_ms_info() self.assertTrue(result_ms, exact_ms)
def test_set_ms_info(self): main = Hap2FluentdMainTestee() main.set_null_fluentd_manager_main() main.set_ms_info( haplib.MonitoringServerInfo({ "serverId": 51, "url": "http://example.com", "type": "Fluentd", "nickName": "Jack", "userName": "******", "password": "******", "pollingIntervalSec": 30, "retryIntervalSec": 10, "extendedInfo": "", }))
def test_private_set_ms_info(self): set_ms_info = testutils.get_priv_attr(self.poller, "__set_ms_info") test_params = { "serverId": None, "url": None, "nickName": None, "userName": None, "password": None, "pollingIntervalSec": None, "retryIntervalSec": None, "extendedInfo": None, "type": None } ms_info = haplib.MonitoringServerInfo(test_params) try: set_ms_info(ms_info) raise except hap.Signal: pass
def __assert_get_extended_info(self, type, expect): ms_info = haplib.MonitoringServerInfo(self.INFO_DICT) ext = ms_info.get_extended_info(type) self.assertEquals(ext, expect)