def _get_dependency_resolver_html(imports, includes, xsd_data, filename): """Return HTML for dependency resolver form. Args: imports: includes: xsd_data: filename: Returns: """ # build the list of dependencies current_types = type_version_manager_api.get_global_version_managers() list_dependencies_template = loader.get_template( 'core_main_app/admin/list_dependencies.html') context = { 'templates': [template for template in current_types if not template.is_disabled] } list_dependencies_html = list_dependencies_template.render(context) # build the dependency resolver form dependency_resolver_template = loader.get_template( 'core_main_app/admin/dependency_resolver.html') context = { 'imports': imports, 'includes': includes, 'xsd_content': html_escape(xsd_data), 'filename': filename, 'dependencies': list_dependencies_html, } return dependency_resolver_template.render(context)
def manage_types(request): """View that allows type management. Args: request: Returns: """ # get all types type_version_managers = type_version_manager_api.get_global_version_managers( request=request) # get buckets buckets = bucket_api.get_all() context = { "object_name": "Type", "available": [ type_version_manager for type_version_manager in type_version_managers if not type_version_manager.is_disabled ], "disabled": [ type_version_manager for type_version_manager in type_version_managers if type_version_manager.is_disabled ], "buckets": buckets, } assets = { "js": [ { "path": "core_main_app/common/js/templates/list/restore.js", "is_raw": False, }, { "path": "core_main_app/common/js/templates/list/modals/disable.js", "is_raw": False, }, EditTemplateVersionManagerView.get_modal_js_path(), ], "css": ["core_composer_app/common/css/bucket.css"], } modals = [ "core_main_app/admin/templates/list/modals/disable.html", EditTemplateVersionManagerView.get_modal_html_path(), ] return admin_render( request, "core_composer_app/admin/types/list.html", assets=assets, context=context, modals=modals, )
def get_template_version_managers(self): """ Get global type version managers Returns: TypeVersionManager """ return type_version_manager_api.get_global_version_managers()
def test_get_global_version_managers_returns_types(self, mock_get_global_version_managers): # Arrange mock_type1 = _create_mock_type() mock_type2 = _create_mock_type() mock_get_global_version_managers.return_value = [mock_type1, mock_type2] result = version_manager_api.get_global_version_managers() # Assert self.assertTrue(all(isinstance(item, Type) for item in result))
def test_get_global_version_managers_returns_types( self, mock_get_global_version_managers): # Arrange mock_user = create_mock_user("1", is_superuser=True) mock_request = create_mock_request(user=mock_user) mock_type1 = _create_mock_type() mock_type2 = _create_mock_type() mock_get_global_version_managers.return_value = [ mock_type1, mock_type2 ] result = version_manager_api.get_global_version_managers( request=mock_request) # Assert self.assertTrue(all(isinstance(item, Type) for item in result))
def _get_dependency_resolver_html(imports, includes, xsd_data, filename, request): """Return HTML for dependency resolver form. Args: imports: includes: xsd_data: filename: request: Returns: """ # build the list of dependencies current_types = type_version_manager_api.get_global_version_managers( request=request) list_dependencies_template = loader.get_template( "core_main_app/admin/list_dependencies.html") context = { "templates": [template for template in current_types if not template.is_disabled] } list_dependencies_html = list_dependencies_template.render(context) # build the dependency resolver form dependency_resolver_template = loader.get_template( "core_main_app/admin/dependency_resolver.html") context = { "imports": imports, "includes": includes, "xsd_content": html_escape(xsd_data), "filename": filename, "dependencies": list_dependencies_html, } return dependency_resolver_template.render(context)