def test_insert_new_project_success(self): """ 1.測試 VersionInfoService 的 insert_new function 2.insert_new時, check_exists 為False 預期拿到的result 會與 release_id 一致 """ objectType = "project" request = request_project_data(full=True) version_vo = VersionInfoVo() version_vo.value_of_import(request, objectType, api_type="create") version_vo.validate(objectType, api_type="create") service = VersionInfoService(app_context) # mock insert_to_project_table insert_to_project_table_patch = patch.object( ProjectDao, 'insert_to_project_table', side_effect=self.mock_insert_to_project_table) insert_to_project_table_patch.start() # mock insert_to_release_table insert_to_release_table_patch = patch.object( ReleaseDao, 'insert_to_release_table', side_effect=self.mock_insert_to_release_table) insert_to_release_table_patch.start() result, cost_time = service.insert_new(objectType, version_vo) assert result == {"projectId": "12345", "releaseId": "23456"} insert_to_project_table_patch.stop() insert_to_release_table_patch.stop()
def new_release_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="create") if not req_data: logger.error("json body is empty") return json.jsonify(response_payload.bulid("999900001")) try: versionVo.validate(objectType, api_type="create") service = VersionInfoService(app_context) result, cost_time = service.insert_new(objectType, versionVo) return json.jsonify( response_payload.bulid("996600001", cost_time=cost_time, data=result)) 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"))
def insert_new_project_fail(self): """ 1.測試 VersionInfoService 的 insert_new function - project 2.check_exists 為True 需要報錯error 389900001 """ objectType = "project" request = request_project_data(full=True) version_vo = VersionInfoVo() version_vo.value_of_import(request, objectType, api_type="create") version_vo.validate(objectType, api_type="create") service = VersionInfoService(app_context) result, cost_time = service.insert_new(objectType, version_vo)