Best Python code snippet using lemoncheesecake
urlConf.py
Source:urlConf.py
1# coding=utf-82import random3import TickerConfig4import time5urls = {6 "auth": { # ç»å½æ¥å£7 "req_url": "/passport/web/auth/uamtk",8 "req_type": "post",9 "Referer": "https://kyfw.12306.cn/otn/resources/login.html",10 "Host": "kyfw.12306.cn",11 "Content-Type": 1,12 "re_try": 10,13 "re_time": 1,14 "s_time": 0.1,15 "is_logger": True,16 "is_json": True,17 "is_cdn": True,18 },19 "uamtk-static": { # ç»å½æ¥å£20 "req_url": "/passport/web/auth/uamtk-static",21 "req_type": "get",22 "Referer": "https://kyfw.12306.cn/otn/resources/login.html",23 "Host": "kyfw.12306.cn",24 "Content-Type": 1,25 "re_try": 10,26 "re_time": 3,27 "s_time": 0.1,28 "is_logger": True,29 "is_json": True,30 "is_cdn": True,31 },32 "login": { # ç»å½æ¥å£33 "req_url": "/passport/web/login",34 "req_type": "post",35 "Referer": "https://kyfw.12306.cn/otn/resources/login.html",36 "Host": "kyfw.12306.cn",37 "Content-Type": 1,38 "re_try": 10,39 "re_time": 1,40 "s_time": 0.5,41 "is_logger": True,42 "is_cdn": True,43 "is_json": True,44 },45 "left_ticket_init": { # ç»å½æ¥å£46 "req_url": "/otn/leftTicket/init",47 "req_type": "post",48 "Referer": "https://kyfw.12306.cn/otn/resources/login.html",49 "Host": "kyfw.12306.cn",50 "Content-Type": 1,51 "re_try": 10,52 "re_time": 1,53 "s_time": 0.1,54 "is_logger": False,55 "is_cdn": True,56 "is_json": False,57 },58 "getCodeImg": { # ç»å½éªè¯ç 59 "req_url": "/passport/captcha/captcha-image?login_site=E&module=login&rand=sjrand&{0}",60 "req_type": "get",61 "Referer": "https://kyfw.12306.cn/otn/resources/login.html",62 "Host": "kyfw.12306.cn",63 "Content-Type": 1,64 "re_try": 10,65 "re_time": 1,66 "s_time": 0.1,67 "is_logger": False,68 "is_json": False,69 "is_cdn": True,70 "not_decode": True,71 },72 "getCodeImg1": { # ç»å½éªè¯ç 73 "req_url": "/passport/captcha/captcha-image64?login_site=E&module=login&rand=sjrand&{0}&callback=jQuery19108016482864806321_1554298927290&_=1554298927293",74 "req_type": "get",75 "Referer": "https://kyfw.12306.cn/otn/resources/login.html",76 "Host": "kyfw.12306.cn",77 "Content-Type": 1,78 "re_try": 10,79 "re_time": 1,80 "s_time": 0.1,81 "is_logger": True,82 "is_cdn": True,83 "is_json": False,84 },85 "codeCheck": { # éªè¯ç æ ¡éª86 "req_url": "/passport/captcha/captcha-check",87 "req_type": "post",88 "Referer": "https://kyfw.12306.cn/otn/resources/login.html",89 "Host": "kyfw.12306.cn",90 "Content-Type": 1,91 "re_try": 10,92 "re_time": 1,93 "s_time": 0.1,94 "is_logger": True,95 "is_cdn": True,96 "is_json": False,97 },98 "codeCheck1": { # éªè¯ç æ ¡éª99 "req_url": "/passport/captcha/captcha-check?callback=jQuery19108016482864806321_1554298927290&answer={0}&rand=sjrand&login_site=E&_={1}",100 "req_type": "get",101 "Referer": "https://kyfw.12306.cn/otn/resources/login.html",102 "Host": "kyfw.12306.cn",103 "Content-Type": 1,104 "re_try": 10,105 "re_time": 1,106 "s_time": 0.1,107 "is_cdn": True,108 "is_logger": True,109 "is_json": False,110 },111 "loginInit": { # ç»å½é¡µé¢112 "req_url": "/otn/login/init",113 "req_type": "get",114 "Referer": "https://kyfw.12306.cn/otn/index/init",115 "Host": "kyfw.12306.cn",116 "re_try": 1,117 "re_time": 1,118 "s_time": 0.1,119 "is_logger": False,120 "is_cdn": True,121 "is_json": False,122 },123 "loginInitCdn": { # ç»å½é¡µé¢124 "req_url": "/otn/login/init",125 "req_type": "get",126 "Referer": "https://kyfw.12306.cn/otn/index/init",127 "Host": "kyfw.12306.cn",128 "re_try": 1,129 "re_time": 1,130 "s_time": 0.1,131 "is_logger": False,132 "is_test_cdn": True,133 "is_cdn": True,134 "is_json": False,135 },136 "loginInitCdn1": { # ç»å½é¡µé¢137 "req_url": "/otn/resources/login.html",138 "req_type": "get",139 "Referer": "https://kyfw.12306.cn/otn/view/index.html",140 "Host": "kyfw.12306.cn",141 "re_try": 1,142 "re_time": 1,143 "s_time": 0.1,144 "is_logger": False,145 "is_test_cdn": False,146 "is_cdn": True,147 "is_json": False,148 },149 "getDevicesId": { # è·åç¨æ·ä¿¡æ¯150 "req_url": "/otn/HttpZF/logdevice",151 "req_type": "get",152 "Referer": "https://kyfw.12306.cn/otn/passport?redirect=/otn/",153 "Host": "kyfw.12306.cn",154 "re_try": 10,155 "re_time": 1,156 "s_time": 0.01,157 "is_cdn": True,158 "is_logger": True,159 "is_json": False,160 },161 "getUserInfo": { # è·åç¨æ·ä¿¡æ¯162 "req_url": "/otn/index/initMy12306",163 "req_type": "get",164 "Referer": "https://kyfw.12306.cn/otn/passport?redirect=/otn/login/userLogin",165 "Host": "kyfw.12306.cn",166 "re_try": 10,167 "re_time": 1,168 "s_time": 0.01,169 "is_cdn": True,170 "is_logger": False,171 "is_json": False,172 },173 "userLogin": { # ç¨æ·ç»å½174 "req_url": "/otn/login/userLogin",175 "req_type": "get",176 "Referer": "https://kyfw.12306.cn/otn/passport?redirect=/otn/login/userLogin",177 "Host": "kyfw.12306.cn",178 "re_try": 10,179 "re_time": 1,180 "s_time": 0.1,181 "is_logger": True,182 "is_cdn": True,183 "is_json": True,184 },185 "uamauthclient": { # ç»å½186 "req_url": "/otn/uamauthclient",187 "req_type": "post",188 "Referer": "https://kyfw.12306.cn/otn/passport?redirect=/otn/login/userLogin",189 "Host": "kyfw.12306.cn",190 "Content-Type": 1,191 "re_try": 10,192 "re_time": 1,193 "s_time": 0.1,194 "is_cdn": True,195 "is_logger": True,196 "is_json": True,197 },198 "initdc_url": { # çæ订å页é¢199 "req_url": "/otn/confirmPassenger/initDc",200 "req_type": "get",201 "Referer": "https://kyfw.12306.cn/otn/leftTicket/init",202 "Host": "kyfw.12306.cn",203 "re_try": 10,204 "re_time": 0.1,205 "s_time": 1,206 "is_logger": False,207 "is_cdn": True,208 "is_json": False,209 },210 "GetJS": { # 订å页é¢js211 "req_url": "/otn/HttpZF/GetJS",212 "req_type": "get",213 "Referer": "https://kyfw.12306.cn/otn/confirmPassenger/initDc",214 "Host": "kyfw.12306.cn",215 "re_try": 10,216 "re_time": 0.1,217 "s_time": 0.1,218 "is_logger": False,219 "is_cdn": True,220 "is_json": False,221 },222 "odxmfwg": { # 订å页é¢js223 "req_url": "/otn/dynamicJs/odxmfwg",224 "req_type": "get",225 "Referer": "https://kyfw.12306.cn/otn/confirmPassenger/initDc",226 "Host": "kyfw.12306.cn",227 "re_try": 10,228 "re_time": 0.1,229 "s_time": 0.1,230 "is_logger": False,231 "is_cdn": True,232 "is_json": False,233 },234 "get_passengerDTOs": { # è·åä¹è½¦äºº235 "req_url": "/otn/confirmPassenger/getPassengerDTOs",236 "req_type": "post",237 "Referer": "https://kyfw.12306.cn/otn/confirmPassenger/initDc",238 "Host": "kyfw.12306.cn",239 "re_try": 10,240 "re_time": 0.1,241 "s_time": 0.1,242 "is_cdn": True,243 "is_logger": True,244 "is_json": True,245 },246 "select_url": { # æ¥è¯¢ä½ç¥¨247 "req_url": "/otn/{3}?leftTicketDTO.train_date={0}&leftTicketDTO.from_station={1}&leftTicketDTO.to_station={2}&purpose_codes=ADULT",248 "req_type": "get",249 "Referer": "https://kyfw.12306.cn/otn/leftTicket/init",250 "Host": "kyfw.12306.cn",251 "re_try": 1,252 "re_time": 0.01,253 "s_time": 0.01,254 "is_logger": False,255 "is_json": True,256 "is_cdn": True,257 },258 "check_user_url": { # æ£æ¥ç¨æ·ç»å½259 "req_url": "/otn/login/checkUser",260 "req_type": "post",261 "Referer": "https://kyfw.12306.cn/otn/leftTicket/init",262 "Host": "kyfw.12306.cn",263 "re_try": 1,264 "re_time": 1,265 "s_time": 1,266 "is_cdn": True,267 "is_logger": True,268 "is_json": True,269 },270 "submit_station_url": { # æ交订å271 "req_url": "/otn/leftTicket/submitOrderRequest",272 "req_type": "post",273 "Referer": "https://kyfw.12306.cn/otn/leftTicket/init",274 "Host": "kyfw.12306.cn",275 "re_try": 10,276 "re_time": 0.01,277 "s_time": 0.1,278 "is_cdn": True,279 "is_logger": True,280 "is_json": True,281 },282 "checkOrderInfoUrl": { # æ£æ¥è®¢åä¿¡æ¯è§è283 "req_url": "/otn/confirmPassenger/checkOrderInfo",284 "req_type": "post",285 "Referer": "https://kyfw.12306.cn/otn/confirmPassenger/initDc",286 "Host": "kyfw.12306.cn",287 "re_try": 10,288 "re_time": 0.01,289 "s_time": 0.1,290 "is_logger": True,291 "is_cdn": True,292 "is_json": True,293 },294 "getQueueCountUrl": { # å©ä½ä½ç¥¨æ°295 "req_url": "/otn/confirmPassenger/getQueueCount",296 "req_type": "post",297 "Referer": "https://kyfw.12306.cn/otn/confirmPassenger/initDc",298 "Host": "kyfw.12306.cn",299 "re_try": 10,300 "re_time": 0.01,301 "s_time": 0.1,302 "is_logger": True,303 "is_cdn": True,304 "is_json": True,305 },306 "checkQueueOrderUrl": { # 订åéåæé307 "req_url": "/otn/confirmPassenger/confirmSingleForQueue",308 "req_type": "post",309 "Referer": "https://kyfw.12306.cn/otn/confirmPassenger/initDc",310 "Host": "kyfw.12306.cn",311 "re_try": 10,312 "re_time": 0.01,313 "s_time": 0.1,314 "is_logger": True,315 "is_cdn": True,316 "is_json": True,317 },318 "checkRandCodeAnsyn": { # ææ¶æ²¡ç¨å°319 "req_url": "/otn/passcodeNew/checkRandCodeAnsyn",320 "req_type": "post",321 "Referer": "https://kyfw.12306.cn/otn/confirmPassenger/initDc",322 "Host": "kyfw.12306.cn",323 "re_try": 10,324 "re_time": 0.01,325 "s_time": 0.1,326 "is_cdn": True,327 "is_logger": True,328 "is_json": True,329 },330 "codeImgByOrder": { # 订å页é¢éªè¯ç 331 "req_url": "/otn/passcodeNew/getPassCodeNew?module=passenger&rand=randp&{}",332 "req_type": "post",333 "Referer": "https://kyfw.12306.cn/otn/confirmPassenger/initDc",334 "Host": "kyfw.12306.cn",335 "re_try": 10,336 "re_time": 0.01,337 "s_time": 0.1,338 "is_logger": False,339 "is_cdn": True,340 "is_json": False,341 },342 "queryOrderWaitTimeUrl": { # 订åçå¾
页é¢343 "req_url": "/otn/confirmPassenger/queryOrderWaitTime?random={0}&tourFlag=dc&_json_att=",344 "req_type": "get",345 "Referer": "https://kyfw.12306.cn/otn/confirmPassenger/initDc",346 "Host": "kyfw.12306.cn",347 "re_try": 10,348 "re_time": 0.01,349 "s_time": 0.1,350 "is_logger": True,351 "is_cdn": True,352 "is_json": True,353 },354 "queryMyOrderNoCompleteUrl": { # 订åæ¥è¯¢é¡µé¢355 "req_url": "/otn/queryOrder/queryMyOrderNoComplete",356 "req_type": "post",357 "Referer": "https://kyfw.12306.cn/otn/queryOrder/initNoComplete",358 "Host": "kyfw.12306.cn",359 "re_try": 10,360 "re_time": 0.01,361 "s_time": 0.1,362 "is_logger": True,363 "is_cdn": True,364 "is_json": True,365 },366 "initNoCompleteUrl": { # è·å订åå表367 "req_url": "/otn/queryOrder/initNoComplete",368 "req_type": "post",369 "Referer": "https://kyfw.12306.cn/otn/queryOrder/initNoComplete",370 "Host": "kyfw.12306.cn",371 "re_try": 10,372 "re_time": 0.01,373 "s_time": 0.1,374 "is_logger": False,375 "is_cdn": True,376 "is_json": False,377 },378 "cancelNoCompleteMyOrder": { # åæ¶è®¢å379 "req_url": "/otn/queryOrder/cancelNoCompleteMyOrder",380 "req_type": "post",381 "Referer": "https://kyfw.12306.cn/otn/queryOrder/initNoComplete",382 "Host": "kyfw.12306.cn",383 "re_try": 10,384 "re_time": 0.01,385 "s_time": 0.1,386 "is_cdn": True,387 "is_logger": True,388 "is_json": True,389 },390 "autoSubmitOrderRequest": { # å¿«éèªå¨æ交订å391 "req_url": "/otn/confirmPassenger/autoSubmitOrderRequest",392 "req_type": "post",393 "Referer": "https://kyfw.12306.cn/otn/leftTicket/init",394 "Host": "kyfw.12306.cn",395 "Content-Type": 1,396 "re_try": 10,397 "re_time": 0.01,398 "s_time": 0.1,399 "is_logger": True,400 "is_cdn": True,401 "is_json": True,402 },403 "getQueueCountAsync": { # å¿«éè·å订åæ°æ®404 "req_url": "/otn/confirmPassenger/getQueueCountAsync",405 "req_type": "post",406 "Referer": "https://kyfw.12306.cn/otn/leftTicket/init",407 "Host": "kyfw.12306.cn",408 "Content-Type": 1,409 "re_try": 10,410 "re_time": 0.01,411 "s_time": 0.1,412 "is_logger": True,413 "is_cdn": True,414 "is_json": True,415 },416 "confirmSingleForQueueAsys": { # å¿«é订åæé417 "req_url": "/otn/confirmPassenger/confirmSingleForQueueAsys",418 "req_type": "post",419 "Referer": "https://kyfw.12306.cn/otn/leftTicket/init",420 "Content-Type": 1,421 "Host": "kyfw.12306.cn",422 "re_try": 10,423 "re_time": 0.01,424 "s_time": 0.1,425 "is_logger": True,426 "is_cdn": True,427 "is_json": True,428 },429 "Pushbear": { # pushéç¥430 "req_url": "/sub",431 "req_type": "post",432 "Referer": "",433 "Content-Type": 1,434 "Host": "pushbear.ftqq.com",435 "re_try": 10,436 "re_time": 0.01,437 "s_time": 0.1,438 "is_logger": False,439 "is_json": True,440 },441 "ServerChan": { # Serveré
± pushéç¥442 "req_url": "/",443 "req_type": "get",444 "Referer": "",445 "Content-Type": 1,446 "Host": "sc.ftqq.com",447 "re_try": 10,448 "re_time": 0.01,449 "s_time": 0.1,450 "is_logger": True,451 "is_json": True,452 },453 "loginHtml": { # ç»å½æ¥å£2454 "req_url": "/otn/resources/login.html",455 "req_type": "get",456 "Referer": "https://kyfw.12306.cn/otn/leftTicket/init",457 "Host": "kyfw.12306.cn",458 "re_try": 10,459 "re_time": 0.3,460 "s_time": 0.1,461 "is_cdn": True,462 "is_logger": True,463 "is_json": True,464 },465 "loginConf": { # ç»å½æ¥å£2466 "req_url": "/otn/login/conf",467 "req_type": "post",468 "Referer": "https://kyfw.12306.cn/otn/leftTicket/init",469 "Host": "kyfw.12306.cn",470 "re_try": 10,471 "re_time": 0.3,472 "s_time": 0.1,473 "is_cdn": True,474 "is_logger": True,475 "is_json": True,476 },477 "loginAysnSuggest": { # ç»å½æ¥å£2478 "req_url": "/otn/login/loginAysnSuggest",479 "req_type": "post",480 "Referer": "https://kyfw.12306.cn/otn/leftTicket/init",481 "Host": "kyfw.12306.cn",482 "re_try": 10,483 "re_time": 0.3,484 "is_cdn": True,485 "s_time": 0.1,486 "is_logger": True,487 "is_json": True,488 },489 # å补订åæ¥å£490 "chechFace": { # 人è¸è¯å«491 "req_url": "/otn/afterNate/chechFace",492 "req_type": "post",493 "Referer": "https://kyfw.12306.cn/otn/leftTicket/init",494 "Host": "kyfw.12306.cn",495 "re_try": 10,496 "re_time": 0.01,497 "s_time": 0.01,498 "is_cdn": True,499 "is_logger": True,500 "is_json": True,501 },502 "getSuccessRate": { # æåä¿¡æ¯503 "req_url": "/otn/afterNate/getSuccessRate",504 "req_type": "post",505 "Referer": "https://kyfw.12306.cn/otn/leftTicket/init",506 "Host": "kyfw.12306.cn",507 "re_try": 10,508 "re_time": 0.01,509 "s_time": 0.01,510 "is_cdn": True,511 "is_logger": True,512 "is_json": True,513 },514 "SubmitOrderRequestRsp": { # æ交å补订ååå¤515 "req_url": "/otn/afterNate/submitOrderRequest",516 "req_type": "post",517 "Referer": "https://kyfw.12306.cn/otn/leftTicket/init",518 "Host": "kyfw.12306.cn",519 "re_try": 10,520 "re_time": 0.01,521 "s_time": 0.01,522 "is_cdn": True,523 "is_logger": True,524 "is_json": True,525 },526 "confirmHB": { # 设置订åä¿¡æ¯527 "req_url": "/otn/afterNate/confirmHB",528 "req_type": "post",529 "Referer": "https://kyfw.12306.cn/otn/leftTicket/init",530 "Host": "kyfw.12306.cn",531 "re_try": 10,532 "re_time": 0.01,533 "s_time": 0.01,534 "is_cdn": True,535 "is_logger": True,536 "is_json": True,537 },538 "queryQueue": { # æé539 "req_url": "/otn/afterNate/queryQueue",540 "req_type": "post",541 "Referer": "https://kyfw.12306.cn/otn/leftTicket/init",542 "Host": "kyfw.12306.cn",543 "re_try": 10,544 "re_time": 0.01,545 "s_time": 0.01,546 "is_cdn": True,547 "is_logger": True,548 "is_json": True,549 },550 "passengerInitApi": { # æé551 "req_url": "/otn/afterNate/passengerInitApi",552 "req_type": "post",553 "Referer": "https://kyfw.12306.cn/otn/leftTicket/init",554 "Host": "kyfw.12306.cn",555 "re_try": 10,556 "re_time": 0.01,557 "s_time": 0.01,558 "is_cdn": True,559 "is_logger": True,560 "is_json": True,561 },562 "autoVerifyImage": { # äºæç æ¥å£563 "req_url": TickerConfig.REQ_URL,564 "req_type": "post",565 "Referer": "",566 "Host": TickerConfig.HOST,567 "re_try": 6,568 "re_time": 10,569 "s_time": 0.001,570 "is_logger": True,571 "is_json": True,572 "httpType": TickerConfig.HTTP_TYPE573 },...
test_is_json.py
Source:test_is_json.py
...3from string_utils import is_json4class IsJsonTestCase(TestCase):5 def test_non_string_objects_are_properly_handled(self):6 # noinspection PyTypeChecker7 self.assertFalse(is_json({'a': 1}))8 # noinspection PyTypeChecker9 self.assertFalse(is_json(None))10 # noinspection PyTypeChecker11 self.assertFalse(is_json([1, 2, 3]))12 # noinspection PyTypeChecker13 self.assertFalse(is_json(500))14 # noinspection PyTypeChecker15 self.assertFalse(is_json(True))16 # noinspection PyTypeChecker17 self.assertFalse(is_json({1, 2}))18 def test_empty_string_are_invalid(self):19 self.assertFalse(is_json(''))20 self.assertFalse(is_json(' '))21 def test_json_object_can_be_empty(self):22 self.assertTrue(is_json('{}'))23 def test_json_array_can_be_empty(self):24 self.assertTrue(is_json('[]'))25 def test_external_spaces_are_ignored(self):26 self.assertTrue(is_json('{"foo":"bar"}'))27 self.assertTrue(is_json(' { "foo": "bar" } '))28 self.assertTrue(is_json('''29 {30 "foo": "bar"31 }32 '''))33 self.assertTrue(is_json('''34 [35 1, 2, 336 ]37 '''))38 def test_attributes_quotes_are_mandatory(self):39 self.assertFalse(is_json('{foo: 1}'))40 def test_quotes_should_be_double_quotes(self):41 self.assertFalse(is_json("{'foo': 1}"))42 self.assertFalse(is_json("['boo', 'bar']"))43 def test_string_values_should_be_wrapped_by_double_quotes(self):44 self.assertFalse(is_json('{"foo": hello}'))45 self.assertFalse(is_json('{"foo": \'hello\'}'))46 self.assertTrue(is_json('{"foo": "hello"}'))47 def test_boolean_should_be_lowercase(self):48 self.assertFalse(is_json('{"bool": True}'))49 self.assertFalse(is_json('{"bool": FALSE}'))50 self.assertTrue(is_json('{"bool": true}'))51 self.assertIsInstance(json.loads('{"bool": true}'), dict)52 self.assertTrue(is_json('{"bool": false}'))53 self.assertIsInstance(json.loads('{"bool": false}'), dict)54 def test_null_should_be_lowercase(self):55 self.assertFalse(is_json('{"null": NULL}'))56 self.assertFalse(is_json('{"null": Null}'))57 self.assertTrue(is_json('{"null": null}'))58 self.assertIsInstance(json.loads('{"null": null}'), dict)59 def test_int_number_can_be_any_length(self):60 self.assertTrue(is_json('{"number": 1}'))61 self.assertTrue(is_json('{"number": 99}'))62 self.assertTrue(is_json('{"number": 1000}'))63 self.assertTrue(is_json('{"number": 1234567890}'))64 def test_float_numbers_should_use_dot_as_separator(self):65 self.assertFalse(is_json('{"float": 4,5}'))66 self.assertTrue(is_json('{"float": 4.5}'))67 self.assertIsInstance(json.loads('{"float": 4.5}'), dict)68 def test_negative_numbers_should_be_start_with_minus(self):69 self.assertFalse(is_json('{"number": - 2}'))70 self.assertFalse(is_json('{"number": - 2.5}'))71 self.assertTrue(is_json('{"number": -2}'))72 self.assertTrue(is_json('{"number": -2.5}'))73 def test_array_can_be_empty(self):74 self.assertTrue(is_json('{"array": []}'))75 self.assertTrue(is_json('{"array": [ ]}'))76 def test_object_can_be_empty(self):77 self.assertTrue(is_json('{"obj": {}}'))78 self.assertTrue(is_json('{"obj": { }}'))79 def test_cannot_have_trailing_comma_in_array(self):80 self.assertFalse(is_json('{"numbers": [1,2,3,]}'))81 def test_cannot_have_multiple_comma_in_array(self):82 self.assertFalse(is_json('{"numbers": [1,2,,3]}'))83 def test_cannot_have_trailing_comma_in_object(self):84 self.assertFalse(is_json('{"numbers": {"a": 1, "b": 2,}}'))85 def test_cannot_have_multiple_comma_in_object(self):86 self.assertFalse(is_json('{"numbers": {"a": 1,, "b": 2}}'))87 def test_string_can_contain_escaped_quotes(self):88 s = '{"string": "Look: \\"escaped string here!\\""}'89 self.assertTrue(is_json(s))90 self.assertIsInstance(json.loads(s), dict)91 def test_array_is_json(self):92 self.assertTrue(is_json('[1,2,3]'))93 self.assertTrue(is_json('[]'))94 self.assertTrue(is_json('["foo", "bar"]'))95 self.assertTrue(is_json('[true]'))96 self.assertTrue(is_json('[false]'))97 self.assertTrue(is_json('[{"a": "b"}]'))98 def test_complete_json_case(self):99 string = '''100 {101 "books": [102 {103 "title": "Book title 1",104 "author": "FirstName LastName",105 "tags": ["tech", "programming", "python"],106 "available": true,107 "pageCount": 516,108 "rating": 4.5,109 "comments": [110 {111 "author": "FirstName LastName",112 "content": "Nice book!"113 }114 ]115 },116 {117 "title": "Book title 2",118 "author": "FirstName LastName",119 "tags": ["tech", "programming", "javascript"],120 "available": true,121 "rating": 4,122 "pageCount": 422,123 "comments": [124 ]125 }126 ]127 }128 '''129 self.assertTrue(is_json(string))...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!