Example #1
0
    def test_new_product_release_version_success(self):
        """
        1.測試 new_release_version for product
        2.正常回傳
        """
        objectType = "product"
        request = request_data_for_new_release()
        release_vo = ReleaseVo()
        release_vo.value_of_import(request, api_type="release_insert")
        release_vo.validate(api_type="release_insert")
        service = ReleaseService(app_context)

        check_insert_to_release_table_patch = patch.object(ReleaseDao, "insert_to_release_table",
                                                           side_effect=self.mock_insert_to_release_table)
        check_insert_to_release_table_patch.start()
        check_insert_to_mapping_table_patch = patch.object(ReleaseMappingDao, "insert_to_release_mapping_table",
                                                           side_effect=self.mock_insert_to_release_mapping_table)
        check_insert_to_mapping_table_patch.start()
        product_check_exist_patch = patch.object(ProductDao, "check_exist",
                                                side_effect=self.mock_product_check_exist)
        product_check_exist_patch.start()

        service.new_release_version(objectType, release_vo)
        check_insert_to_release_table_patch.stop()
        check_insert_to_mapping_table_patch.stop()
        product_check_exist_patch.stop()
Example #2
0
    def test_latest_info_product_success(self):
        """
        1.測試拿取上一版的 dependency
        2.正常回傳
        """
        request = request_latest_info_data()
        release_vo = ReleaseVo()
        release_vo.value_of_import(request, api_type="latest_info")
        release_vo.validate(api_type="latest_info")

        get_release_info_view_patch = patch.object(
            SearchViewDao,
            'get_release_info',
            side_effect=self.mock_get_release_info_success)
        get_release_info_view_patch.start()
        get_release_info_table_patch = patch.object(
            ReleaseDao,
            'get_release_info',
            side_effect=self.mock_get_release_info_success)
        get_release_info_table_patch.start()

        service = ReleaseService(app_context)
        result, cost_time = service.latest_release_info("product", release_vo)
        assert result == None
        get_release_info_view_patch.stop()
        get_release_info_table_patch.stop()
Example #3
0
    def test_modify_success(self):
        """
        1.測試 modify
        2.正常回傳
        """
        request = request_modify_data()
        release_vo = ReleaseVo()
        release_vo.value_of_import(request, api_type="modify_release_info")
        release_vo.validate(api_type="modify_release_info")

        modify_dependency_by_release_id_patch = patch.object(
            ReleaseMappingDao,
            'modify_dependency_by_release_id',
            side_effect=self.mock_modify_dependency_by_release_id_success)
        modify_dependency_by_release_id_patch.start()
        get_status_and_dependency_by_id_patch = patch.object(
            ReleaseDao,
            'get_status_and_dependency_by_id',
            side_effect=self.mock_get_status_and_dependency_by_id)
        get_status_and_dependency_by_id_patch.start()
        update_by_parameters_patch = patch.object(
            ReleaseDao,
            'update_by_parameters',
            side_effect=self.mock_update_by_parameters_None)
        update_by_parameters_patch.start()

        service = ReleaseService(app_context)
        result, cost_time = service.modify_release(release_vo)
        assert result == "test_release_id"
        modify_dependency_by_release_id_patch.stop()
        get_status_and_dependency_by_id_patch.stop()
        update_by_parameters_patch.stop()
Example #4
0
    def test_deactivate_success(self):
        """
        1.測試 deactivate
        2.update_by_parameters 正常回傳

        """
        request = request_activate_data(running_status=0)
        release_vo = ReleaseVo()
        release_vo.value_of_import(request, api_type="activate")
        release_vo.validate(api_type="activate")

        check_parent_dependency_patch = patch.object(
            ReleaseMappingDao,
            'check_parent_dependency',
            side_effect=self.mock_check_parent_dependency_not_exist)
        check_parent_dependency_patch.start()
        update_by_parameters_patch = patch.object(
            ReleaseDao,
            'update_by_parameters',
            side_effect=self.mock_update_by_parameters_success)
        update_by_parameters_patch.start()

        service = ReleaseService(app_context)
        result, cost_time = service.activate(release_vo)
        assert result == "test_release_id"
        check_parent_dependency_patch.stop()
        update_by_parameters_patch.stop()
Example #5
0
def activate_func():
    app_context = current_app.config["app_context"]
    response_payload = ReponsePayloadBulider(app_context.messages)

    if request.method == "POST":
        req_data = request.get_json()
        releaseVo = ReleaseVo()
        releaseVo.value_of_import(req_data, api_type="activate")

        if not req_data:
            logger.error("json body is empty")
            return json.jsonify(response_payload.bulid("999900001"))

    try:
        releaseVo.validate(api_type="activate")
        service = ReleaseService(app_context)
        result, cost_time = service.activate(releaseVo)
        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 #6
