def test_create_custom_resource_no_sort_return_except(self): # Act template = self.fixture.create_and_save_template() # Assert with self.assertRaises(exceptions.ModelError): custom_resource_api.parse_and_save( self.fixture.get_dict_custom_resource_no_sort(), template)
def test_create_all_resource_custom_resource_return_type_is_not_none(self): # Act template = self.fixture.create_and_save_template() custom_resource_api.parse_and_save( self.fixture.get_dict_all_custom_resource(), template) result = custom_resource_api.get_all_by_template(template) # Assert self.assertIsNotNone(all(item.type for item in result))
def test_create_custom_resource_return_type(self): # Act template = self.fixture.create_and_save_template() custom_resource_api.parse_and_save( self.fixture.get_dict_custom_resource(), template) result = custom_resource_api.get_all_by_template(template) # Assert self.assertEquals(result[0].type, CUSTOM_RESOURCE_TYPE.RESOURCE.value)
def test_create_custom_resource_return_slug(self): # Act template = self.fixture.create_and_save_template() custom_resource_api.parse_and_save( self.fixture.get_dict_custom_resource(), template) result = custom_resource_api.get_all_by_template(template) # Assert self.assertEquals(result[0].slug, slugify(result[0].title))
def test_create_custom_resource_return_refinements_value(self): # Act template = self.fixture.create_and_save_template() custom_resource_api.parse_and_save( self.fixture.get_dict_custom_resource(), template) result = custom_resource_api.get_all_by_template(template) # Assert self.assertEquals(result[0].refinements[0], "unspecified Organization")
def test_create_custom_resource_return_refinements_length(self): # Act template = self.fixture.create_and_save_template() custom_resource_api.parse_and_save( self.fixture.get_dict_custom_resource(), template) result = custom_resource_api.get_all_by_template(template) # Assert self.assertEquals(len(result[0].refinements), 1)
def test_create_custom_resource_return_refinements_is_not_none(self): # Act template = self.fixture.create_and_save_template() custom_resource_api.parse_and_save( self.fixture.get_dict_custom_resource(), template) result = custom_resource_api.get_all_by_template(template) # Assert self.assertIsNotNone(result[0].refinements)
def test_create_all_custom_resource_return_collection_of_custom_resource(self): # Act template = self.fixture.create_and_save_template() custom_resource_api.parse_and_save( self.fixture.get_dict_all_custom_resource(), template ) result = custom_resource_api.get_all_by_template(template) # Assert self.assertTrue(all(isinstance(item, CustomResource) for item in result))
def test_get_all_by_template_return_all(self): # Act length = len(self.fixture.get_dict_all_custom_resource()) template = self.fixture.create_and_save_template() custom_resource_api.parse_and_save( self.fixture.get_dict_all_custom_resource(), template) result = custom_resource_api.get_all_by_template(template) # Assert self.assertEquals(length, len(result))
def test_replace_custom_resources_by_template_check_old(self): # Check template = self.fixture.create_and_save_template() custom_resource_api.parse_and_save( self.fixture.get_dict_custom_resource_all_resource(), template) result = custom_resource_api.get_all_by_template(template) old_cr = list(result)[0] self.assertEquals(1, len(result)) # Act custom_resource_api.replace_custom_resources_by_template( template, self.fixture.get_dict_all_custom_resource()) result = custom_resource_api.get_all_by_template(template) # Assert self.assertFalse(old_cr in result)
def _init_custom_registry(): """Init the custom registry. Returns: """ try: current_template_version = ( version_manager_api.get_active_global_version_manager_by_title( REGISTRY_XSD_FILENAME)) current_template = template_api.get( version_manager_api.get_current(current_template_version)) except: raise Exception("Can't get the current template.") if len(custom_resource_api.get_all_by_template(current_template)) > 0: print('**********') print(custom_resource_api.get_all_by_template(current_template)) print('**********') logger.info( "Custom resources related to current template already exist.") else: json_path = CUSTOM_REGISTRY_FILE_PATH if json_path == "": raise Exception( "Please configure the CUSTOM_REGISTRY_FILE_PATH setting in your project." ) try: default_json_path = finders.find(json_path) with open(default_json_path) as json_file: data = json.load(json_file) print('**********') print(f'parsing json: {data}') print('**********') custom_resource_api.parse_and_save(data, current_template) except Exception as e: logger.error( "Impossible to use the custom registry json file: {0}".format( str(e)))
def _init_custom_registry(): """Init the custom registry. Returns: """ from core_main_registry_app.components.custom_resource import ( api as custom_resource_api, ) try: current_template_version = ( system_api.get_active_global_version_manager_by_title( REGISTRY_XSD_FILENAME)) current_template = system_api.get_template_by_id( current_template_version.current) except: raise Exception("Can't get the current template.") if len(custom_resource_api.get_all_by_template(current_template)) > 0: logger.info( "Custom resources related to current template already exist.") else: json_path = CUSTOM_REGISTRY_FILE_PATH if json_path == "": raise Exception( "Please configure the CUSTOM_REGISTRY_FILE_PATH setting in your project." ) try: default_json_path = finders.find(json_path) with open(default_json_path) as json_file: data = json.load(json_file) custom_resource_api.parse_and_save(data, current_template) except Exception as e: logger.error( "Impossible to use the custom registry json file: {0}".format( str(e)))