def test_check_deserialize(): expected = Check(response_time=100, status_code=201, url='http://google.com') got = Check.deserialize( b'{"response_time": 100, "status_code": 201, "url": "http://google.com"}' ) assert expected == got
def test_登录(self, cases): for caseName, caseInfo in cases.items(): caseName = caseName data = caseInfo["data"] check = caseInfo["check"] self.__dict__['_testMethodDoc'] = caseName # 发送请求 response = self.client.sendRequest(self.method, self.url, self.headers, data) # 接口返回文本信息 text = response.text # 把文本信息转化为字典格式 text_dict = json.loads(text) # 判断接口响应code是否为200,获取cookie if text_dict["code"] == 200: self.token_dict["cookie"] = response.headers['Set-Cookie'].split(";")[0] # 写日志 writeLog(caseName, self.url, data, check, text) # 断言 Check().check(check, text_dict)
def test_登录(self, cases): for caseName, caseInfo in cases.items(): caseName = caseName email = caseInfo["account"] passwd = caseInfo["password"] check = caseInfo["assert"] self.__dict__['_testMethodDoc'] = caseName # 拼装请求参数 loginData = {"account": email, "userPwd": passwd} # 发送请求 response = self.client.sendRequest(self.method, self.url, self.headers, loginData) # 接口返回文本信息 text = response.text # 把文本信息转化为字典格式 text_dict = json.loads(text) # 判断接口响应code是否为200,获取cookie if text_dict["code"] == 200: self.token_dict["cookie"] = response.headers['Set-Cookie'].split( ";")[0] # 写日志 writeLog(caseName, self.url, loginData, check, text_dict) # 断言 Check().check(check, text_dict)
def test_修改车型(self, cases): for caseName, caseInfo in cases.items(): caseName = caseName data = caseInfo["data"] check = caseInfo["check"] self.__dict__['_testMethodDoc'] = caseName ids = {"carModelId": self.car_model_id} # 用例中值替换为变量 data = eval(findAndReplace(str(data), ids)) # 发送请求 response = self.client.sendRequest(self.method, self.url, self.headers, data) # 接口返回文本信息 text = response.text # 把文本信息转化为字典格式 text_dict = json.loads(text) # 写日志 writeLog(caseName, self.url, data, check, text_dict) # 断言 Check().check(check, text_dict)
def _make_request(self) -> Check: """Make a request to site TODO handle timeout """ start = time.monotonic() resp = urlopen(self.url) took = round((time.monotonic() - start) * 1000) return Check( response_time=took, status_code=resp.status, url=self.url, )
def test_consumer_handle_event(): config = Config(kafka_bootstrap='localhost:9002', kafka_topic='checks', kafka_ca_path='./', kafka_key_path='./', kafka_cert_path='./', postgres_uri='postgres://*****:*****@localhost:port/db') check = Check(response_time=100, status_code=201, url='http://google.com') event = Mock() event.value = check.serialize() kafka_consumer = [event] db = Mock() cursor = Mock() db.cursor = Mock(return_value=cursor) consumer = Consumer(config, kafka_consumer, db) # type: ignore consumer.run() cursor.execute.assert_called()
def test_修改密码(self, cases): for caseName, caseInfo in cases.items(): caseName = caseName data = caseInfo["data"] check = caseInfo["check"] self.__dict__['_testMethodDoc'] = caseName # 发送请求 response = self.client.sendRequest(self.method, self.url, self.headers, data) text = response.text # 接口返回信息 # 写日志 writeLog(caseName, self.url, data, check, text) # 断言 Check().check(check, text)
def test_checker_send_event(): config = Config(site='https://google.com', interval=10, kafka_bootstrap='localhost:9002', kafka_topic='checks', kafka_ca_path='./', kafka_key_path='./', kafka_cert_path='./') producer = Mock() checker = Checker(config, producer) check = Check(response_time=100, status_code=201, url='http://google.com') with patch.object(Checker, '_make_request', return_value=check): checker.run(once=True) producer.send.assert_called_once_with( 'checks', b'{"response_time": 100, "status_code": 201, "url": "http://google.com"}' )
def test_摇树(self, cases): for caseName, caseInfo in cases.items(): caseName = caseName data = caseInfo["data"] check = caseInfo["check"] self.__dict__['_testMethodDoc'] = caseName # 发送请求 response = self.client.sendRequest(self.method, self.url, data) # 接口返回文本信息 text = response.text # 把文本信息转化为字典格式 text_dict = json.loads(text) # 写日志 writeLog(caseName, self.url, data, check, text_dict) # 断言 Check().check(check, text_dict)
def __init__(self, domain): Check.__init__(self) self.domain = domain self.module = 'check' self.source = "NSECCheck"
def send_check_event(self, event: Check): self.producer.send(self.topic, event.serialize())
def __init__(self, domain): Check.__init__(self) self.domain = domain self.module = 'check' self.source = 'SitemapCheck'
def handle_message(self, raw_msg: bytes) -> None: check = Check.deserialize(raw_msg) insert_check(self.db, check)
def __init__(self, domain): Check.__init__(self) self.domain = domain self.module = 'check' self.source = 'AXFRCheck' self.results = []
def __init__(self, domain): Check.__init__(self) self.domain = domain self.module = 'check' self.source = 'RobotsCheck'
def __init__(self, domain): Check.__init__(self) self.domain = domain self.module = 'check' self.source = 'CertInfo'
def __init__(self, domain, header): Check.__init__(self) self.domain = domain self.module = 'check' self.source = 'CSPCheck' self.csp_header = header
def test_check_serialize(): check = Check(response_time=100, status_code=201, url='http://google.com') assert check.serialize( ) == b'{"response_time": 100, "status_code": 201, "url": "http://google.com"}'