Example #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"
Example #2
0
    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()
Example #3
0
def get_detail():
    app_context = current_app.config["app_context"]
    response_payload = ReponsePayloadBulider(app_context.messages)

    if request.method == "POST":
        req_data = request.get_json()
        if not req_data:
            logger.error("json body is empty")
            return json.jsonify(response_payload.bulid("999900001"))

    try:
        if not req_data.get("user") or not req_data.get(
                "objectId") or not req_data.get("objectType"):
            return json.jsonify(response_payload.bulid("999900001"))
        service = VersionInfoService(app_context)
        result, cost_time = service.get_detail_info(req_data["objectType"],
                                                    req_data["objectId"])

        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"))
Example #4
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"))
Example #5
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)
Example #6
0
    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)
Example #7
0
    def test_search_from_db_project_success(self):
        """
        1.測試 VersionInfoService 的 search_from_db function - project
        2.search_from_db, 正常回傳

        """
        objectType = "project"
        page = 1
        page_size = 10
        request = request_project_data(full=True)
        version_vo = VersionInfoVo()
        version_vo.value_of_import(request, objectType, api_type="search")
        version_vo.validate(objectType, api_type="search")
        service = VersionInfoService(app_context)
        result, cost_time, page_object = service.search_from_db(
            objectType, version_vo, page, page_size)
Example #8
0
    def get_detail_info_project_fail(self):
        """
        1.測試 VersionInfoService 的 get_detail_info function - project
        2.select_by_id 為 fail 時, 會回報錯誤 389900009

        """
        objectType = "project"
        object_id = "fail"
        # 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()
Example #9
0
    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()
Example #10
0
    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()
Example #11
0
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"))