def application_add(p_engine, appname): """ Add application to Masking engine param1: p_engine: engine name from configuration param2: appname: application name return 0 if added, non 0 for error """ ret = 0 enginelist = get_list_of_engines(p_engine) if enginelist is None: return 1 # create new object of Application class for engine_tuple in enginelist: engine_obj = DxMaskingEngine(engine_tuple) if engine_obj.get_session(): continue applist = DxApplicationList() appnew = DxApplication(engine_obj) # set a name appnew.create_application(application_name=appname) # add Application to engine and list # rc is None all is OK if applist.add(appnew): ret = ret + 1 return ret
class TestApp(TestCase): @mock.patch("dxm.lib.DxApplication.DxApplicationList.paginator", app_load) def setUp(self): self.dal = DxApplicationList() self.dal.LoadApplications() def test_application_add(self): with mock.patch.object( ApplicationApi, 'create_application', return_value=None) as mock_method, \ mock.patch.object( DxMaskingEngine, 'get_session', return_value=None): application_add(None, "Test1") name, args, kwargs = mock_method.mock_calls[0] self.assertEqual("Test1", args[0].application_name) @mock.patch("dxm.lib.DxApplication.DxApplicationList.paginator", app_load) def test_application_list(self): with mock.patch.object( DxMaskingEngine, 'get_session', return_value=None): application_list(None, "csv", "App1") if not hasattr(sys.stdout, "getvalue"): self.fail("need to run in buffered mode") output = sys.stdout.getvalue().strip() self.assertEquals( output, '#Engine name,Application name\r\ntesteng,App1') def test_get_applicationId_by_name(self): self.assertEqual("App1", self.dal.get_applicationId_by_name("App1")[0])
def LoadEnvironments(self): """ Load environment list from Engine into global list return None if OK return 1 if error """ if self.__loaded_engine is None: self.__loaded_engine = self.__engine.get_name() if self.__loaded_engine == self.__engine.get_name() and self.__environmentList != {}: return None else: # delete a list as we can have multi engines self.__environmentList.clear() self.__loaded_engine = self.__engine.get_name() appList = DxApplicationList() appList.LoadApplications() if (self.__engine.version_ge('6.0.0')): from masking_api_60.api.environment_api import EnvironmentApi from masking_api_60.rest import ApiException else: from masking_api_53.api.environment_api import EnvironmentApi from masking_api_53.rest import ApiException self.__api = EnvironmentApi self.__apiexc = ApiException try: api_instance = self.__api(self.__engine.api_client) envlist = paginator( api_instance, "get_all_environments", _request_timeout=self.__engine.get_timeout()) if envlist.response_list: for c in envlist.response_list: environment = DxEnvironment(self.__engine) environment.from_environment(c) if hasattr(c, "application_id"): app = appList.get_by_ref(c.application_id) environment.application_name = app.application_name self.__environmentList[c.environment_id] = environment else: self.__logger.error("No environments found") print_error("No environments found") except self.__apiexc as e: self.__logger.error("Can't load environment %s" % e.body) print_error("Can't load environment %s" % e.body) return 1
def create_environment(self, environment_name, application_name, purpose): """ Create an environment object :param app: Application object """ if hasattr(self.__model, "application_id"): appList = DxApplicationList() appList.LoadApplications() application_id = appList.get_applicationId_by_name( application_name) self.__obj = self.__model(environment_name=environment_name, application_id=application_id[0], purpose=purpose) else: self.__obj = self.__model(environment_name=environment_name, application=application_name, purpose=purpose)
def create_environment(self, environment_name, application_name, purpose): """ Create an environment object :param app: Application object """ self.__obj = GenericModel({ x:None for x in self.swagger_map.values()}, self.swagger_types, self.swagger_map) if self.__engine.version_ge("6.0.0.0"): appList = DxApplicationList() appList.LoadApplications() application_id = appList.get_applicationId_by_name(application_name) self.environment_name=environment_name self.purpose=purpose self.application_id = application_id[0] else: self.environment_name=environment_name self.purpose=purpose self.application_name = application_name
def application_list(p_engine, format, appname): """ Print list of applications param1: p_engine: engine name from configuration param2: format: output format param3: appname: application name to list, all if None return 0 if application found """ ret = 0 enginelist = get_list_of_engines(p_engine) if enginelist is None: return 1 data = DataFormatter() data_header = [ ("Engine name", 30), ("Application name", 30), ] data.create_header(data_header) data.format_type = format for engine_tuple in enginelist: engine_obj = DxMaskingEngine(engine_tuple) if engine_obj.get_session(): continue applist = DxApplicationList() # load all objects applist.LoadApplications() if appname is None: applications = applist.get_allref() else: applications = applist.get_applicationId_by_name(appname) if len(applications) == 0: ret = ret + 1 for appref in applications: appobj = applist.get_by_ref(appref) data.data_insert( engine_tuple[0], appobj.application_name ) print("") print (data.data_output(False)) print("") return ret
def setUp(self): self.dal = DxApplicationList() self.dal.LoadApplications()