标签:timestamp kuaidi100 %s nbsp host client 字符串 insert 数据库
实现接口测试平台使用jsonpath进行取值来断言,效果:
访问页面:
调试功能:http://www.kuaidi100.com/query
保存功能
目录结构
common的代码:
init:
import time
import uuid
def get_timestamp(data=None):
""" 生成字符串格式的时间戳数据 20190704204826 """
if data:
return time.strftime("%Y%m%d%H%M%S", time.localtime(data)) # 把传进来的时间格式化为字符串
else:
return time.strftime("%Y%m%d%H%M%S", time.localtime(time.time()))
def get_case_id():
""" 生成case的id,时间戳+uuid的第5到8位 """
return get_timestamp() + uuid.uuid1().hex[4:8]
if __name__ == ‘__main__‘:
print(get_timestamp())
print(get_case_id())
mongo:
from pymongo import MongoClient
class Mongo(object):
""" MongoDB数据库的增删改查 """
def __init__(self, host=‘127.0.0.1‘, port=27017):
self.connect = MongoClient(host, port)
def __del__(self):
self.connect.close()
def insert(self, database, collection, documents):
""" 如果要插入的参数是一个,就执行insert_one()返回单个id,否则就执行insert_many()返回id的list """
_database = self.connect.get_database(database)
_collection = _database.get_collection(collection)
if isinstance(documents, dict):
result = _collection.insert_one(documents)
return str(result.inserted_id)
else:
result = _collection.insert_many(documents)
return [str(id) for id in result.inserted_ids]
def search(self, database, collection, filter):
""" 查找 """
projection = None
if "projection" in filter:
projection = filter.pop("projection")
_database = self.connect.get_database(database)
_collection = _database.get_collection(collection)
return _collection.find(filter, projection)
def delete(self, database, collection, filter):
""" 删除 """
_database = self.connect.get_database(database)
_collection = _database.get_collection(collection)
_collection.delete_one(filter)
def update(self, database, collection, filter, documents):
""" 更新 """
_database = self.connect.get_database(database)
_collection = _database.get_collection(collection)
_collection.update_one(filter, {‘$set‘: documents})
标签:timestamp kuaidi100 %s nbsp host client 字符串 insert 数据库
原文地址:https://www.cnblogs.com/zhongyehai/p/11100228.html