0
 def product_history_release_dep_info_fail(self):
     objectType = "product"
     request = request_data_for_history_info()
     release_vo = ReleaseVo()
     release_vo.value_of_import(request, api_type="history_info")
     release_vo.validate(api_type="history_info")
     service = ReleaseService(app_context)
     service.get_release_history_info(objectType, release_vo)
Example #7
0
 def test_dependency_overview(self):
     """
     1.測試 拿取所有依賴套件的資料
     2.正常回傳
     """
     request_data_user = {"user": "******"}
     release_vo = ReleaseVo()
     release_vo.value_of_import(request_data_user, api_type="dependency_overview")
     release_vo.validate(api_type="dependency_overview")
     service = ReleaseService(app_context)
     result, cost_time = service.get_release_overview()
Example #8
0
    def verify_fail(self):
        """
        1.測試對不存在的 release_id verify
        2.回傳錯誤 389900002
        """
        request = request_verify_data()
        release_vo = ReleaseVo()
        release_vo.value_of_import(request, api_type="verify")
        release_vo.validate(api_type="verify")

        service = ReleaseService(app_context)
        result, cost_time = service.verify(release_vo)
Example #9
0
    def activate_fail(self):
        """
        1.測試對不存在的 release_id 進行 activate
        2.回傳錯誤 389900009
        """
        request = request_activate_data(running_status=1)
        release_vo = ReleaseVo()
        release_vo.value_of_import(request, api_type="activate")
        release_vo.validate(api_type="activate")

        service = ReleaseService(app_context)
        result, cost_time = service.activate(release_vo)
Example #10
0
    def deactive_not_exist_object(self):
        """
        1.測試對不存在的 release_id 進行 deactivate
        2.回傳錯誤 389900002
        """
        request = request_activate_data(running_status=0)
        release_vo = ReleaseVo()
        release_vo.value_of_import(request, api_type="activate")
        release_vo.validate(api_type="activate")

        service = ReleaseService(app_context)
        result, cost_time = service.activate(release_vo)
Example #11
0
    def test_get_specific_releases_info(self):
        """
        1.測試 拿取指定release_id的release詳細資料
        2.正常回傳
        """
        request = request_data_for_get_spec_release_detail()
        release_vo = ReleaseVo()
        release_vo.value_of_import(request, api_type="get_release_info")
        release_vo.validate(api_type="get_release_info")
        service = ReleaseService(app_context)

        check_search_by_id_list_patch = patch.object(ReleaseDao, "search_by_id_list",
                                                     side_effect=self.mock_search_by_id_list)
        check_search_by_id_list_patch.start()
        result, cost_time = service.get_specific_releases_info(release_vo)
        check_search_by_id_list_patch.stop()
Example #12
0
    def test_project_history_release_dep_info_success(self):
        """
        1.測試 拿取專案所依賴的服務或套件歷史紀錄
        2.正常回傳
        """
        objectType = "project"
        request = request_data_for_history_info()
        release_vo = ReleaseVo()
        release_vo.value_of_import(request, api_type="history_info")
        release_vo.validate(api_type="history_info")
        service = ReleaseService(app_context)

        check_history_release_dep_info_patch = patch.object(ReleaseDao, "get_data_by_object_id",
                                                            side_effect=self.mock_history_release_info_success)
        check_history_release_dep_info_patch.start()
        result, cost_time = service.get_release_history_info(objectType, release_vo)
        check_history_release_dep_info_patch.stop()
Example #13
0
    def test_latest_info_fail(self):
        """
        1.測試拿取不存在的 release_id 的上一版的 dependency 紀錄
        2.回傳錯誤 389900009
        """
        request = request_latest_info_data()
        release_vo = ReleaseVo()
        release_vo.value_of_import(request, api_type="latest_info")
        release_vo.validate(api_type="latest_info")

        get_release_info_patch = patch.object(
            SearchViewDao,
            'get_release_info',
            side_effect=self.mock_get_release_info_not_exist)
        get_release_info_patch.start()
        service = ReleaseService(app_context)
        result, cost_time = service.latest_release_info("project", release_vo)
        assert result == None
        get_release_info_patch.stop()
Example #14
0
    def test_verify_success(self):
        """
        1.測試 verify
        2.正常回傳
        """

        request = request_verify_data()
        release_vo = ReleaseVo()
        release_vo.value_of_import(request, api_type="verify")
        release_vo.validate(api_type="verify")

        update_by_parameters_patch = patch.object(
            ReleaseDao,
            'update_by_parameters',
            side_effect=self.mock_update_by_parameters_success)
        update_by_parameters_patch.start()

        service = ReleaseService(app_context)
        result, cost_time = service.verify(release_vo)
        assert result == "test_release_id"
        update_by_parameters_patch.stop()