def get_detail_info_product_fail(self): """ 1.測試 VersionInfoService 的 get_detail_info function - product 2.select_by_id 為 fail 時, 會回報錯誤 389900009 """ objectType = "product" object_id = "fail" # mock select_by_id select_by_id_patch = patch.object( ProductDao, 'select_by_id', side_effect=self.mock_select_by_id_product) select_by_id_patch.start() service = VersionInfoService(app_context) result, cost_time = service.get_detail_info(objectType, object_id) assert result["productName"] == "prodcut12345" select_by_id_patch.stop()
def test_get_detail_info_project_success(self): """ 1.測試 VersionInfoService 的 get_detail_info function - project 2.get_detail_info 時, 會正常回傳 """ objectType = "project" object_id = "object_id123" # mock select_by_id select_by_id_patch = patch.object( ProjectDao, 'select_by_id', side_effect=self.mock_select_by_id_project) select_by_id_patch.start() service = VersionInfoService(app_context) result, cost_time = service.get_detail_info(objectType, object_id) assert result["projectName"] == "project12345" select_by_id_patch.stop()
def test_archive_db_data_project_success(self): """ 1.測試 VersionInfoService 的 archive_db_data function - project 2.archive_db_data 正常回傳 """ objectType = "project" user = "******" object_id = "object_project" service = VersionInfoService(app_context) # mock update_to_product_table update_to_project_table_patch = patch.object( ProjectDao, 'update_to_project_table', side_effect=self.mock_update_to_project_table) update_to_project_table_patch.start() result, cost_time = service.archive_db_data(user, object_id, objectType) assert result == "update12345" update_to_project_table_patch.stop()
def test_modify_db_data_product_success(self): """ 1.測試 VersionInfoService 的 modify_db_data function - product 2.測試modify成功案例 """ objectType = "product" request = request_product_data(full=True) version_vo = VersionInfoVo() version_vo.value_of_import(request, objectType, api_type="modify") version_vo.validate(objectType, api_type="modify") service = VersionInfoService(app_context) # mock update_to_product_table update_to_product_table_patch = patch.object( ProductDao, 'update_to_product_table', side_effect=self.mock_update_to_product_table) update_to_product_table_patch.start() result, cost_time = service.modify_db_data(objectType, version_vo) assert result == "update12345"
def search_func(objectType): app_context = current_app.config["app_context"] response_payload = ReponsePayloadBulider(app_context.messages) if request.method == "POST": req_data = request.get_json() versionVo = VersionInfoVo() versionVo.value_of_import(req_data, objectType, api_type="search") if not req_data: logger.error("json body is empty") return json.jsonify(response_payload.bulid("999900001")) try: if req_data.get("page") is not None: page = req_data["page"] else: page = 1 if req_data.get("pageSize") is not None: page_size = req_data["pageSize"] else: page_size = 20 versionVo.validate(objectType, api_type="search") service = VersionInfoService(app_context) result, cost_time, page_object = service.search_from_db( objectType, versionVo, page, page_size) return json.jsonify( response_payload.bulid("996600001", cost_time=cost_time, data=result, paging=page_object)) except CommonRuntimeException as crex: logger.error(traceback.format_exc()) return json.jsonify((response_payload.bulid_from_exception(crex))) except AssertionError as ae: return json.jsonify((response_payload.bulid(ae.args[0]))) except: logger.error(traceback.format_exc()) return json.jsonify(response_payload.bulid("999999999"))