def save_market_app_template(self, user, tenant, app_templates): template_version = app_templates["template_version"] is_v1 = bool(template_version == "v1") if is_v1: v2_template = template_transform_service.v1_to_v2(app_templates) else: v2_template = app_templates rainbond_app = rainbond_app_repo.get_enterpirse_app_by_key_and_version( tenant.enterprise_id, v2_template["group_key"], v2_template["group_version"]) if not rainbond_app: if common_services.is_public() and user.is_sys_admin: enterprise_id = "public" else: enterprise_id = tenant.enterprise_id rainbond_app = RainbondCenterApp( group_key=app_templates["group_key"], group_name=app_templates["group_name"], version=app_templates['group_version'], share_user=0, record_id=0, share_team="", source="market", scope="goodrain", describe=app_templates["info"], pic=app_templates["pic"], app_template="", enterprise_id=enterprise_id, template_version=app_templates.get("template_version", "")) if is_v1: rainbond_app.share_user = v2_template["share_user"] rainbond_app.share_team = v2_template["share_team"] rainbond_app.pic = v2_template["pic"] rainbond_app.describe = v2_template["describe"] rainbond_app.app_template = json.dumps(v2_template) rainbond_app.is_complete = True rainbond_app.update_time = current_time_str("%Y-%m-%d %H:%M:%S") rainbond_app.save() else: user_name = v2_template.get("publish_user", None) user_id = 0 if user_name: try: user = user_repo.get_user_by_username(user_name) user_id = user.user_id except Exception as e: logger.exception(e) rainbond_app.share_user = user_id rainbond_app.share_team = v2_template.get("publish_team", "") rainbond_app.pic = v2_template.get("pic", rainbond_app.pic) rainbond_app.describe = v2_template.get("update_note", rainbond_app.describe) rainbond_app.app_template = v2_template["template_content"] rainbond_app.is_complete = True rainbond_app.update_time = current_time_str("%Y-%m-%d %H:%M:%S") rainbond_app.save()
def test_rbd_app_not_found(mocker): from console.services.app_actions.properties_changes import PropertiesChanges with open("{}/tests/console/svcupgrade/app_template.json".format(settings.BASE_DIR)) as json_file: app_template = json.load(json_file) rain_app = RainbondCenterApp() rain_app.app_template = json.dumps(app_template) mocker.patch("console.repositories.market_app_repo.rainbond_app_repo.get_enterpirse_app_by_key_and_version", return_value=rain_app) service_source = ServiceSourceInfo() service_source.group_key = "dummy group_key" mocker.patch("console.repositories.app.service_source_repo.get_service_source", return_value=service_source) with pytest.raises(RbdAppNotFound): properties_changes = PropertiesChanges(TenantServiceInfo(), Tenants()) properties_changes.get_property_changes("eid", "version")