def add_case_suite(project_id): request_data = request.get_json() request_data["status"] = True request_data["projectId"] = ObjectId(project_id) request_data["lastUpdateTime"] = datetime.datetime.utcnow() request_data["createAt"] = datetime.datetime.utcnow() try: filtered_data = CaseSuite.filter_field(request.get_json(), use_set_default=True) CaseSuite.insert(filtered_data) return jsonify({'status': 'ok', 'data': '添加成功'}) except BaseException as e: return jsonify({'status': 'failed', 'data': '添加失败 %s' % e})
def update_case_suite(project_id, case_suite_id): try: filtered_data = CaseSuite.filter_field(request.get_json()) for key, value in filtered_data.items(): CaseSuite.update({"_id": ObjectId(case_suite_id)}, {'$set': { key: value }}) update_response = CaseSuite.update( {"_id": ObjectId(case_suite_id)}, {'$set': { 'lastUpdateTime': datetime.datetime.utcnow() }}, ) if update_response["n"] == 0: return jsonify({'status': 'failed', 'data': '未找到相应更新数据!'}) return jsonify({'status': 'ok', 'data': '更新成功'}) except BaseException as e: return jsonify({'status': 'failed', 'data': '更新失败: %s' % e})