def test_don_create_new_service_when_get(self) -> None: """Don't create new service on get""" services: Dict[int, str] = {} class _MockRequest(BaseMockRequest): @property def method(self): return "GET" service( service_id=11, service_request=_MockRequest(), services=services, success_redirect=lambda _: None, ) self.assertTrue(11 not in services.keys())
def test_create_new_service_with_name(self) -> None: """Create new posted service with name""" services: Dict[int, str] = {} class _MockRequest(BaseMockRequest): @property def method(self): return "POST" @property def form(self): return {"name": "foo"} service( service_id=3, service_request=_MockRequest(), services=services, success_redirect=lambda _: None, ) self.assertEqual("foo", services[3])
def test_create_new_service(self) -> None: """Identify new serive""" services: Dict[int, str] = {} class _MockRequest(BaseMockRequest): @property def method(self): return "POST" @property def form(self): return {"name": ""} service( service_id=11, service_request=_MockRequest(), services=services, success_redirect=lambda _: None, ) self.assertTrue(11 in services.keys())
def test_service_not_new(self) -> None: """Identify existing serive""" class _MockRequest(BaseMockRequest): @property def method(self): return "GET" data = service( service_id=42, service_request=_MockRequest(), services={42: ""}, success_redirect=lambda _: None, ) self.assertFalse(data["new"])
def test_service_id_and_anme(self) -> None: """Identify new serive""" class _MockRequest(BaseMockRequest): @property def method(self): return "GET" data = service( service_id=4, service_request=_MockRequest(), services={4: "bar"}, success_redirect=lambda _: None, ) self.assertEqual( (4, "bar"), (data.get("service_id"), data.get("service_name")), )
def test_use_success_redirect(self) -> None: """POST success triggers redirect call""" class _MockRequest(BaseMockRequest): @property def method(self): return "POST" @property def form(self): return {"name": "foo"} def _redirect(service_id): return f"was redirected to service/{service_id}" data = service( service_id=4, service_request=_MockRequest(), services={4: "bar"}, success_redirect=_redirect, ) self.assertEqual("was redirected to service/4", data)
def run(self): main.service()
def __run(self, params): self.__sem.acquire() #信号量减1 ta.g.log.debug("load config and run : " + params) main.service(params) self.__sem.release() #信号量加1 return
SMTPauth = os.environ['SMTPAUTH'] # 不可改动 except: # my_user = "" # 收件人 # my_sender = "" # 发件人 # SMTPdomain = "" # 发件人SMTP地址(SSL) # SMTPauth = "" # 发件人SMTP授权码 my_user = load_dict.get("my_user", ) my_sender = load_dict.get("my_sender", ) SMTPdomain = load_dict.get("SMTPdomain", ) SMTPauth = load_dict.get("SMTPauth", ) historyurl = encode(username) print(historyurl) run = 0 try: run = service(username, password, mobile, homemobile, gpslocation, lat, lon, datetime, reporttype, region, area, build, dorm, schoolgps, schoollat, schoollon, vaccine, nucleicacidtest) except: pass if run == 1: reportstatus = 1 # 这里是为了以后方便加入retry和其它通知方式 print("mission success") else: reportstatus = 0 print("mission faild") if noticetype == 1: if reportstatus == 1: mail(username, "成功", historyurl, my_user, my_sender, SMTPdomain, SMTPauth, datetime, reporttype)