示例#1
0
    def test_VersionInfoVo_create_project(self):
        """
        1.測試versioninfovo api_type = create
        2.判斷request_project與versioninfovo要一致

        Parameters
        ----------
        version_vo : object
            包含所有 input 資訊
        """
        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")
        assert version_vo.version == request.get("version")
        assert version_vo.name == request.get("name")
        assert version_vo.user == request.get("user")
        assert version_vo.object_id == request.get("objectId")
        assert version_vo.note == request.get("note")
        assert version_vo.git_url == request.get("gitUrl")
        assert version_vo.project_type == request.get("projectType")
        assert version_vo.language_type == request.get("languageType")
        assert version_vo.service_port == request.get("servicePort")
        assert version_vo.service_url == request.get("serviceUrl")
示例#2
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"
示例#3
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()
示例#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"))
示例#5
0
    def VersionInfoVo_create_project_fail(self):
        """
        1.測試 VersionInfoService 的 api_type = create
        2.port 在chatbot的連續port號 內會報錯 389900010

        """
        objectType = "project"
        request = request_project_data(full=True, port="fail")
        version_vo = VersionInfoVo()
        version_vo.value_of_import(request, objectType, api_type="create")
        version_vo.validate(objectType, api_type="create")
示例#6
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)
示例#7
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)
示例#8
0
    def VersionInfoVo_modify_project_fail(self):
        """
        1.測試versioninfovo api_type = modify
        2.預期request_product 因為 git_url 不存在 判斷失敗

        Parameters
        ----------
        version_vo : object
            包含所有 input 資訊
        """
        objectType = "project"
        request = request_project_data(full=True, fail="service_url")
        version_vo = VersionInfoVo()
        version_vo.value_of_import(request, objectType, api_type="modify")
        version_vo.validate(objectType, api_type="modify")
示例#9
0
    def VersionInfoVo_create_project_fail_2(self):
        """
        1.測試versioninfovo api_type = create
        2.預期request_project 因少 languageType 欄位 判斷失敗

        Parameters
        ----------
        version_vo : object
            包含所有 input 資訊
        """
        objectType = "project"
        request = request_project_data(full=True, fail="languageType")
        version_vo = VersionInfoVo()
        version_vo.value_of_import(request, objectType, api_type="create")
        version_vo.validate(objectType, api_type="create")
示例#10
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)
示例#11
0
    def test_VersionInfoVo_create_product(self):
        """
        1.測試versioninfovo api_type = create
        2.判斷request_product與versioninfovo要一致

        Parameters
        ----------
        version_vo : object
            包含所有 input 資訊
        """
        objectType = "product"
        request = request_product_data()
        version_vo = VersionInfoVo()
        version_vo.value_of_import(request, objectType, api_type="create")
        version_vo.validate(objectType, api_type="create")
        assert version_vo.version == request.get("version")
        assert version_vo.name == request.get("name")
        assert version_vo.note == request.get("note")
示例#12
0
    def test_VersionInfoVo_modify_product(self):
        """
        1.測試versioninfovo api_type = modify
        2.判斷request_product與versioninfovo要一致

        Parameters
        ----------
        version_vo : object
            包含所有 input 資訊
        """
        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")
        assert version_vo.object_id == request.get("objectId")
        assert version_vo.user == request.get("user")
        assert version_vo.note == request.get("note")
示例#13
0
    def test_VersionInfoVo_search(self):
        """
        1.測試versioninfovo api_type = search
        2.判斷request與versioninfovo要一致

        Parameters
        ----------
        version_vo : object
            包含所有 input 資訊
        """
        objectType = "product"
        request = search_data()
        version_vo = VersionInfoVo()
        version_vo.value_of_import(request, objectType, api_type="search")
        version_vo.validate(objectType, api_type="search")
        assert version_vo.keyword == request.get("keyword")
        assert version_vo.name == request.get("name")
        assert version_vo.active_status == request.get("activeStatus")
        assert version_vo.language_type == request.get("languageType")
        assert version_vo.project_type == request.get("projectType")
示例#14
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"))