예제 #1
0
    def test_modify_db_data_project_success(self):
        """
        1.測試 VersionInfoService 的 modify_db_data function - project
        2.測試modify成功案例

        """
        objectType = "project"
        request = request_project_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_project_table_patch = patch.object(
            ProjectDao,
            'update_to_project_table',
            side_effect=self.mock_update_to_project_table)
        update_to_project_table_patch.start()
        # # mock check_exist
        check_exist_by_id_patch = patch.object(
            ProjectDao, 'check_exist', side_effect=self.mock_check_exist)
        check_exist_by_id_patch.start()

        result, cost_time = service.modify_db_data(objectType, version_vo)
        assert result == "update12345"
예제 #2
0
def modify_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="modify")
        if not req_data:
            logger.error("json body is empty")
            return json.jsonify(response_payload.bulid("999900001"))

    try:
        versionVo.validate(objectType, api_type="modify")
        service = VersionInfoService(app_context)
        result, cost_time = service.modify_db_data(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"))
예제 #3
0
    def modify_db_data_project_fail1(self):
        """
        1.測試 VersionInfoService 的 modify_db_data function - project
        2.check_exist_by_id 為False 的情形下報錯 - 389900002

        """
        objectType = "project"
        request = request_project_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)
        result, cost_time = service.modify_db_data(objectType, version_vo)