def test_email_g01(self): """ email_g01 """ if "json" == ml_system.CFG_TYPE: shutil.copyfile(os.path.join("unittest", "email-g01.json"), os.path.join("running", "email.txt")) if "jcfg" == ml_system.CFG_TYPE: shutil.copyfile(os.path.join("unittest", "email-g01.jcfg"), os.path.join("running", "email.txt")) if "pickle" == ml_system.CFG_TYPE: return self.maxDiff = None e = ml_w_email.get(None, threading.RLock()) self.assertEqual(e, (True, { "alert": True, "from": "*****@*****.**", "to": ["*****@*****.**"], "server": "1.2.3.4", "timeout": 10 }))
def email(self, **kwargs): ''' snmp email notification setting data format from middleware (True, {'to': [], 'server': '', 'from': '', 'timeout': 0, 'alert': False}) ''' import libs.login if False == libs.login.cklogin(): raise _.HTTPRedirect('/') import ml_w_email as wem import json import libs.tools _.response.headers["Content-Type"] = "application/json" if "from" in kwargs: # for updating setting libs.tools.v(kwargs) tos = [] if type(kwargs["to"]).__name__ == "list": for v in kwargs["to"]: if len(v) > 0: tos.append(libs.tools.convert(v)) else: if len(kwargs['to']) > 0: tos.append(libs.tools.convert(kwargs['to'])) res = {'to': tos, 'server': libs.tools.convert(kwargs['server']), 'from': libs.tools.convert(kwargs['from']), 'timeout': int(kwargs['timeout']), 'alert': 'alert' in kwargs} libs.tools.v(res) return json.dumps(wem.set(user = self.getUser(), cfg = res)) else: # for information getter return json.dumps(wem.get())