Ejemplo n.º 1
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"))
Ejemplo n.º 2
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()
Ejemplo n.º 3
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()