From cc33a6a8d565e8e756bcc5974e6ca7abc7c3c0a1 Mon Sep 17 00:00:00 2001 From: RainSun Date: Sat, 6 Feb 2021 20:04:05 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=95=B0=E6=8D=AE=E5=BA=93?= =?UTF-8?q?=E4=BB=A5=E5=8F=8A=E7=88=AC=E8=99=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/db.py | 42 ++++++++++++++++++++++ test/kong.py | 97 ++++++++++++++++++++++++++++++++++++++++++++++++++ test/lesson.py | 86 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 225 insertions(+) create mode 100644 test/db.py create mode 100644 test/kong.py create mode 100644 test/lesson.py diff --git a/test/db.py b/test/db.py new file mode 100644 index 0000000..24cd63e --- /dev/null +++ b/test/db.py @@ -0,0 +1,42 @@ +from pymongo import MongoClient +from bson import ObjectId, json_util + +# 主环境 (生产环境为production,开发环境为development) +ENV = 'development' + +def col(arg): + """ + 获取数据集 + """ + # 链接数据库 + conn = MongoClient('mongodb://192.168.2:27017/cherry') + # 判断环境 + if ENV == 'development': + arg += '_test' + return conn.cherry[arg] + +col('user_y').insert({'cid': 1, 'sid': 2}) +col('group_y').insert([ + { + 'group_id': 3, + 'avatar': 4 + }, + { + 'group_id': 5, + 'avatar': 6 + } +]) +col('link_y').insert([ + { + 'sid': 2, + 'group_id': 3 + }, + { + 'sid': 2, + 'group_id': 5 + } +]) + +print(col('user_y').find({})) +print(col('link_y').find({})) +print(col('group_y').find({})) \ No newline at end of file diff --git a/test/kong.py b/test/kong.py new file mode 100644 index 0000000..94ad5c7 --- /dev/null +++ b/test/kong.py @@ -0,0 +1,97 @@ +from urllib.request import quote, unquote +import base64 +import json + +# 西区第一教学楼 +WESTID = { + # 西区第一教学楼 + 'teaching_building_1': 'f74dac26-c58a-4eae-bc46-ff2055b2de19', + # 西区第二教学楼 + 'teaching_building_2': '201a429b-df6d-489e-9a1d-de7c85f0081e', + # 西区图书馆 + 'library': '3adb80f2-7e27-4058-a60c-fbb32cb36587' +} +EASTID = { + # 东区第一教学楼 + 'teaching_building_1': 'd91cc53c-a9ad-4be3-becf-7f3ed62e8762', + # 东区第二教学楼 + 'teaching_building_2': 'e14b90bd-0c92-422e-b299-7009118104b9', + # 东区第三教学楼 + 'teaching_building_3': '3534f8ce-f10b-4058-a818-95a116d9bca4', + # 东区前楼 + 'front_building': '6accca4d-b092-4bdc-b2e0-0c1941782eec' +} +SOUTHID = { + # 南区研究生教学楼 + 'graduate_building': '20a207f7-65ef-4ae4-9286-2a2b5a73e1c9', + # 南区实训楼 + 'practical_training_building': 'cb5265e8-84a1-41ed-985b-3920449738aa' +} + +IDLIST = { + 'wtb1': WESTID['teaching_building_1'], + 'wtb2': WESTID['teaching_building_2'], + 'wl': WESTID['library'], + 'etb1': EASTID['teaching_building_1'], + 'etb2': EASTID['teaching_building_2'], + 'etb3': EASTID['teaching_building_3'], + 'efb': EASTID['front_building'], + 'sgb': SOUTHID['graduate_building'], + 'sptb': SOUTHID['practical_training_building'], +} + +COURSELIST = ['0102', '0304', '0506', '0708', '0910', '1112'] + +# JSON转base64 +def btoa(content): + return base64.b64encode(quote(content).encode()) + +# base64转JSON +def atob(content): + return unquote(base64.b64decode(content).decode()) + +def getParam(SJ, JSs, Addr): + try: + checkData(SJ, JSs, Addr) + except Exception as e: + print(e) + raise Exception(str(e)) + param = { + "EmptyRoomParam": { + "SJ": SJ, + "JCs": JSs + }, + "PagingParam": { + "IsPaging": 1, + "Offset": 0, + "Limit": 500, + "Conditions": { + "PropertyParams": [ + { + "Field": "BDJXLXXID", + "Value": IDLIST[Addr] + } + ] + } + } + } + return str(btoa(json.dumps(param)))[2:-1] + +# 校验数据 +def checkData(sj, jss, addr): + # 校验sj + sj_split = sj.split('-') + if len(sj_split) != 3: + raise Exception('SJ错误') + for content in sj_split: + if len(content) == 0: + raise Exception('SJ错误') + # 校验jss + if not isinstance(jss,list): + raise Exception('JSs错误') + for content in jss: + if content not in COURSELIST: + raise Exception('JSs错误') + # 校验addr + if addr not in IDLIST: + raise Exception('Addr错误') \ No newline at end of file diff --git a/test/lesson.py b/test/lesson.py new file mode 100644 index 0000000..01f94ef --- /dev/null +++ b/test/lesson.py @@ -0,0 +1,86 @@ +from urllib.request import quote, unquote +import base64 +import json + + +def btoa(content): + """ + JSON转base64 + """ + return base64.b64encode(quote(content).encode()) + + +def atob(content): + """ + base64转JSON + """ + return unquote(base64.b64decode(content).decode()) + +print(atob("JTdCJTIyS0JMWCUyMiUzQSUyMjIlMjIlMkMlMjJDWExYJTIyJTNBJTIyMCUyMiUyQyUyMlhOWFElMjIlM0ElMjIyMDIwMiUyMiUyQyUyMkNYSUQlMjIlM0ElMjJkZDcwOWU3Ny0zNGY4LTQzZjctOGVmYS0wODM4ZmQxMzg0MzAlMjIlMkMlMjJDWFpDJTIyJTNBJTIyMCUyMiUyQyUyMkpYQkxYJTIyJTNBJTIyJTIyJTdE")) + +""" +param = { + "pagingParam": { + "IsPaging": false, + "Offset": 0, + "Limit": 50, + "Orders": { + "PropertyParams": [ + { + "Field": "ClassInfo.ProfessionInfoYear.NF", + "IsDesc": true + }, + { + "Field": "ClassInfo.ProfessionInfoYear.Department.DWBH", + "IsDesc": false + }, + { + "Field": "ClassInfo.ProfessionInfoYear.XNZYBH", + "IsDesc": false + }, + { + "Field": "ClassInfo.BJBH", + "IsDesc": false + }, + { + "Field": "XH", + "IsDesc": false + } + ] + }, + "Searchs": { + "PropertyParams": [ + + ] + }, + "Conditions": { + "PropertyParams": [ + { + "Field": "ClassInfo.ProfessionInfoYear.NF", + "Value": "2019", + "Operation": 3, + "Logic": 0 + }, + { + "Field": "ClassInfo.ProfessionInfoYear.Department.BDDWXXID", + "Value": "3c438133-0ede-443f-8fb7-1a7a58c7e104", + "Operation": 3, + "Logic": 0 + }, + { + "Field": "ClassInfo.ProfessionInfoYear.BDZYXXNDID", + "Value": "d70fd0d5-7521-4a31-a068-70f484daa8ef", + "Operation": 3, + "Logic": 0 + }, + { + "Field": "ClassInfo.BDBJXXID", + "Value": "33eb5cf7-1688-44e6-bd09-fc08a2b3e8a5", + "Operation": 3, + "Logic": 0 + } + ] + } + } +} +""" \ No newline at end of file