Best Python code snippet using avocado_python
views.py
Source:views.py
...22 'Authorization': 'Bearer ' + self.eslCloudClient.token23 }24 url = self.eslCloudClient.useSceneUrl25 result = yield asyncTornadoRequest(url,method='GET',headers=self.headers)26 self.write(json_dumps(result))27class GoodsView(web.RequestHandler):28 def initialize(self, server):29 self.eslCloudClient = server.eslCloudClient30 self.ioloop = server.ioloop31 self.storeCode = server.eslCloudClient.storeCode32 #todo:æ ¹æ®æ ç¾æ¥è¯¢ç»å®åå ==>æµè¯ok33 @gen.coroutine34 def get(self,*args,**kwargs):35 #todo:å
Œ
±æ°æ®36 self.headers = {37 'content-type': 'application/json',38 'Authorization': 'Bearer ' + self.eslCloudClient.token39 }40 transaction_info = yield mysqlClient.tornadoOpenTransaction('aura')41 transactionPoint = transaction_info.get('point')42 #todo: è·ååæ°43 mac = self.get_argument('mac', '') # æ¡å½¢ç 44 if not all([mac]):45 content = {46 'ret':RET.PARAMERR,47 'msg':'æ ç¾æªç¥'48 }49 return self.write(json_dumps(content))50 data = {51 'mac':mac,52 }53 url = self.eslCloudClient.queryGoodsUrl54 result = yield asyncTornadoRequest(url, method='GET', headers=self.headers, params=data)55 status = result.get('status')56 if status == 200:57 content = {58 'goods':result,59 'ret': RET.OK,60 'msg': 'ååæ·»å æå'61 }62 elif status == 210:63 content = {64 'ret': RET.PARAMERR,65 'msg': 'æ ç¾æ²¡æç»å®åå'66 }67 else:68 content = {69 'ret': RET.PARAMERR,70 'msg': 'æªç¥é误'71 }72 self.write(json_dumps(content))73 #todo:æ°å¢ååä¿¡æ¯ ==>æµè¯ok74 @gen.coroutine75 def post(self,*args,**kwargs):76 self.headers = {77 'content-type': 'application/json',78 'Authorization': 'Bearer ' + self.eslCloudClient.token79 }80 transaction_info = yield mysqlClient.tornadoOpenTransaction('aura')81 transactionPoint = transaction_info.get('point')82 #todo:è·ååæ°83 barcode = self.get_argument('barcode','') #æ¡å½¢ç 84 qrcode = self.get_argument('qrcode','') #äºç»´ç 85 label1 = barcode86 label2 = qrcode87 label3 = self.get_argument('label3', '')88 label4 = self.get_argument('label4', '')89 label5 = self.get_argument('label5', '')90 label6 = self.get_argument('label6', '')91 label7 = self.get_argument('label7', '')92 label8 = self.get_argument('label8', '')93 label9 = self.get_argument('label9', '')94 label10 = self.get_argument('label10', '')95 label11 = self.get_argument('label11', '')96 label12 = self.get_argument('label12', '')97 label13 = self.get_argument('label13', '')98 label14 = self.get_argument('label14', '')99 label15 = self.get_argument('label15', '')100 label16 = self.get_argument('label16', '')101 label17 = self.get_argument('label17', '')102 label18 = self.get_argument('label18', '')103 photo1 = self.get_argument('photo1', '')104 photo2 = self.get_argument('photo2', '')105 photo3 = self.get_argument('photo3', '')106 photo4 = self.get_argument('photo4', '')107 photo5 = self.get_argument('photo5', '')108 if not all([barcode]):109 content = {110 'ret':RET.PARAMERR,111 'msg':'æ¡å½¢ç åæ°æªç¥'112 }113 return self.write(json_dumps(content))114 #todo:å¤ææ°æ®åºä¸æ¯å¦æbarcodeçè®°å½,is_delete=Ture115 data = {116 'fields': ['barcode'],117 'eq': {118 'barcode': barcode119 },120 }121 data['database'] = 'aura'122 msg = yield mysql_client.tornadoSelectOnly('d_shop_goods', data)123 if not isinstance(msg, dict):124 content = {125 'ret': RET.PARAMERR,126 'msg': msg127 }128 return self.write(json_dumps(content))129 if msg['ret'] != '0':130 content = {131 'ret': RET.PARAMERR,132 'msg': 'æ°æ®åºæ¥è¯¢é误'133 }134 return self.write(json_dumps(content))135 else:136 # todo:è¥ä¸åå¨,æ°å¢ååä¿¡æ¯137 if msg['lenght'] == 0:138 # todo:ä¿åè³æ°æ®åº139 data = {140 'transactionPoint': transactionPoint,141 'msg': {142 "barcode": barcode,143 'create_time': datetime.datetime.now(),144 'update_time': datetime.datetime.now(),145 'is_delete': False,146 "qrcode": qrcode,147 "label1": label1,148 "label2": label2,149 "label3": label3,150 "label4": label4,151 "label5": label5,152 "label6": label6,153 "label7": label7,154 "label8": label8,155 "label9": label9,156 "label10": label10,157 "label11": label11,158 "label12": label12,159 "label13": label13,160 "label14": label14,161 "label15": label15,162 "label16": label16,163 "label17": label17,164 "label18": label18,165 "photo1": photo1,166 "photo2": photo2,167 "photo3": photo3,168 "photo4": photo4,169 "photo5": photo5,170 },171 }172 data['database'] = 'aura'173 msg = yield mysql_client.tornadoInsertOne('d_shop_goods', data)174 if not isinstance(msg, dict):175 content = {176 'ret': RET.DBERR,177 'msg': msg178 }179 return self.write(json_dumps(content))180 if msg['ret'] != '0':181 content = {182 'ret': RET.DBERR,183 'msg': 'æ°æ®åºæå
¥é误'184 }185 return self.write(json_dumps(content))186 # todo:è¥åå¨,ä¿®æ¹ååä¿¡æ¯187 else:188 data = {189 'transactionPoint': transactionPoint,190 'msg': {191 'update_time': datetime.datetime.now(),192 'is_delete': False,193 "qrcode": qrcode,194 "label1": label1,195 "label2": label2,196 "label3": label3,197 "label4": label4,198 "label5": label5,199 "label6": label6,200 "label7": label7,201 "label8": label8,202 "label9": label9,203 "label10": label10,204 "label11": label11,205 "label12": label12,206 "label13": label13,207 "label14": label14,208 "label15": label15,209 "label16": label16,210 "label17": label17,211 "label18": label18,212 "photo1": photo1,213 "photo2": photo2,214 "photo3": photo3,215 "photo4": photo4,216 "photo5": photo5,217 },218 'eq': {219 "barcode": barcode,220 }221 }222 data['database'] = 'aura'223 msg = yield mysql_client.tornadoUpdateMany('d_shop_goods', data)224 if not isinstance(msg, dict):225 content = {226 'ret': RET.DBERR,227 'msg': msg228 }229 return self.write(json_dumps(content))230 if msg['ret'] != '0':231 content = {232 'ret': RET.DBERR,233 'msg': 'æ°æ®åºä¿®æ¹é误'234 }235 return self.write(json_dumps(content))236 #todo:åæ¥è³WSLäº237 shopGoods = {238 "goods": [239 {240 "barcode": barcode,241 "qrcode": qrcode,242 "label1": label1,243 "label2": label2,244 "label3": label3,245 "label4": label4,246 "label5": label5,247 "label6": label6,248 "label7": label7,249 "label8": label8,250 "label9": label9,251 "label10": label10,252 "label11": label11,253 "label12": label12,254 "label13": label13,255 "label14": label14,256 "label15": label15,257 "label16": label16,258 "label17": label17,259 "label18": label18,260 "photo1": photo1,261 "photo2": photo2,262 "photo3": photo3,263 "photo4": photo4,264 "photo5": photo5,265 },266 ],267 "storeUuid": self.storeCode #å¿
å¡«åæ° é¨åºç¼ç 268 }269 url = self.eslCloudClient.goodsUrl270 result = yield asyncTornadoRequest(url,method='POST',headers=self.headers,body=shopGoods)271 status = result.get('status')272 if status == 200:273 #todo:æ°æ®æ交274 yield mysql_client.asyncioCommitTransaction(transactionPoint)275 content = {276 'ret':RET.OK,277 'msg':'ååæ·»å æå'278 }279 elif status == 400:280 #todo:åæ»281 yield mysql_client.asyncioRollbackTransaction(transactionPoint)282 content = {283 'ret': RET.PARAMERR,284 'msg': '没ææ¤é¨åºç¼ç '285 }286 elif status == 401:287 # todo:åæ»288 yield mysql_client.asyncioRollbackTransaction(transactionPoint)289 content = {290 'ret': RET.PARAMERR,291 'msg': 'é¨åºç¼ç 为空'292 }293 elif status == 404:294 # todo:åæ»295 yield mysql_client.asyncioRollbackTransaction(transactionPoint)296 content = {297 'ret': RET.PARAMERR,298 'msg': '没ææé'299 }300 else:301 # todo:åæ»302 yield mysql_client.asyncioRollbackTransaction(transactionPoint)303 content = {304 'ret': RET.PARAMERR,305 'msg': 'æªç¥é误'306 }307 self.write(json_dumps(content))308 #todo:ä¿®æ¹ååä¿¡æ¯ ==>æµè¯ok309 @gen.coroutine310 def put(self,*args,**kwargs):311 self.headers = {312 'content-type': 'application/json',313 'Authorization': 'Bearer ' + self.eslCloudClient.token314 }315 transaction_info = yield mysqlClient.tornadoOpenTransaction('aura')316 transactionPoint = transaction_info.get('point')317 # todo:è·ååæ°318 barcode = self.get_argument('barcode', '') # æ¡å½¢ç 319 qrcode = self.get_argument('qrcode', '') # äºç»´ç 320 label1 = barcode321 label2 = qrcode322 label3 = self.get_argument('label3', '')323 label4 = self.get_argument('label4', '')324 label5 = self.get_argument('label5', '')325 label6 = self.get_argument('label6', '')326 label7 = self.get_argument('label7', '')327 label8 = self.get_argument('label8', '')328 label9 = self.get_argument('label9', '')329 label10 = self.get_argument('label10', '')330 label11 = self.get_argument('label11', '')331 label12 = self.get_argument('label12', '')332 label13 = self.get_argument('label13', '')333 label14 = self.get_argument('label14', '')334 label15 = self.get_argument('label15', '')335 label16 = self.get_argument('label16', '')336 label17 = self.get_argument('label17', '')337 label18 = self.get_argument('label18', '')338 photo1 = self.get_argument('photo1', '')339 photo2 = self.get_argument('photo2', '')340 photo3 = self.get_argument('photo3', '')341 photo4 = self.get_argument('photo4', '')342 photo5 = self.get_argument('photo5', '')343 #todo:å¤æååæ¯å¦åå¨344 data = {345 'fields': ['barcode'],346 'eq': {347 'barcode': barcode348 },349 }350 data['database'] = 'aura'351 msg = yield mysql_client.tornadoSelectOnly('d_shop_goods', data)352 if not isinstance(msg, dict):353 content = {354 'ret': RET.PARAMERR,355 'msg': msg356 }357 return self.write(json_dumps(content))358 if msg['ret'] != '0':359 content = {360 'ret': RET.PARAMERR,361 'msg': 'æ°æ®åºæ¥è¯¢é误'362 }363 return self.write(json_dumps(content))364 else:365 # todo:è¥ä¸åå¨,æ°å¢ååä¿¡æ¯366 if msg['lenght'] == 0:367 data = {368 'transactionPoint': transactionPoint,369 'msg': {370 "barcode": barcode,371 'create_time': datetime.datetime.now(),372 'update_time': datetime.datetime.now(),373 'is_delete': False,374 "qrcode": qrcode,375 "label1": label1,376 "label2": label2,377 "label3": label3,378 "label4": label4,379 "label5": label5,380 "label6": label6,381 "label7": label7,382 "label8": label8,383 "label9": label9,384 "label10": label10,385 "label11": label11,386 "label12": label12,387 "label13": label13,388 "label14": label14,389 "label15": label15,390 "label16": label16,391 "label17": label17,392 "label18": label18,393 "photo1": photo1,394 "photo2": photo2,395 "photo3": photo3,396 "photo4": photo4,397 "photo5": photo5,398 },399 }400 data['database'] = 'aura'401 msg = yield mysql_client.tornadoInsertOne('d_shop_goods', data)402 if not isinstance(msg, dict):403 content = {404 'ret': RET.DBERR,405 'msg': msg406 }407 return self.write(json_dumps(content))408 if msg['ret'] != '0':409 content = {410 'ret': RET.DBERR,411 'msg': 'æ°æ®åºæå
¥é误'412 }413 return self.write(json_dumps(content))414 # todo:è¥åå¨,ä¿®æ¹æ°æ®åºä¿¡æ¯415 else:416 data = {417 'transactionPoint': transactionPoint,418 'msg': {419 'update_time': datetime.datetime.now(),420 'is_delete': False,421 "qrcode": qrcode,422 "label1": label1,423 "label2": label2,424 "label3": label3,425 "label4": label4,426 "label5": label5,427 "label6": label6,428 "label7": label7,429 "label8": label8,430 "label9": label9,431 "label10": label10,432 "label11": label11,433 "label12": label12,434 "label13": label13,435 "label14": label14,436 "label15": label15,437 "label16": label16,438 "label17": label17,439 "label18": label18,440 "photo1": photo1,441 "photo2": photo2,442 "photo3": photo3,443 "photo4": photo4,444 "photo5": photo5,445 },446 'eq': {447 "barcode": barcode,448 }449 }450 data['database'] = 'aura'451 msg = yield mysql_client.tornadoUpdateMany('d_shop_goods', data)452 if not isinstance(msg, dict):453 content = {454 'ret': RET.DBERR,455 'msg': msg456 }457 return self.write(json_dumps(content))458 if msg['ret'] != '0':459 content = {460 'ret': RET.DBERR,461 'msg': 'æ°æ®åºä¿®æ¹é误'462 }463 return self.write(json_dumps(content))464 #todo:åæ¥ååä¿¡æ¯è³ESLäº465 shopGoods = {466 "goods": [467 {468 "barcode": barcode,469 "qrcode": qrcode,470 "label1": label1,471 "label2": label2,472 "label3": label3,473 "label4": label4,474 "label5": label5,475 "label6": label6,476 "label7": label7,477 "label8": label8,478 "label9": label9,479 "label10": label10,480 "label11": label11,481 "label12": label12,482 "label13": label13,483 "label14": label14,484 "label15": label15,485 "label16": label16,486 "label17": label17,487 "label18": label18,488 "photo1": photo1,489 "photo2": photo2,490 "photo3": photo3,491 "photo4": photo4,492 "photo5": photo5,493 },494 ],495 "storeUuid": self.storeCode # å¿
å¡«åæ°é¨åºç¼ç 496 }497 url = self.eslCloudClient.goodsUrl498 result = yield asyncTornadoRequest(url, method='PUT', headers=self.headers, body=shopGoods)499 status = result.get('status')500 if status == 200:501 # todo:æ°æ®æ交502 yield mysql_client.asyncioCommitTransaction(transactionPoint)503 content = {504 'ret': RET.OK,505 'msg': 'ååä¿®æ¹æå'506 }507 elif status == 400:508 # todo:åæ»509 yield mysql_client.asyncioRollbackTransaction(transactionPoint)510 content = {511 'ret': RET.PARAMERR,512 'msg': '没ææ¤é¨åºç¼ç '513 }514 elif status == 401:515 # todo:åæ»516 yield mysql_client.asyncioRollbackTransaction(transactionPoint)517 content = {518 'ret': RET.PARAMERR,519 'msg': 'é¨åºç¼ç 为空'520 }521 elif status == 404:522 # todo:åæ»523 yield mysql_client.asyncioRollbackTransaction(transactionPoint)524 content = {525 'ret': RET.PARAMERR,526 'msg': '没ææé'527 }528 else:529 # todo:åæ»530 yield mysql_client.asyncioRollbackTransaction(transactionPoint)531 content = {532 'ret': RET.PARAMERR,533 'msg': 'æªç¥é误'534 }535 # todo:å¤æååæ¯å¦ç»å®æ ç¾536 data = {537 'fields': ['mac'],538 'eq': {539 'is_delete': False,540 'barcode': barcode541 },542 }543 msg = yield mysql_client.tornadoSelectOnly('d_label_binding_goods', data)544 if not isinstance(msg, dict):545 content = {546 'ret': RET.PARAMERR,547 'msg': msg548 }549 return self.write(json_dumps(content))550 if msg['ret'] != '0':551 content = {552 'ret': RET.PARAMERR,553 'msg': 'æ°æ®åºæ¥è¯¢é误'554 }555 return self.write(json_dumps(content))556 else:557 # todo:è¥å·²ç»å®æ ç¾,æ¨éååä¿¡æ¯558 if msg['lenght'] != 0:559 shopGoods = {560 "information": {561 "barcode": barcode,562 'create_time': datetime.datetime.now(),563 'update_time': datetime.datetime.now(),564 'is_delete': False,565 "qrcode": qrcode,566 "label1": label1,567 "label2": label2,568 "label3": label3,569 "label4": label4,570 "label5": label5,571 "label6": label6,572 "label7": label7,573 "label8": label8,574 "label9": label9,575 "label10": label10,576 "label11": label11,577 "label12": label12,578 "label13": label13,579 "label14": label14,580 "label15": label15,581 "label16": label16,582 "label17": label17,583 "label18": label18,584 "photo1": photo1,585 "photo2": photo2,586 "photo3": photo3,587 "photo4": photo4,588 "photo5": photo5,589 },590 "storeUuid": self.storeCode # å¿
å¡«åæ° é¨åºç¼ç 591 }592 url = self.eslCloudClient.goodBrushUrl593 result = yield asyncTornadoRequest(url, method='POST', headers=self.headers, body=shopGoods)594 status = result.get('status')595 data = result.get('data')596 if status == 200:597 content = []598 for d in data:599 code = d.get('code')600 if code == '201':601 content_info = {602 'msg': 'ååä¿®æ¹æå,æ ç¾æ²¡æç»å®ç½å
³'603 }604 content.append(content_info)605 elif code == '202':606 content_info = {607 'msg': 'ååä¿®æ¹æå,æ ç¾æ²¡æ导å
¥'608 }609 content.append(content_info)610 elif code == '203':611 content_info = {612 'msg': 'ååä¿®æ¹æå,å·å¾å¼å¸¸'613 }614 content.append(content_info)615 else:616 content_info = {617 'msg': 'ååä¿®æ¹æå,æªç¥ä¿¡æ¯'618 }619 content.append(content_info)620 elif status == 400:621 content = {622 'ret': RET.PARAMERR,623 'msg': 'ååä¿®æ¹æå,没ææ¤é¨åºç¼ç '624 }625 elif status == 401:626 content = {627 'ret': RET.PARAMERR,628 'msg': 'ååä¿®æ¹æå,é¨åºç¼ç 为空'629 }630 elif status == 404:631 content = {632 'ret': RET.PARAMERR,633 'msg': 'ååä¿®æ¹æå,没ææé'634 }635 elif status == 405:636 content = {637 'ret': RET.PARAMERR,638 'msg': 'ååä¿®æ¹æå,æ¡å½¢ç é误'639 }640 elif status == 406:641 content = {642 'ret': RET.PARAMERR,643 'msg': 'ååä¿®æ¹æå,åå没æç»å®æ ç¾'644 }645 else:646 content = {647 'ret': RET.PARAMERR,648 'msg': 'ååä¿®æ¹æå,æªç¥é误'649 }650 self.write(json_dumps(content))651 #todo:å é¤ååä¿¡æ¯ ==>æµè¯ok652 @gen.coroutine653 def delete(self,*args,**kwargs):654 self.headers = {655 'content-type': 'application/json',656 'Authorization': 'Bearer ' + self.eslCloudClient.token657 }658 transaction_info = yield mysqlClient.tornadoOpenTransaction('aura')659 transactionPoint = transaction_info.get('point')660 #todo:è·ååæ°661 barcodes = self.get_argument('barcodes', '') # æ¡å½¢ç 662 barcode_list = barcodes.split('%')663 while '' in barcode_list:664 barcode_list.remove('')665 if not all([barcodes]):666 content = {667 'ret':RET.PARAMERR,668 'msg':'æ¡å½¢ç åæ°æªç¥'669 }670 return self.write(json_dumps(content))671 shopGoods = {672 "goods": [],673 "storeUuid": self.storeCode674 }675 for barcode in barcode_list:676 shopGoods['goods'] = [{'barcode':barcode}]677 # todo:å¤æbarcodeæ¯å¦åå¨678 data = {679 'fields': ['barcode'],680 'eq': {681 'is_delete': False,682 'barcode': barcode683 },684 }685 data['database'] = 'aura'686 msg = yield mysql_client.tornadoSelectOnly('d_shop_goods', data)687 if not isinstance(msg, dict):688 content = {689 'ret': RET.PARAMERR,690 'msg': msg691 }692 return self.write(json_dumps(content))693 if msg['ret'] != '0':694 content = {695 'ret': RET.PARAMERR,696 'msg': 'æ°æ®åºæ¥è¯¢é误'697 }698 return self.write(json_dumps(content))699 else:700 if msg['lenght'] != 0:701 #todo:æ°æ®åºå é¤åå702 data = {703 'transactionPoint': transactionPoint,704 'msg': {705 'update_time': datetime.datetime.now(),706 'is_delete': True,707 },708 'eq': {709 "barcode": barcode,710 }711 }712 data['database'] = 'aura'713 msg = yield mysql_client.tornadoUpdateMany('d_shop_goods', data)714 if not isinstance(msg, dict):715 content = {716 'ret': RET.DBERR,717 'msg': msg718 }719 return self.write(json_dumps(content))720 if msg['ret'] != '0':721 content = {722 'ret': RET.DBERR,723 'msg': 'æ°æ®åºä¿®æ¹é误'724 }725 return self.write(json_dumps(content))726 #todo:ESLäºå é¤727 url = self.eslCloudClient.goodsUrl728 result = yield asyncTornadoRequest(url, method='DELETE', headers=self.headers, body=shopGoods,allow_nonstandard_methods=True)729 status = result.get('status')730 if status == 200:731 # todo:æ°æ®æ交732 yield mysql_client.asyncioCommitTransaction(transactionPoint)733 elif status == 400:734 # todo:åæ»735 yield mysql_client.asyncioRollbackTransaction(transactionPoint)736 content = {737 'ret': RET.PARAMERR,738 'msg': '没ææ¤é¨åºç¼ç '739 }740 self.write(json_dumps(content))741 elif status == 401:742 # todo:åæ»743 yield mysql_client.asyncioRollbackTransaction(transactionPoint)744 content = {745 'ret': RET.PARAMERR,746 'msg': 'é¨åºç¼ç 为空'747 }748 self.write(json_dumps(content))749 elif status == 404:750 # todo:åæ»751 yield mysql_client.asyncioRollbackTransaction(transactionPoint)752 content = {753 'ret': RET.PARAMERR,754 'msg': '没ææé'755 }756 self.write(json_dumps(content))757 else:758 # todo:åæ»759 yield mysql_client.asyncioRollbackTransaction(transactionPoint)760 content = {761 'ret': RET.PARAMERR,762 'msg': 'æªç¥é误'763 }764 self.write(json_dumps(content))765 else:766 content = {767 'ret': RET.OK,768 'msg': 'ååå é¤æå'769 }770 self.write(json_dumps(content))771class ControlView(web.RequestHandler):772 @gen.coroutine773 def initialize(self, server):774 self.eslCloudClient = server.eslCloudClient775 self.ioloop = server.ioloop776 self.storeCode = server.eslCloudClient.storeCode777 #todo:è·å模æ¿id778 @gen.coroutine779 def get(self,*args,**kwargs):780 self.headers = {781 'content-type': 'application/json',782 'Authorization': 'Bearer ' + self.eslCloudClient.token783 }784 transaction_info = yield mysqlClient.tornadoOpenTransaction('aura')785 transactionPoint = transaction_info.get('point')786 page = self.get_argument('page','')787 size = self.get_argument('size','')788 name = self.get_argument('name','')789 if not all([page,size]):790 content = {791 'ret': RET.PARAMERR,792 'msg': 'åæ°é误'793 }794 return self.write(json_dumps(content))795 data = {796 'page': page,797 'size': size,798 'storeUuid':self.storeCode,799 'name':name800 }801 url = self.eslCloudClient.templateUrl802 result = yield asyncTornadoRequest(url, method='GET', headers=self.headers,params=data)803 self.write(json_dumps(result))804 #todo:ç»å®æ ç¾ ==>æµè¯ok805 @gen.coroutine806 def post(self,*args,**kwargs):807 #todo:å
Œ
±åæ°808 self.headers = {809 'content-type': 'application/json',810 'Authorization': 'Bearer ' + self.eslCloudClient.token811 }812 transaction_info = yield mysqlClient.tornadoOpenTransaction('aura')813 transactionPoint = transaction_info.get('point')814 #todo:è·ååæ°815 barcode = self.get_argument('barcode', '') # æ¡å½¢ç 816 template = self.get_argument('template','') # 模æ¿id817 mac = self.get_argument('mac', '') # æ ç¾mac818 if not all([barcode,template,mac]):819 content = {820 'ret': RET.PARAMERR,821 'msg': 'åæ°ä¸å
¨'822 }823 return self.write(json_dumps(content))824 #todo:æ¥è¯¢æ ç¾åååæ¯å¦ç»å®825 data = {826 'fields': ['guid'],827 'eq': {828 'barcode': barcode,829 'mac':mac830 },831 }832 data['database'] = 'aura'833 msg = yield mysql_client.tornadoSelectOnly('d_label_binding_goods', data)834 if not isinstance(msg, dict):835 content = {836 'ret': RET.PARAMERR,837 'msg': msg838 }839 return self.write(json_dumps(content))840 if msg['ret'] != '0':841 content = {842 'ret': RET.PARAMERR,843 'msg': 'æ°æ®åºæ¥è¯¢é误'844 }845 return self.write(json_dumps(content))846 else:847 guid_list = [x['guid'] for x in msg['msg']]848 # todo:è¥æ²¡æç»å®,åæ°å¢ç»å®å
³ç³»849 if msg['lenght'] == 0:850 data = {851 'transactionPoint': transactionPoint,852 'msg': {853 'guid': uuid.uuid1().urn.split(':')[2],854 'create_time': datetime.datetime.now(),855 'update_time': datetime.datetime.now(),856 'is_delete': False,857 "barcode": barcode,858 'mac':mac,859 'template':template,860 },861 }862 data['database'] = 'aura'863 msg = yield mysql_client.tornadoInsertOne('d_label_binding_goods', data)864 if not isinstance(msg, dict):865 content = {866 'ret': RET.DBERR,867 'msg': msg868 }869 return self.write(json_dumps(content))870 if msg['ret'] != '0':871 content = {872 'ret': RET.DBERR,873 'msg': 'æ°æ®åºæå
¥é误'874 }875 return self.write(json_dumps(content))876 # todo:è¥ç»å®,åä¿®æ¹ç»å®è§å(模æ¿id)877 else:878 data = {879 'transactionPoint': transactionPoint,880 'msg': {881 'update_time': datetime.datetime.now(),882 'is_delete': False,883 "barcode": barcode,884 'mac': mac,885 'template': template,886 },887 'eq': {888 "guid": guid_list,889 }890 }891 data['database'] = 'aura'892 msg = yield mysql_client.tornadoUpdateMany('d_label_binding_goods', data)893 if not isinstance(msg, dict):894 content = {895 'ret': RET.DBERR,896 'msg': msg897 }898 return self.write(json_dumps(content))899 if msg['ret'] != '0':900 content = {901 'ret': RET.DBERR,902 'msg': 'æ°æ®åºä¿®æ¹é误'903 }904 return self.write(json_dumps(content))905 data = {906 "procBindings": [907 {908 "barcode": barcode, #æ¡å½¢ç 909 "demoId": template, #模æ¿id910 "mac": mac #æ ç¾Macå°å911 },912 ],913 "storeUuid": self.storeCode # å¿
å¡«åæ° é¨åºç¼ç 914 }915 url = self.eslCloudClient.bindingUrl916 result = yield asyncTornadoRequest(url, method='POST', headers=self.headers, body=data)917 status = result.get('status')918 data = result.get('data')919 if status == 200:920 content = []921 for d in data:922 code = d.get('code')923 if code == '200':924 # todo:æ°æ®æ交925 yield mysql_client.asyncioCommitTransaction(transactionPoint)926 content_info = {927 'æ ç¾':d.get('message'),928 'msg': 'ååç»å®æå'929 }930 content.append(content_info)931 elif code == '205':932 # todo:æ°æ®æ交933 yield mysql_client.asyncioCommitTransaction(transactionPoint)934 content_info = {935 'æ ç¾':d.get('message'),936 'msg': 'ååå·²ç»å®'937 }938 content.append(content_info)939 elif code == '206':940 # todo:åæ»941 yield mysql_client.asyncioRollbackTransaction(transactionPoint)942 content_info = {943 'æ ç¾': d.get('message'),944 'msg': '没ææ¤ååä¿¡æ¯,请å
导å
¥ææ·»å '945 }946 content.append(content_info)947 elif code == '207':948 # todo:åæ»949 yield mysql_client.asyncioRollbackTransaction(transactionPoint)950 content_info = {951 'æ ç¾': d.get('message'),952 'msg': '没ææ¤æ ç¾ä¿¡æ¯ï¼è¯·å
导å
¥'953 }954 content.append(content_info)955 elif code == '208':956 content_info = {957 'æ ç¾': d.get('message'),958 'msg': 'ååç»å®æå'959 }960 content.append(content_info)961 else:962 # todo:åæ»963 yield mysql_client.asyncioRollbackTransaction(transactionPoint)964 content_info = {965 'msg': 'æªç¥ä¿¡æ¯'966 }967 content.append(content_info)968 elif status == 400:969 # todo:åæ»970 yield mysql_client.asyncioRollbackTransaction(transactionPoint)971 content = {972 'ret': RET.PARAMERR,973 'msg': '没ææ¤é¨åºç¼ç '974 }975 else:976 # todo:åæ»977 yield mysql_client.asyncioRollbackTransaction(transactionPoint)978 content = {979 'ret': RET.PARAMERR,980 'msg': 'æªç¥é误'981 }982 self.write(json_dumps(content))983 #todo:å é¤ç»å® ==>æµè¯ok984 @gen.coroutine985 def delete(self,*args,**kwargs):986 #todo:å
Œ
±åæ°987 self.headers = {988 'content-type': 'application/json',989 'Authorization': 'Bearer ' + self.eslCloudClient.token990 }991 transaction_info = yield mysqlClient.tornadoOpenTransaction('aura')992 transactionPoint = transaction_info.get('point')993 #todo:è·ååæ°994 macs = self.get_argument('macs')995 mac_list = macs.split('%')996 while '' in mac_list:997 mac_list.remove('')998 if not all([mac_list]):999 content = {1000 'ret':RET.PARAMERR,1001 'msg':'macå°åé误'1002 }1003 return self.write(json_dumps(content))1004 for mac in mac_list:1005 #todo:å¤æmacæ ç¾æ¯å¦åå¨1006 data = {1007 'fields': ['mac'],1008 'eq': {1009 'is_delete': False,1010 'mac': mac1011 },1012 }1013 data['database'] = 'aura'1014 msg = yield mysql_client.tornadoSelectOnly('d_label_device', data)1015 if not isinstance(msg, dict):1016 content = {1017 'ret': RET.PARAMERR,1018 'msg': msg1019 }1020 return self.write(json_dumps(content))1021 if msg['ret'] != '0':1022 content = {1023 'ret': RET.PARAMERR,1024 'msg': 'æ°æ®åºæ¥è¯¢é误'1025 }1026 return self.write(json_dumps(content))1027 #todo:å é¤æ ç¾ç»å®å
³ç³»1028 data = {1029 'transactionPoint': transactionPoint,1030 'msg': {1031 'update_time': datetime.datetime.now(),1032 'is_delete': True,1033 },1034 'eq': {1035 "mac": mac,1036 }1037 }1038 data['database'] = 'aura'1039 msg = yield mysql_client.tornadoUpdateMany('d_label_binding_goods', data)1040 if not isinstance(msg, dict):1041 content = {1042 'ret': RET.DBERR,1043 'msg': msg1044 }1045 return self.write(json_dumps(content))1046 if msg['ret'] != '0':1047 content = {1048 'ret': RET.DBERR,1049 'msg': 'æ°æ®åºä¿®æ¹é误'1050 }1051 return self.write(json_dumps(content))1052 data = {1053 "storeUuid": self.storeCode # å¿
å¡«åæ° é¨åºç¼ç 1054 }1055 data['macs'] = [mac]1056 url = self.eslCloudClient.removeBindingUrl1057 result = yield asyncTornadoRequest(url, method='DELETE', headers=self.headers, body=data,allow_nonstandard_methods=True)1058 status = result.get('status')1059 if status == 200:1060 # todo:æ°æ®æ交1061 yield mysql_client.asyncioCommitTransaction(transactionPoint)1062 elif status == 400:1063 # todo:åæ»1064 yield mysql_client.asyncioRollbackTransaction(transactionPoint)1065 content = {1066 'ret': RET.PARAMERR,1067 'msg': '没ææ¤é¨åºç¼ç '1068 }1069 self.write(json_dumps(content))1070 else:1071 # todo:åæ»1072 yield mysql_client.asyncioRollbackTransaction(transactionPoint)1073 content = {1074 'ret': RET.PARAMERR,1075 'msg': 'æªç¥é误'1076 }1077 self.write(json_dumps(content))1078 content = {1079 'ret': RET.OK,1080 'msg': 'æ ç¾å é¤ç»å®æå'1081 }1082 self.write(json_dumps(content))1083class BrushView(web.RequestHandler):1084 def initialize(self, server):1085 self.eslCloudClient = server.eslCloudClient1086 self.ioloop = server.ioloop1087 self.storeCode = server.eslCloudClient.storeCode1088 #todo:å个ååæ¨é1089 @gen.coroutine1090 def post(self,*args,**kwargs):1091 self.headers = {1092 'content-type': 'application/json',1093 'Authorization': 'Bearer ' + self.eslCloudClient.token1094 }1095 transaction_info = yield mysqlClient.tornadoOpenTransaction('aura')1096 transactionPoint = transaction_info.get('point')1097 barcode = self.get_argument('barcode', '') # æ¡å½¢ç 1098 if not all([barcode]):1099 content = {1100 'ret':RET.PARAMERR,1101 'msg':'æ¡å½¢ç åæ°æªç¥'1102 }1103 return self.write(json_dumps(content))1104 #todo:è·åååä¿¡æ¯1105 data = {1106 'fields': ['barcode', 'qrcode', 'label1', 'label2', 'label3', 'label4', 'label5', 'label6', 'label7',1107 'label8',1108 'label9', 'label10', 'label11', 'label12', 'label13', 'label14', 'label15', 'label16', 'label17',1109 'label18',1110 'photo1', 'photo2', 'photo3', 'photo4', 'photo5'],1111 'eq': {1112 'is_delete': False,1113 'barcode':barcode,1114 },1115 'sortInfo': [1116 {'update_time': ''},1117 ]1118 }1119 data['database'] = 'aura'1120 msg = yield mysqlClient.tornadoSelectOnly('d_shop_goods', data)1121 if not isinstance(msg, dict):1122 content = {1123 'ret': RET.DBERR,1124 'msg': msg1125 }1126 return self.write(json_dumps(content))1127 if msg['ret'] != '0':1128 content = {1129 'ret': RET.DBERR,1130 'msg': 'æ°æ®åºæ¥è¯¢é误'1131 }1132 return self.write(json_dumps(content))1133 else:1134 if msg['lenght'] == 0:1135 content = {1136 'ret': RET.DBERR,1137 'msg': 'ååä¸åå¨'1138 }1139 return self.write(json_dumps(content))1140 goods_info = msg['msg'][0]1141 #todo:æ¨éååä¿¡æ¯å°æ ç¾1142 shopGoods = {1143 "information": {1144 "barcode": goods_info['barcode'],1145 "qrcode": goods_info['qrcode'],1146 "label1": goods_info['label1'],1147 "label2": goods_info['label2'],1148 "label3": goods_info['label3'],1149 "label4": goods_info['label4'],1150 "label5": goods_info['label5'],1151 "label6": goods_info['label6'],1152 "label7": goods_info['label7'],1153 "label8": goods_info['label8'],1154 "label9": goods_info['label9'],1155 "label10": goods_info['label10'],1156 "label11": goods_info['label11'],1157 "label12": goods_info['label12'],1158 "label13": goods_info['label13'],1159 "label14": goods_info['label14'],1160 "label15": goods_info['label15'],1161 "label16": goods_info['label16'],1162 "label17": goods_info['label17'],1163 "label18": goods_info['label18'],1164 "photo1": goods_info['photo1'],1165 "photo2": goods_info['photo2'],1166 "photo3": goods_info['photo3'],1167 "photo4": goods_info['photo4'],1168 "photo5": goods_info['photo5'],1169 },1170 "storeUuid": self.storeCode #å¿
å¡«åæ° é¨åºç¼ç 1171 }1172 url = self.eslCloudClient.goodBrushUrl1173 result = yield asyncTornadoRequest(url, method='POST', headers=self.headers, body=shopGoods)1174 status = result.get('status')1175 data = result.get('data')1176 if status == 200:1177 content = []1178 for d in data:1179 code = d.get('code')1180 if code == '201':1181 content_info = {1182 'msg': 'æ ç¾æ²¡æç»å®ç½å
³'1183 }1184 content.append(content_info)1185 elif code == '202':1186 content_info = {1187 'msg': 'æ ç¾æ²¡æ导å
¥'1188 }1189 content.append(content_info)1190 elif code == '203':1191 content_info = {1192 'msg': 'å·å¾å¼å¸¸'1193 }1194 content.append(content_info)1195 else:1196 content_info = {1197 'msg': 'æªç¥ä¿¡æ¯'1198 }1199 content.append(content_info)1200 content = {1201 'ret': RET.OK,1202 'msg': 'ååæ¨éæå'1203 }1204 elif status == 400:1205 content = {1206 'ret': RET.PARAMERR,1207 'msg': '没ææ¤é¨åºç¼ç '1208 }1209 elif status == 401:1210 content = {1211 'ret': RET.PARAMERR,1212 'msg': 'é¨åºç¼ç 为空'1213 }1214 elif status == 404:1215 content = {1216 'ret': RET.PARAMERR,1217 'msg': '没ææé'1218 }1219 elif status == 405:1220 content = {1221 'ret': RET.PARAMERR,1222 'msg': 'æ¡å½¢ç é误'1223 }1224 elif status == 406:1225 content = {1226 'ret': RET.PARAMERR,1227 'msg': 'åå没æç»å®æ ç¾'1228 }1229 elif status == 201:1230 content = {1231 'ret': RET.PARAMERR,1232 'msg': 'æ ç¾æ²¡æç»å®ç½å
³'1233 }1234 elif status == 202:1235 content = {1236 'ret': RET.PARAMERR,1237 'msg': 'æ ç¾æ²¡æ导å
¥'1238 }1239 elif status == 203:1240 content = {1241 'ret': RET.PARAMERR,1242 'msg': 'å·å¾å¼å¸¸'1243 }1244 else:1245 content = {1246 'ret': RET.PARAMERR,1247 'msg': 'æªç¥é误'1248 }1249 self.write(json_dumps(content))1250 #todo:æ ç¾ç¯æ§å¶æ¥å£1251 @gen.coroutine1252 def put(self,*args,**kwargs):1253 self.headers = {1254 'content-type': 'application/json',1255 'Authorization': 'Bearer ' + self.eslCloudClient.token1256 }1257 transaction_info = yield mysqlClient.tornadoOpenTransaction('aura')1258 transactionPoint = transaction_info.get('point')1259 # storeUuid = self.get_argument('storeUuid', '') # é¨åºç¼ç 1260 mac = self.get_argument('mac', '') # æ ç¾mac1261 color = self.get_argument('color','') # ç¯çé¢è² 0 å
³é,1:èè²,2:绿è²,3:红è²1262 total = self.get_argument('total','') # æ§å¶ç¯çæ»æ¶é´,åä½s1263 period = self.get_argument('period','') #ç¯ä¸æ¬¡äº®å¤ä¹
ï¼åä½ms1264 interval = self.get_argument('interval','') #ç¯å¤ä¹
亮ä¸æ¬¡ï¼åä½ms1265 brigthness = self.get_argument('brigthness','') #ç¯ç亮度ï¼1~100,亮度太ä½ææä¸ææ¾1266 # if not all([storeUuid,mac]):1267 # content = {1268 # 'ret': RET.PARAMERR,1269 # 'msg': 'é¨åºç¼ç ææ ç¾mac为空'1270 # }1271 # return self.write(json_dumps(content))1272 try:1273 color = int(color)1274 total = int(total)1275 period = int(period)1276 interval = int(interval)1277 brigthness = int(brigthness)1278 except:1279 content = {1280 'ret': RET.PARAMERR,1281 'msg': 'æ§å¶åæ°é误'1282 }1283 return self.write(json_dumps(content))1284 data = {1285 'storeUuid':self.storeCode,1286 'mac':mac,1287 'color':color,1288 'total':total,1289 'period':period,1290 'interval':interval,1291 'brigthness':brigthness,1292 }1293 url = self.eslCloudClient.controlLedUrl1294 result = yield asyncTornadoRequest(url, method='PUT', headers=self.headers, params=data,body=data)1295 status = result.get('status')1296 if status == 200:1297 content = {1298 'ret': RET.OK,1299 'msg': 'LEDæ§å¶æåæå'1300 }1301 elif status == 400:1302 content = {1303 'ret': RET.PARAMERR,1304 'msg': '没ææ¤é¨åºç¼ç '1305 }1306 elif status == 401:1307 content = {1308 'ret': RET.PARAMERR,1309 'msg': 'æ¤macå°åé误ææ ç¾ä¸åå¨'1310 }1311 elif status == 402:1312 content = {1313 'ret': RET.PARAMERR,1314 'msg': 'æ ç¾æ²¡æç»å®ç½å
³'1315 }1316 else:1317 content = {1318 'ret': RET.PARAMERR,1319 'msg': 'æªç¥é误'1320 }1321 self.write(json_dumps(content))1322class Callback(web.RedirectHandler):1323 def initialize(self, server):1324 self.eslCloudClient = server.eslCloudClient1325 self.ioloop = server.ioloop1326 self.storeCode = server.eslCloudClient.storeCode1327 self.meeting_room_list = server.meeting_room_list1328 @gen.coroutine1329 def post(self,*args,**kwargs):1330 try:1331 result = json.loads(self.request.body)1332 except:1333 content = {1334 'ret': 1,1335 'status': 'é误'1336 }1337 self.write(json_dumps(content))1338 return1339 username = result.get('username')1340 code = result.get('code') #è¿åç 1341 commodity = result.get('commodity') #ååæ¡ç 1342 mac = result.get('mac') #æ ç¾macç 1343 operationType = result.get('operationType') #æä½1344 storeUuid = result.get('storeUuid') #é¨åºid1345 result = result.get('result') #åè°è¯´æ1346 if commodity == None or mac == None:1347 return1348 for meeting_room in self.meeting_room_list:1349 for mac_id,lableDeviceInfo in meeting_room.labelDeviceDict.items():1350 if mac == mac_id:1351 meeting_room_object = meeting_room1352 for good_id, good in meeting_room_object.goods_dict.items():1353 if commodity == good_id:1354 goodObject = good1355 if code == 301 or code == '301': # å·å¾æå1356 yield logClient.tornadoInfoLog('ä¼è®®å®¤:{},ç¨æ·:{},è¿è¡å¯¹é¨åº{},åå{},æ ç¾{},{}æä½,ç»æ为:{},ç¼ç 为{}'.format(meeting_room_object.name,username, storeUuid,commodity, mac,operationType, result,code))1357 else: # å·å¾å¤±è´¥1358 yield logClient.tornadoErrorLog('ä¼è®®å®¤:{},ç¨æ·:{},è¿è¡å¯¹é¨åº{},åå{},æ ç¾{},{}æä½,ç»æ为:{},ç¼ç 为{}'.format(meeting_room_object.name,username, storeUuid,commodity, mac,operationType, result,code))1359 yield goodObject.updateLabelInfo(meeting_room_object.name,meeting_room_object.company_db,1,1)1360 return1361class TokenChangeView(web.RedirectHandler):1362 def initialize(self,server):1363 self.eslCloudClient = server.eslCloudClient1364 @gen.coroutine1365 def post(self,*args,**kwargs):1366 result = json.loads(self.request.body)1367 token = result.get('token')1368 self.eslCloudClient.token = token1369 content = {1370 'ret':01371 }...
app.py
Source:app.py
1from flask import Flask, render_template, session, redirect, url_for, request2from apscheduler.schedulers.background import BackgroundScheduler3from extend import db4import json5from datetime import timedelta6from blueprint.users import user_dp7from blueprint.validate_code import validate_code8from mail import send_mail9import config10import datetime11from pojo import *12from redis_cache import redis_cache13from blueprint.product import product_dp14app = Flask(__name__)15app.jinja_env.add_extension('jinja2.ext.loopcontrols')16app.register_blueprint(user_dp)17app.register_blueprint(validate_code)18app.register_blueprint(product_dp)19app.config.from_object(config)20db.init_app(app)21send_mail.init_app(app)22with app.app_context():23 db.create_all()24@app.route('/')25def index():26 productList = redis_cache.get('productList')27 productList1 = redis_cache.get('productList1')28 productList2 = redis_cache.get('productList2')29 productList3 = redis_cache.get('productList3')30 category = Category.query.all()31 # çé¨äº§å32 if productList is None:33 products = Product.query.filter(Product.is_sell == 1, Product.is_pass == 2, Product.counts != 0).order_by(34 Product.click_count.desc()).slice(0, 10)35 productList = []36 for product in products:37 product = Product.product_json(product)38 productList.append(product)39 json_dumps = json.dumps(productList, ensure_ascii=False)40 print(json_dumps)41 redis_cache.set("productList", json_dumps)42 else:43 productList = productList.decode('utf8')44 productList = json.loads(productList)45 print(productList)46 # æ°äº§å47 if productList1 is None:48 products = Product.query.filter(Product.is_sell == 1, Product.is_pass == 2, Product.counts != 0).order_by(49 Product.pdate.desc()).slice(0, 10)50 productList1 = []51 for product in products:52 product = Product.product_json(product)53 productList1.append(product)54 json_dumps = json.dumps(productList1, ensure_ascii=False)55 print(json_dumps)56 redis_cache.set("productList1", json_dumps)57 else:58 productList1 = productList1.decode('utf8')59 productList1 = json.loads(productList1)60 print(productList1)61 # è½®æå¾åå62 if productList2 is None:63 products = Product.query.filter(Product.is_hot == 2, Product.is_sell == 1, Product.is_pass == 2, Product.counts != 0).order_by(64 Product.pdate.desc()).slice(0, 3)65 productList2 = []66 for product in products:67 product = Product.product_json(product)68 productList2.append(product)69 json_dumps = json.dumps(productList2, ensure_ascii=False)70 print(json_dumps)71 redis_cache.set("productList2", json_dumps)72 else:73 productList2 = productList2.decode('utf8')74 productList2 = json.loads(productList2)75 print(productList2)76 # æä½ä»·åå77 if productList3 is None:78 products = Product.query.filter(Product.is_sell == 1, Product.is_pass == 2, Product.counts != 0).order_by(79 Product.new_price.asc()).slice(0, 6)80 productList3 = []81 for product in products:82 product = Product.product_json(product)83 productList3.append(product)84 json_dumps = json.dumps(productList3, ensure_ascii=False)85 print(json_dumps)86 redis_cache.set("productList3", json_dumps)87 else:88 productList3 = productList3.decode('utf8')89 productList3 = json.loads(productList3)90 print(productList3)91 return render_template('user/index.html', hot_products=productList, new_products=productList1,92 extend_products=productList2, comment_products=productList3, categorys=category)93@app.context_processor94def my_context_processor():95 category_all = Category.query.all()96 categoryList = redis_cache.get('categoryList')97 if categoryList is None:98 categorys = Category.query.all()99 categoryList = []100 for category in categorys:101 category = Category.category_json(category)102 categoryList.append(category)103 json_dumps = json.dumps(categoryList, ensure_ascii=False)104 print(json_dumps)105 redis_cache.set("categoryList", json_dumps)106 else:107 categoryList = categoryList.decode('utf8')108 categoryList = json.loads(categoryList)109 print(categoryList)110 uid = session.get("uid")111 last_time = ""112 if uid is not None:113 user = User.query.get(uid)114 if user.shop_time is not None:115 shop_time = user.shop_time116 offset = timedelta(minutes=20)117 result_time = (shop_time + offset) - datetime.now()118 if result_time.days < 0:119 for shopCart in user.shopcarts:120 product = Product.query.get(shopCart.pid)121 product.counts = product.counts + shopCart.count122 db.session.delete(shopCart)123 db.session.commit()124 user.shop_time is None125 db.session.commit()126 last_time = ""127 else:128 m, s = divmod(result_time.seconds, 60)129 last_time = "" + str(m) + ":" + str(s)130 length = 0131 for shopCart in user.shopcarts:132 length += shopCart.count133 return {"uid": uid, "username": user.username, 'user_img': user.img_url, "categorys": categoryList,134 "category_all": category_all, "last_time": last_time, "length": length, "user": user}135 else:136 return {"categorys": categoryList, "category_all": category_all, "uid": "", "length": "0"}137def clear_redis():138 redis_cache.delete("userList")139 redis_cache.delete("productList1")140 redis_cache.delete("productList3")141@app.errorhandler(404)142def not_foundPage(error):143 return redirect(url_for('index'))144if __name__ == '__main__':...
test_vectors_plaintext_negative.py
Source:test_vectors_plaintext_negative.py
1from authlib.common.encoding import json_dumps2from didcomm.errors import MalformedMessageError3from tests.test_vectors.common import TTestVectorNegative4INVALID_MESSAGES = [5 json_dumps({}),6 json_dumps("aaa"),7 json_dumps(8 {9 "typ": "application/didcomm-plain+json",10 "type": "http://example.com/protocols/lets_do_lunch/1.0/proposal",11 "body": {},12 }13 ),14 json_dumps(15 {16 "id": "1234567890",17 "type": "http://example.com/protocols/lets_do_lunch/1.0/proposal",18 "body": {},19 }20 ),21 json_dumps(22 {23 "id": "1234567890",24 "typ": "application/didcomm-plain+json",25 "body": {},26 }27 ),28 json_dumps(29 {30 "id": "1234567890",31 "typ": "application/didcomm-plain+json",32 "type": "http://example.com/protocols/lets_do_lunch/1.0/proposal",33 }34 ),35 json_dumps(36 {37 "id": "1234567890",38 "typ": "application/didcomm-plain+json-unknown",39 "type": "http://example.com/protocols/lets_do_lunch/1.0/proposal",40 "body": {},41 }42 ),43 json_dumps(44 {45 "id": "1234567890",46 "typ": "application/didcomm-plain+json",47 "type": "http://example.com/protocols/lets_do_lunch/1.0/proposal",48 "body": {},49 "attachments": [{}],50 }51 ),52 json_dumps(53 {54 "id": "1234567890",55 "typ": "application/didcomm-plain+json",56 "type": "http://example.com/protocols/lets_do_lunch/1.0/proposal",57 "body": {},58 "attachments": [{"id": "23"}],59 }60 ),61 json_dumps(62 {63 "id": "1234567890",64 "typ": "application/didcomm-plain+json",65 "type": "http://example.com/protocols/lets_do_lunch/1.0/proposal",66 "body": {},67 "attachments": [{"id": "23", "data": {}}],68 }69 ),70 json_dumps(71 {72 "id": "1234567890",73 "typ": "application/didcomm-plain+json",74 "type": "http://example.com/protocols/lets_do_lunch/1.0/proposal",75 "body": {},76 "attachments": [{"id": "23", "data": {"links": ["231", "212"]}}],77 }78 ),79 json_dumps(80 {81 "id": "1234567890",82 "typ": "application/didcomm-plain+json",83 "type": "http://example.com/protocols/lets_do_lunch/1.0/proposal",84 "body": {},85 "attachments": "131",86 }87 ),88 json_dumps(89 {90 "id": "1234567890",91 "typ": "application/didcomm-plain+json",92 "type": "http://example.com/protocols/lets_do_lunch/1.0/proposal",93 "body": {},94 "attachments": [2131],95 }96 ),97 json_dumps(98 {99 "id": "1234567890",100 "typ": "application/didcomm-plain+json",101 "type": "http://example.com/protocols/lets_do_lunch/1.0/proposal",102 "body": {},103 "attachments": [{"id": 2}],104 }105 ),106 json_dumps(107 {108 "id": "1234567890",109 "typ": "application/didcomm-plain+json",110 "type": "http://example.com/protocols/lets_do_lunch/1.0/proposal",111 "body": {},112 "attachments": [{"id": "1", "data": None}],113 }114 ),115 json_dumps(116 {117 "id": "1234567890",118 "typ": "application/didcomm-plain+json",119 "type": "http://example.com/protocols/lets_do_lunch/1.0/proposal",120 "body": {},121 "attachments": [{"id": "1", "data": "None"}],122 }123 ),124 json_dumps(125 {126 "id": "1234567890",127 "typ": "application/didcomm-plain+json",128 "type": "http://example.com/protocols/lets_do_lunch/1.0/proposal",129 "body": {},130 "attachments": [{"id": "1", "data": "None"}],131 }132 ),133 # TODO: add more134]135INVALID_PLAINTEXT_TEST_VECTORS = [136 TTestVectorNegative(value, MalformedMessageError) for value in INVALID_MESSAGES...
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!!